Search in sources :

Example 1 with View

use of org.jgroups.View in project camel by apache.

the class JGroupsFilters method dropNonCoordinatorViews.

/**
     * Creates predicate rejecting messages that are instances of {@code org.jgroups.View}, but have not been received
     * by the coordinator JGroups node. This filter is useful for keeping only view messages indicating that receiving
     * endpoint is a master node.
     *
     * @return predicate filtering out non-coordinator view messages.
     */
public static Predicate dropNonCoordinatorViews() {
    return new Predicate() {

        @Override
        public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            LOG.debug("Filtering message {}.", body);
            if (body instanceof View) {
                View view = (View) body;
                Address coordinatorNodeAddress = view.getMembers().get(COORDINATOR_NODE_INDEX);
                Address channelAddress = exchange.getIn().getHeader(HEADER_JGROUPS_CHANNEL_ADDRESS, Address.class);
                LOG.debug("Comparing endpoint channel address {} against the coordinator node address {}.", channelAddress, coordinatorNodeAddress);
                return channelAddress.equals(coordinatorNodeAddress);
            }
            LOG.debug("Body {} is not an instance of org.jgroups.View . Skipping filter.", body);
            return false;
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Address(org.jgroups.Address) View(org.jgroups.View) Predicate(org.apache.camel.Predicate)

Example 2 with View

use of org.jgroups.View 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)

Example 3 with View

use of org.jgroups.View in project geode by apache.

the class JGroupsMessenger method installView.

@Override
public void installView(NetView v) {
    this.view = v;
    if (this.jgAddress.getVmViewId() < 0) {
        this.jgAddress.setVmViewId(this.localAddress.getVmViewId());
    }
    List<JGAddress> mbrs = new ArrayList<>(v.size());
    mbrs.addAll(v.getMembers().stream().map(JGAddress::new).collect(Collectors.toList()));
    ViewId vid = new ViewId(new JGAddress(v.getCoordinator()), v.getViewId());
    View jgv = new View(vid, new ArrayList<>(mbrs));
    logger.trace("installing JGroups view: {}", jgv);
    this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
    addressesWithIoExceptionsProcessed.clear();
    if (encrypt != null) {
        encrypt.installView(v);
    }
    synchronized (scheduledMcastSeqnos) {
        for (DistributedMember mbr : v.getCrashedMembers()) {
            scheduledMcastSeqnos.remove(mbr);
        }
        for (DistributedMember mbr : v.getShutdownMembers()) {
            scheduledMcastSeqnos.remove(mbr);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ViewId(org.jgroups.ViewId) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Event(org.jgroups.Event) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View)

Example 4 with View

use of org.jgroups.View in project JGroups by belaban.

the class GossipRouterTest method testLateStart.

/**
 * Tests the following scenario (http://jira.jboss.com/jira/browse/JGRP-682):
 * - First node is started with tunnel.xml, cannot connect
 * - Second node is started *with* GossipRouter
 * - Now first node should be able to connect and first and second node should be able to merge into a group
 * - SUCCESS: a view of 2
 */
public void testLateStart() throws Exception {
    final Lock lock = new ReentrantLock();
    final Condition cond = lock.newCondition();
    AtomicBoolean done = new AtomicBoolean(false);
    System.out.println("-- starting first channel");
    a = createTunnelChannel("A");
    a.setReceiver(new MyReceiver("c1", done, lock, cond));
    a.connect("demo");
    System.out.println("-- starting second channel");
    b = createTunnelChannel("B");
    b.setReceiver(new MyReceiver("c2", done, lock, cond));
    b.connect("demo");
    System.out.println("-- starting GossipRouter");
    router = new GossipRouter(bind_addr_str, gossip_router_port);
    router.start();
    System.out.println("-- waiting for merge to happen --");
    long target_time = System.currentTimeMillis() + 40000;
    lock.lock();
    try {
        while (System.currentTimeMillis() < target_time && !done.get()) {
            cond.await(1000, TimeUnit.MILLISECONDS);
        }
    } finally {
        lock.unlock();
    }
    Util.sleep(500);
    View view = a.getView();
    System.out.println("view=" + view);
    assert view.size() == 2 : "view=" + view;
    Util.close(b, a);
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GossipRouter(org.jgroups.stack.GossipRouter) View(org.jgroups.View) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 5 with View

use of org.jgroups.View in project JGroups by belaban.

the class INJECT_VIEWTest method checkViews.

private static void checkViews(JChannel[] channels, String channel_name, String... members) {
    JChannel ch = findChannel(channel_name, channels);
    View view = ch.getView();
    assert view.size() == members.length : "view is " + view + ", members: " + Arrays.toString(members);
    for (String member : members) {
        Address addr = findAddress(member, channels);
        assert view.getMembers().contains(addr) : "view " + view + " does not contain " + addr;
    }
}
Also used : JChannel(org.jgroups.JChannel) Address(org.jgroups.Address) View(org.jgroups.View)

Aggregations

View (org.jgroups.View)51 Address (org.jgroups.Address)24 JChannel (org.jgroups.JChannel)14 GMS (org.jgroups.protocols.pbcast.GMS)6 Event (org.jgroups.Event)5 Receiver (org.jgroups.Receiver)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ViewId (org.jgroups.ViewId)3 IOException (java.io.IOException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 IpAddress (org.jgroups.stack.IpAddress)2 UUID (org.jgroups.util.UUID)2 java.io (java.io)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1