use of org.jgroups.JChannel in project xwiki-platform by xwiki.
the class JGroupsNetworkAdapter method startChannel.
@Override
public void startChannel(String channelId) throws RemoteEventException {
if (this.channels.containsKey(channelId)) {
throw new RemoteEventException(MessageFormat.format("Channel [{0}] already started", channelId));
}
JChannel channel;
try {
channel = createChannel(channelId);
channel.connect("event");
this.channels.put(channelId, channel);
} catch (Exception e) {
throw new RemoteEventException("Failed to create channel [" + channelId + "]", e);
}
// Register the channel against the JMX Server
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JmxConfigurator.registerChannel(channel, mbs, channel.getClusterName());
} catch (Exception e) {
this.logger.warn("Failed to register channel [" + channelId + "] against the JMX Server", e);
}
this.logger.info("Channel [{}] started", channelId);
}
use of org.jgroups.JChannel in project JGroups by belaban.
the class ReplicatedHashMapDemo method main.
public static void main(String[] args) {
ReplicatedHashMapDemo client = new ReplicatedHashMapDemo();
JChannel channel;
String props = "udp.xml";
try {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if ("-props".equals(arg)) {
props = args[++i];
continue;
}
help();
return;
}
} catch (Exception e) {
help();
return;
}
try {
channel = new JChannel(props);
channel.connect("ReplicatedHashMapDemo-Cluster");
client.start(channel);
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.jgroups.JChannel in project JGroups by belaban.
the class Topology method start.
public void start() throws Exception {
channel = new JChannel(props).name(name);
channel.setReceiver(new Receiver() {
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);
}
use of org.jgroups.JChannel in project JGroups by belaban.
the class FORK method setStateInMainAndForkChannels.
protected void setStateInMainAndForkChannels(InputStream in) {
try (DataInputStream input = new DataInputStream(in)) {
for (; ; ) {
String stack_name = Bits.readString(input);
String ch_name = Bits.readString(input);
int len = input.readInt();
if (len > 0) {
byte[] data = new byte[len];
in.read(data, 0, len);
ByteArrayInputStream tmp = new ByteArrayInputStream(data, 0, len);
if (stack_name == null && ch_name == null)
up_prot.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp));
else {
Protocol prot = fork_stacks.get(stack_name);
if (prot == null) {
log.warn("%s: fork stack %s not found, dropping state for %s:%s", local_addr, stack_name, stack_name, ch_name);
continue;
}
ForkProtocolStack fork_stack = getForkStack(prot);
JChannel fork_ch = fork_stack.get(ch_name);
if (fork_ch == null) {
log.warn("%s: fork channel %s not found, dropping state for %s:%s", local_addr, ch_name, stack_name, ch_name);
continue;
}
fork_ch.up(new Event(Event.STATE_TRANSFER_INPUTSTREAM, tmp));
}
}
}
} catch (EOFException ignored) {
} catch (Throwable ex) {
log.error("%s: failed setting state in main channel", local_addr, ex);
}
}
use of org.jgroups.JChannel in project JGroups by belaban.
the class FORK method getStateFromMainAndForkChannels.
protected void getStateFromMainAndForkChannels(Event evt) {
final OutputStream out = evt.getArg();
try (DataOutputStream dos = new DataOutputStream(out)) {
getStateFrom(null, up_prot, null, null, dos);
// now fetch state from all fork channels
for (Map.Entry<String, Protocol> entry : fork_stacks.entrySet()) {
String stack_name = entry.getKey();
Protocol prot = entry.getValue();
ForkProtocolStack fork_stack = getForkStack(prot);
for (Map.Entry<String, JChannel> en : fork_stack.getForkChannels().entrySet()) {
String fc_name = en.getKey();
JChannel fc = en.getValue();
getStateFrom(fc, null, stack_name, fc_name, dos);
}
}
} catch (Throwable ex) {
log.error("%s: failed fetching state from main channel", local_addr, ex);
}
}
Aggregations