Search in sources :

Example 26 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class ForkChannelTest method testRefcount.

public void testRefcount() throws Exception {
    FORK fork = a.getProtocolStack().findProtocol(FORK.class);
    Protocol prot = fork.get("stack");
    assert prot == null;
    fc1 = new ForkChannel(a, "stack", "fc1");
    prot = fork.get("stack");
    assert prot != null;
    ForkProtocolStack fork_stack = (ForkProtocolStack) getProtStack(prot);
    int inits = fork_stack.getInits();
    assert inits == 1 : "inits is " + inits + "(expected 1)";
    // uses the same fork stack "stack"
    fc2 = new ForkChannel(a, "stack", "fc2");
    inits = fork_stack.getInits();
    assert inits == 2 : "inits is " + inits + "(expected 2)";
    a.connect(CLUSTER);
    fc1.connect(CLUSTER);
    int connects = fork_stack.getConnects();
    assert connects == 1 : "connects is " + connects + "(expected 1)";
    // duplicate connect()
    fc1.connect(CLUSTER);
    connects = fork_stack.getConnects();
    assert connects == 1 : "connects is " + connects + "(expected 1)";
    fc2.connect(CLUSTER);
    connects = fork_stack.getConnects();
    assert connects == 2 : "connects is " + connects + "(expected 2)";
    fc2.disconnect();
    // duplicate disconnect() !
    fc2.disconnect();
    connects = fork_stack.getConnects();
    assert connects == 1 : "connects is " + connects + "(expected 1)";
    Util.close(fc2);
    inits = fork_stack.getInits();
    assert inits == 1 : "inits is " + inits + "(expected 1)";
    // duplicate close()
    Util.close(fc2);
    inits = fork_stack.getInits();
    assert inits == 1 : "inits is " + inits + "(expected 1)";
    Util.close(fc1);
    connects = fork_stack.getConnects();
    assert connects == 0 : "connects is " + connects + "(expected 0)";
    inits = fork_stack.getInits();
    assert inits == 0 : "inits is " + inits + "(expected 0)";
    prot = fork.get("stack");
    assert prot == null;
}
Also used : FORK(org.jgroups.protocols.FORK) Protocol(org.jgroups.stack.Protocol) ForkChannel(org.jgroups.fork.ForkChannel) ForkProtocolStack(org.jgroups.fork.ForkProtocolStack)

Example 27 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class InetAddressChecksTest method testIPVersionCheckingNoConsistentVersion.

/*
	 * Checks IP version mechanism for inconsistent version processing
	 */
@Test(expectedExceptions = RuntimeException.class)
public void testIPVersionCheckingNoConsistentVersion() throws Exception {
    List<ProtocolConfiguration> protocol_configs = new ArrayList<>();
    List<Protocol> protocols = new ArrayList<>();
    // create the layer described by IPCHECK
    protocol = Configurator.createProtocol(ipCheckNoConsistentProps, stack);
    // process the defaults
    protocol_configs.add(new ProtocolConfiguration(ipCheckNoConsistentProps));
    protocols.add(protocol);
    Map<String, Map<String, InetAddressInfo>> inetAddressMap = null;
    try {
        inetAddressMap = Configurator.createInetAddressMap(protocol_configs, protocols);
        Collection<InetAddress> addrs = Configurator.getAddresses(inetAddressMap);
        determineIpVersionFromAddresses(addrs);
    } catch (RuntimeException e) {
        System.out.println("Expected exception received: " + e.getMessage());
        throw e;
    }
}
Also used : ProtocolConfiguration(org.jgroups.conf.ProtocolConfiguration) Protocol(org.jgroups.stack.Protocol) InetAddress(java.net.InetAddress) Test(org.testng.annotations.Test)

Example 28 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class KeyExchange method findProtocolAbove.

protected <T extends Protocol> T findProtocolAbove(Class<? extends Protocol> clazz) {
    Protocol tmp = this;
    while (tmp != null) {
        Class<?> protClass = tmp.getClass();
        if (clazz.isAssignableFrom(protClass))
            return (T) tmp;
        tmp = tmp.getUpProtocol();
    }
    return null;
}
Also used : Protocol(org.jgroups.stack.Protocol)

