本文整理汇总了Java中org.jgroups.JChannel.setReceiver方法的典型用法代码示例。如果您正苦于以下问题:Java JChannel.setReceiver方法的具体用法?Java JChannel.setReceiver怎么用?Java JChannel.setReceiver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.JChannel
的用法示例。
在下文中一共展示了JChannel.setReceiver方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.jgroups.JChannel; //导入方法依赖的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: main
import org.jgroups.JChannel; //导入方法依赖的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);
}
}
示例3: init
import org.jgroups.JChannel; //导入方法依赖的package包/类
@Override
public CoChannel init(ChannelSelector selector) throws CoChannelException {
super.init(selector);
try {
jch = new JChannel(); // TODO config
jch.setReceiver(this);
jch.connect(name());
} catch (Exception e) {
LOG.error(e.getMessage(), e);
try {
close();
} catch (IOException e1) {}
}
return this;
}
示例4: doPreSetup
import org.jgroups.JChannel; //导入方法依赖的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: start
import org.jgroups.JChannel; //导入方法依赖的package包/类
private void start(String props, String name) throws Exception {
channel=new JChannel(props);
if(name != null)
channel.name(name);
channel.setReceiver(this);
channel.connect("ChatCluster");
eventLoop();
channel.close();
}
示例6: start
import org.jgroups.JChannel; //导入方法依赖的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: start
import org.jgroups.JChannel; //导入方法依赖的package包/类
private void start() throws Exception {
channel=new JChannel();
channel.setReceiver(this);
channel.connect("ChatCluster");
channel.getState(null, 10000);
eventLoop();
channel.close();
}
示例8: initialize
import org.jgroups.JChannel; //导入方法依赖的package包/类
@Override
public void initialize(RevenoClusterConfiguration config) {
this.config = config;
Properties props = new Properties();
props.put("jgroups.tcp.bind_addr", ((InetAddress) config.currentNodeAddress()).getHost());
props.put("jgroups.tcp.bind_port", Integer.toString(((InetAddress) config.currentNodeAddress()).getPort()));
props.put("jgroups.tcpping.initial_hosts", makeInitialHostsString(config.nodesAddresses()));
props.put("jgroups.auth.token", Optional.ofNullable(config.authToken()).orElse(""));
setProperties(props);
try {
String protocol;
if (jGroupsConfigFile.startsWith("classpath:/")) {
protocol = ResourceLoader.loadResource(new ByteArrayInputStream(DEFAULT_CONFIG.getBytes("UTF-8")), props);
} else {
protocol = ResourceLoader.loadResource(new File(jGroupsConfigFile), props);
}
Element xml = ResourceLoader.loadXMLFromString(protocol).getDocumentElement();
channel = new JChannel(xml);
channel.setReceiver(new JChannelReceiver());
channel.setDiscardOwnMessages(true);
cluster = new JGroupsCluster(config, channel);
buffer = createBuffer();
} catch (Exception e) {
throw Exceptions.runtime(e);
}
isInitialized = true;
}
示例9: JChannelWrapper
import org.jgroups.JChannel; //导入方法依赖的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);
}
}
}
});
}