Search in sources :

Example 81 with JChannel

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);
}
Also used : JChannel(org.jgroups.JChannel) RemoteEventException(org.xwiki.observation.remote.RemoteEventException) RemoteEventException(org.xwiki.observation.remote.RemoteEventException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) IOException(java.io.IOException) MBeanServer(javax.management.MBeanServer)

Example 82 with JChannel

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

Example 83 with JChannel

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

Example 84 with JChannel

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);
    }
}
Also used : JChannel(org.jgroups.JChannel) Event(org.jgroups.Event) ForkProtocol(org.jgroups.fork.ForkProtocol) Protocol(org.jgroups.stack.Protocol) ForkProtocolStack(org.jgroups.fork.ForkProtocolStack)

Example 85 with JChannel

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);
    }
}
Also used : JChannel(org.jgroups.JChannel) ForkProtocol(org.jgroups.fork.ForkProtocol) Protocol(org.jgroups.stack.Protocol) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ForkProtocolStack(org.jgroups.fork.ForkProtocolStack)

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