Example 29 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class FORK method createForkStack.

/**
 * Returns the fork stack for fork_stack_id (if exitstent), or creates a new fork-stack from protocols and adds it
 * into the hashmap of fork-stack (key is fork_stack_id).
 * Method init() will be called on each protocol, from bottom to top.
 * @param fork_stack_id The key under which the new fork-stack should be added to the fork-stacks hashmap
 * @param protocols A list of protocols from <em>bottom to top</em> to be inserted. They will be sandwiched
 *                  between ForkProtocolStack (top) and ForkProtocol (bottom). The list can be empty (or null) in
 *                  which case we won't create any protocols, but still have a separate fork-stack inserted.
 * @param initialize If false, the ref count 'inits' will not get incremented and init() won't be called. This is
 *                   needed when creating a fork stack from an XML config inside of the FORK protocol. The protocols
 *                   in the fork stack will only get initialized on the first ForkChannel creation
 * @return The new {@link ForkProtocolStack}, or the existing stack (if present)
 */
public synchronized ProtocolStack createForkStack(String fork_stack_id, List<Protocol> protocols, boolean initialize) throws Exception {
    Protocol bottom;
    if ((bottom = get(fork_stack_id)) != null) {
        ForkProtocolStack retval = getForkStack(bottom);
        return initialize ? retval.incrInits() : retval;
    }
    List<Protocol> prots = new ArrayList<>();
    // add a ForkProtocol as bottom protocol
    prots.add(bottom = new ForkProtocol(fork_stack_id).setDownProtocol(this));
    if (protocols != null)
        prots.addAll(protocols);
    ForkProtocolStack fork_stack = (ForkProtocolStack) new ForkProtocolStack(getUnknownForkHandler(), prots, fork_stack_id).setChannel(this.stack.getChannel());
    fork_stack.init();
    if (initialize)
        fork_stack.incrInits();
    fork_stacks.put(fork_stack_id, bottom);
    return fork_stack;
}
Also used : ForkProtocol(org.jgroups.fork.ForkProtocol) ForkProtocol(org.jgroups.fork.ForkProtocol) Protocol(org.jgroups.stack.Protocol) ForkProtocolStack(org.jgroups.fork.ForkProtocolStack)

Example 30 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class Util method getTestStack.

/**
 * Returns a default stack for testing with transport = SHARED_LOOPBACK
 * @param additional_protocols Any number of protocols to add to the top of the returned protocol list
 * @return
 */
public static Protocol[] getTestStack(Protocol... additional_protocols) {
    Protocol[] protocols = { new SHARED_LOOPBACK(), new SHARED_LOOPBACK_PING(), new NAKACK2(), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(1000), new FRAG2().setFragSize(8000) };
    if (additional_protocols == null)
        return protocols;
    Protocol[] tmp = Arrays.copyOf(protocols, protocols.length + additional_protocols.length);
    System.arraycopy(additional_protocols, 0, tmp, protocols.length, additional_protocols.length);
    return tmp;
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol) GMS(org.jgroups.protocols.pbcast.GMS)

Aggregations

Protocol (org.jgroups.stack.Protocol)87 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)18 JChannel (org.jgroups.JChannel)17 GMS (org.jgroups.protocols.pbcast.GMS)17 STABLE (org.jgroups.protocols.pbcast.STABLE)13 ProtocolStack (org.jgroups.stack.ProtocolStack)12 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)9 Property (org.jgroups.annotations.Property)6 HashMap (java.util.HashMap)5 ForkProtocol (org.jgroups.fork.ForkProtocol)5 ForkProtocolStack (org.jgroups.fork.ForkProtocolStack)5 InetAddress (java.net.InetAddress)4 ProtocolConfiguration (org.jgroups.conf.ProtocolConfiguration)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 Message (org.jgroups.Message)3 FORK (org.jgroups.protocols.FORK)3 UNICAST3 (org.jgroups.protocols.UNICAST3)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Method (java.lang.reflect.Method)2