本文整理汇总了Java中org.jgroups.ReceiverAdapter类的典型用法代码示例。如果您正苦于以下问题:Java ReceiverAdapter类的具体用法?Java ReceiverAdapter怎么用?Java ReceiverAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReceiverAdapter类属于org.jgroups包,在下文中一共展示了ReceiverAdapter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.jgroups.ReceiverAdapter; //导入依赖的package包/类
public void start() throws Exception {
String props="udp.xml";
channel=new JChannel(props);
channel.setReceiver(new ReceiverAdapter() {
public void viewAccepted(View view) {
setInternalState(view.getMembers());
}
public void setInternalState(java.util.List<Address> mbrs) {
members.clear();
for(Address mbr : mbrs)
addNode(mbr);
coordinator=mbrs.size() <= 1 || (mbrs.size() > 1 && mbrs.iterator().next().equals(my_addr));
repaint();
}
});
channel.connect(channel_name);
my_addr=channel.getAddress();
if(my_addr != null)
setTitle(my_addr.toString());
pack();
setVisible(true);
}
示例2: start
import org.jgroups.ReceiverAdapter; //导入依赖的package包/类
void start(String props, String name, long repl_timeout, boolean allow_dirty_reads, boolean follower) throws Exception {
ch=new JChannel(props).name(name);
counter_service=new CounterService(ch).raftId(name).replTimeout(repl_timeout).allowDirtyReads(allow_dirty_reads);
if(follower)
disableElections(ch);
ch.setReceiver(new ReceiverAdapter() {
public void viewAccepted(View view) {
System.out.println("-- view: " + view);
}
});
try {
ch.connect("cntrs");
loop();
}
finally {
Util.close(ch);
}
}
示例3: initialize
import org.jgroups.ReceiverAdapter; //导入依赖的package包/类
@Override
synchronized public void initialize() throws Exception {
super.initialize();
CompletableFuture<JChannel> channelFuture = CompletableFuture.supplyAsync(() -> {
// Put this where JGroups can see it:
System.setProperty("jgroups.udp.mcast_port", String.valueOf(multicastPort));
try {
JChannel channel = new JChannel("cluster.xml");
channel.setName("EventsAndStatus");
channel.setDiscardOwnMessages(false); // Also the default, this is documentation.
channel.setReceiver(new ReceiverAdapter() {
@Override
public void receive(Message msg) {
eventBus.post(msg.getObject());
}
});
channel.connect(clusterName);
log.info("JGroups cluster initialization complete");
return channel;
} catch (Exception e) {
throw new RuntimeException("Unable to initialize JGroups", e);
}
});
executor.schedule(
() -> channelFuture.completeExceptionally(new TimeoutException(
"Failed to connect in " + INITIALIZATION_TIMEOUT_SECONDS + " seconds")),
INITIALIZATION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
this.channel = channelFuture.get();
}
示例4: doPreSetup
import org.jgroups.ReceiverAdapter; //导入依赖的package包/类
@Override
protected void doPreSetup() throws Exception {
super.doPreSetup();
channel = new JChannel();
channel.setReceiver(new ReceiverAdapter() {
@Override
public void receive(Message msg) {
messageReceived = msg.getObject();
}
});
channel.connect(CLUSTER_NAME);
}
示例5: main
import org.jgroups.ReceiverAdapter; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Protocol[] prot_stack={
new UDP().setValue("bind_addr", InetAddress.getByName("127.0.0.1")),
new PING(),
new MERGE3(),
new FD_SOCK(),
new FD_ALL(),
new VERIFY_SUSPECT(),
new BARRIER(),
new NAKACK2(),
new UNICAST3(),
new STABLE(),
new GMS(),
new UFC(),
new MFC(),
new FRAG2()};
JChannel ch=new JChannel(prot_stack).name(args[0]);
ch.setReceiver(new ReceiverAdapter() {
public void viewAccepted(View new_view) {
System.out.println("view: " + new_view);
}
public void receive(Message msg) {
System.out.println("<< " + msg.getObject() + " [" + msg.getSrc() + "]");
}
});
ch.connect("ChatCluster");
for(;;) {
String line=Util.readStringFromStdin(": ");
ch.send(null, line);
}
}
示例6: start
import org.jgroups.ReceiverAdapter; //导入依赖的package包/类
void start(String props, String channel_name) throws Exception {
ch=new JChannel(props);
ch.setName(channel_name);
ch.setReceiver(new ReceiverAdapter() {
public void viewAccepted(View view) {
System.out.println("-- view: " + view);
}
});
loop();
}
示例7: JChannelWrapper
import org.jgroups.ReceiverAdapter; //导入依赖的package包/类
public JChannelWrapper(JChannelManager manager, final String channelName, JChannel channel) throws Exception {
this.refCount = 1;
this.channelName = channelName;
this.channel = channel;
this.manager = manager;
if (logger.isTraceEnabled() && channel.getReceiver() != null) {
logger.trace(this + "The channel already had a receiver previously!!!! == " + channel.getReceiver(), new Exception("trace"));
}
//we always add this for the first ref count
channel.setReceiver(new ReceiverAdapter() {
@Override
public String toString() {
return "ReceiverAdapter::" + JChannelWrapper.this;
}
@Override
public void receive(org.jgroups.Message msg) {
if (logger.isTraceEnabled()) {
logger.trace(this + ":: Wrapper received " + msg + " on channel " + channelName);
}
synchronized (receivers) {
for (JGroupsReceiver r : receivers) {
r.receive(msg);
}
}
}
});
}
示例8: JGroupsClusterInitializer
import org.jgroups.ReceiverAdapter; //导入依赖的package包/类
public JGroupsClusterInitializer(final ReceiverAdapter receiverAdapter) {
this.receiverAdapter = receiverAdapter;
}