Search in sources :

Example 1 with JChannel

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);
    }
}
Also used : JChannel(org.jgroups.JChannel) StartException(org.jboss.msc.service.StartException) StartException(org.jboss.msc.service.StartException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 2 with JChannel

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;
        }
    }
}
Also used : JChannel(org.jgroups.JChannel) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with JChannel

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();
}
Also used : JChannel(org.jgroups.JChannel)

Example 4 with 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();
}
Also used : JChannel(org.jgroups.JChannel)

Example 5 with 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);
}
Also used : JChannel(org.jgroups.JChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) ByteArrayInputStream(java.io.ByteArrayInputStream) GemFireConfigException(org.apache.geode.GemFireConfigException) ViewId(org.jgroups.ViewId) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) SystemConnectException(org.apache.geode.SystemConnectException)

Aggregations

JChannel (org.jgroups.JChannel)119 GMS (org.jgroups.protocols.pbcast.GMS)22 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)21 Protocol (org.jgroups.stack.Protocol)18 STABLE (org.jgroups.protocols.pbcast.STABLE)15 View (org.jgroups.View)14 Message (org.jgroups.Message)10 ArrayList (java.util.ArrayList)9 Address (org.jgroups.Address)7 IOException (java.io.IOException)6 Test (org.testng.annotations.Test)5 InetSocketAddress (java.net.InetSocketAddress)4 HashMap (java.util.HashMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 LockService (org.jgroups.blocks.locking.LockService)4 Test (org.junit.Test)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ChannelBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory)3