Search in sources :

Example 6 with ChannelInterceptor

use of org.apache.catalina.tribes.ChannelInterceptor in project tomcat by apache.

the class GroupChannel method addInterceptor.

/**
     * Adds an interceptor to the stack for message processing<br>
     * Interceptors are ordered in the way they are added.<br>
     * <code>channel.addInterceptor(A);</code><br>
     * <code>channel.addInterceptor(C);</code><br>
     * <code>channel.addInterceptor(B);</code><br>
     * Will result in a interceptor stack like this:<br>
     * <code>A -&gt; C -&gt; B</code><br>
     * The complete stack will look like this:<br>
     * <code>Channel -&gt; A -&gt; C -&gt; B -&gt; ChannelCoordinator</code><br>
     * @param interceptor ChannelInterceptorBase
     */
@Override
public void addInterceptor(ChannelInterceptor interceptor) {
    if (interceptors == null) {
        interceptors = interceptor;
        interceptors.setNext(coordinator);
        interceptors.setPrevious(null);
        coordinator.setPrevious(interceptors);
    } else {
        ChannelInterceptor last = interceptors;
        while (last.getNext() != coordinator) {
            last = last.getNext();
        }
        last.setNext(interceptor);
        interceptor.setNext(coordinator);
        interceptor.setPrevious(last);
        coordinator.setPrevious(interceptor);
    }
}
Also used : ChannelInterceptor(org.apache.catalina.tribes.ChannelInterceptor)

Example 7 with ChannelInterceptor

use of org.apache.catalina.tribes.ChannelInterceptor in project tomcat by apache.

the class StaticMembershipInterceptor method start.

/**
     * {@inheritDoc}
     * <p>
     * Sends notifications upwards.
     */
@Override
public void start(int svc) throws ChannelException {
    if ((Channel.SND_RX_SEQ & svc) == Channel.SND_RX_SEQ)
        super.start(Channel.SND_RX_SEQ);
    if ((Channel.SND_TX_SEQ & svc) == Channel.SND_TX_SEQ)
        super.start(Channel.SND_TX_SEQ);
    final ChannelInterceptorBase base = this;
    for (final Member member : members) {
        Thread t = new Thread() {

            @Override
            public void run() {
                base.memberAdded(member);
                if (getfirstInterceptor().getMember(member) != null) {
                    sendLocalMember(new Member[] { member });
                }
            }
        };
        t.start();
    }
    super.start(svc & (~Channel.SND_RX_SEQ) & (~Channel.SND_TX_SEQ));
    // check required interceptors
    TcpFailureDetector failureDetector = null;
    TcpPingInterceptor pingInterceptor = null;
    ChannelInterceptor prev = getPrevious();
    while (prev != null) {
        if (prev instanceof TcpFailureDetector)
            failureDetector = (TcpFailureDetector) prev;
        if (prev instanceof TcpPingInterceptor)
            pingInterceptor = (TcpPingInterceptor) prev;
        prev = prev.getPrevious();
    }
    if (failureDetector == null) {
        log.warn(sm.getString("staticMembershipInterceptor.no.failureDetector"));
    }
    if (pingInterceptor == null) {
        log.warn(sm.getString("staticMembershipInterceptor.no.pingInterceptor"));
    }
}
Also used : ChannelInterceptorBase(org.apache.catalina.tribes.group.ChannelInterceptorBase) ChannelInterceptor(org.apache.catalina.tribes.ChannelInterceptor) Member(org.apache.catalina.tribes.Member)

Example 8 with ChannelInterceptor

use of org.apache.catalina.tribes.ChannelInterceptor in project tomcat by apache.

the class TcpPingInterceptor method start.

@Override
public synchronized void start(int svc) throws ChannelException {
    super.start(svc);
    running = true;
    if (thread == null && useThread) {
        thread = new PingThread();
        thread.setDaemon(true);
        String channelName = "";
        if (getChannel().getName() != null)
            channelName = "[" + getChannel().getName() + "]";
        thread.setName("TcpPingInterceptor.PingThread" + channelName + "-" + cnt.addAndGet(1));
        thread.start();
    }
    //acquire the interceptors to invoke on send ping events
    ChannelInterceptor next = getNext();
    while (next != null) {
        if (next instanceof TcpFailureDetector)
            failureDetector = new WeakReference<>((TcpFailureDetector) next);
        if (next instanceof StaticMembershipInterceptor)
            staticMembers = new WeakReference<>((StaticMembershipInterceptor) next);
        next = next.getNext();
    }
}
Also used : ChannelInterceptor(org.apache.catalina.tribes.ChannelInterceptor) WeakReference(java.lang.ref.WeakReference)

