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 -> C -> B</code><br>
* The complete stack will look like this:<br>
* <code>Channel -> A -> C -> B -> 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);
}
}
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"));
}
}
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();
}
}
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);
}
}
}
}
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);
}
Aggregations