use of org.jgroups.JChannel in project wildfly by wildfly.
the class ChannelBuilder method start.
@Override
public void start(StartContext context) throws StartException {
try {
this.channel = this.factory.getValue().createChannel(this.name);
} catch (Exception e) {
throw new StartException(e);
}
if (JGroupsLogger.ROOT_LOGGER.isTraceEnabled()) {
String output = this.channel.getProtocolStack().printProtocolSpec(true);
JGroupsLogger.ROOT_LOGGER.tracef("JGroups channel %s created with configuration:%n %s", this.name, output);
}
if (this.channel instanceof JChannel) {
JChannel channel = (JChannel) this.channel;
channel.enableStats(this.statisticsEnabled);
if (this.server != null) {
try {
JmxConfigurator.registerChannel((JChannel) this.channel, this.server.getValue(), this.name);
} catch (Exception e) {
JGroupsLogger.ROOT_LOGGER.debug(e.getLocalizedMessage(), e);
}
}
}
try {
this.channel.connect(this.cluster.getValue());
} catch (Exception e) {
throw new StartException(e);
}
}
use of org.jgroups.JChannel in project geode by apache.
the class JGroupsMessengerJUnitTest method testJChannelError.
@Test
public void testJChannelError() throws Exception {
for (int i = 0; i < 2; i++) {
boolean enableMcast = (i == 1);
initMocks(enableMcast);
JChannel mockChannel = mock(JChannel.class);
when(mockChannel.isConnected()).thenReturn(true);
doThrow(new RuntimeException()).when(mockChannel).send(any(Message.class));
JChannel realChannel = messenger.myChannel;
messenger.myChannel = mockChannel;
try {
InternalDistributedMember mbr = createAddress(8888);
DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
when(msg.getMulticast()).thenReturn(enableMcast);
when(msg.getProcessorId()).thenReturn(1234);
when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
try {
messenger.send(msg);
fail("expected a failure");
} catch (DistributedSystemDisconnectedException e) {
// success
}
verify(mockChannel).send(isA(Message.class));
} finally {
messenger.myChannel = realChannel;
}
}
}
use of org.jgroups.JChannel in project camel by apache.
the class JGroupsComponentTest method doPreSetup.
// Fixture setup
@Override
protected void doPreSetup() throws Exception {
super.doPreSetup();
clientChannel = new JChannel();
clientChannel.connect(CLUSTER_NAME);
defaultComponentChannel = new JChannel();
}
use of org.jgroups.JChannel in project camel by apache.
the class JGroupsComponentWithChannelPropertiesTest method doPreSetup.
// Fixture setup
@Override
protected void doPreSetup() throws Exception {
super.doPreSetup();
clientChannel = new JChannel();
clientChannel.connect(CLUSTER_NAME);
defaultComponentChannel = new JChannel();
}
use of org.jgroups.JChannel in project geode by apache.
the class JGroupsMessenger method start.
@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void start() {
// create the configuration XML string for JGroups
String properties = this.jgStackConfig;
long start = System.currentTimeMillis();
// start the jgroups channel and establish the membership ID
boolean reconnecting = false;
try {
Object oldChannel = services.getConfig().getTransport().getOldDSMembershipInfo();
if (oldChannel != null) {
logger.debug("Reusing JGroups channel from previous system", properties);
myChannel = (JChannel) oldChannel;
// scrub the old channel
ViewId vid = new ViewId(new JGAddress(), 0);
View jgv = new View(vid, new ArrayList<>());
this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
UUID logicalAddress = (UUID) myChannel.getAddress();
if (logicalAddress instanceof JGAddress) {
((JGAddress) logicalAddress).setVmViewId(-1);
}
reconnecting = true;
} else {
logger.debug("JGroups configuration: {}", properties);
checkForIPv6();
InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8"));
myChannel = new JChannel(is);
}
} catch (Exception e) {
throw new GemFireConfigException("unable to create jgroups channel", e);
}
// give the stats to the jchannel statistics recorder
StatRecorder sr = (StatRecorder) myChannel.getProtocolStack().findProtocol(StatRecorder.class);
if (sr != null) {
sr.setServices(services);
}
Transport transport = (Transport) myChannel.getProtocolStack().getTransport();
transport.setMessenger(this);
nackack2HeaderId = ClassConfigurator.getProtocolId(NAKACK2.class);
try {
myChannel.setReceiver(null);
myChannel.setReceiver(new JGroupsReceiver());
if (!reconnecting) {
// apache g***** (whatever we end up calling it)
myChannel.connect("AG");
}
} catch (Exception e) {
myChannel.close();
throw new SystemConnectException("unable to create jgroups channel", e);
}
if (JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK) {
JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = false;
throw new SystemConnectException("failing for test");
}
establishLocalAddress();
logger.info("JGroups channel {} (took {}ms)", (reconnecting ? "reinitialized" : "created"), System.currentTimeMillis() - start);
}
Aggregations