Example 9 with ChannelInterceptor

use of org.apache.catalina.tribes.ChannelInterceptor in project tomcat by apache.

the class ChannelSF method storeChildren.

/**
     * Store the specified Channel children.
     *
     * @param aWriter
     *            PrintWriter to which we are storing
     * @param indent
     *            Number of spaces to indent this element
     * @param aChannel
     *            Channel whose properties are being stored
     *
     * @exception Exception
     *                if an exception occurs while storing
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aChannel, StoreDescription parentDesc) throws Exception {
    if (aChannel instanceof Channel) {
        Channel channel = (Channel) aChannel;
        if (channel instanceof ManagedChannel) {
            ManagedChannel managedChannel = (ManagedChannel) channel;
            // Store nested <Membership> element
            MembershipService service = managedChannel.getMembershipService();
            if (service != null) {
                storeElement(aWriter, indent, service);
            }
            // Store nested <Sender> element
            ChannelSender sender = managedChannel.getChannelSender();
            if (sender != null) {
                storeElement(aWriter, indent, sender);
            }
            // Store nested <Receiver> element
            ChannelReceiver receiver = managedChannel.getChannelReceiver();
            if (receiver != null) {
                storeElement(aWriter, indent, receiver);
            }
            Iterator<ChannelInterceptor> interceptors = managedChannel.getInterceptors();
            while (interceptors.hasNext()) {
                ChannelInterceptor interceptor = interceptors.next();
                storeElement(aWriter, indent, interceptor);
            }
        }
    }
}
Also used : ChannelReceiver(org.apache.catalina.tribes.ChannelReceiver) ManagedChannel(org.apache.catalina.tribes.ManagedChannel) Channel(org.apache.catalina.tribes.Channel) MembershipService(org.apache.catalina.tribes.MembershipService) ChannelInterceptor(org.apache.catalina.tribes.ChannelInterceptor) ChannelSender(org.apache.catalina.tribes.ChannelSender) ManagedChannel(org.apache.catalina.tribes.ManagedChannel)

Example 10 with ChannelInterceptor

use of org.apache.catalina.tribes.ChannelInterceptor in project tomcat by apache.

the class TestGroupChannelOptionFlag method testOptionConflict.

@Test
public void testOptionConflict() throws Exception {
    boolean error = false;
    channel.setOptionCheck(true);
    ChannelInterceptor i = new TestInterceptor();
    i.setOptionFlag(128);
    channel.addInterceptor(i);
    i = new TestInterceptor();
    i.setOptionFlag(128);
    channel.addInterceptor(i);
    try {
        channel.start(Channel.DEFAULT);
    } catch (ChannelException x) {
        if (x.getMessage().indexOf("option flag conflict") >= 0)
            error = true;
    }
    assertTrue(error);
}
Also used : ChannelInterceptor(org.apache.catalina.tribes.ChannelInterceptor) ChannelException(org.apache.catalina.tribes.ChannelException) Test(org.junit.Test)

Aggregations

ChannelInterceptor (org.apache.catalina.tribes.ChannelInterceptor)10 ChannelException (org.apache.catalina.tribes.ChannelException)3 Test (org.junit.Test)2 WeakReference (java.lang.ref.WeakReference)1 Channel (org.apache.catalina.tribes.Channel)1 ChannelReceiver (org.apache.catalina.tribes.ChannelReceiver)1 ChannelSender (org.apache.catalina.tribes.ChannelSender)1 ManagedChannel (org.apache.catalina.tribes.ManagedChannel)1 Member (org.apache.catalina.tribes.Member)1 MembershipService (org.apache.catalina.tribes.MembershipService)1 ChannelInterceptorBase (org.apache.catalina.tribes.group.ChannelInterceptorBase)1 MessageDispatchInterceptor (org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor)1 StaticMembershipInterceptor (org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor)1