use of org.apache.catalina.tribes.Channel in project tomcat by apache.
the class CatalinaClusterSF method storeChildren.
/**
* Store the specified Cluster children.
*
* @param aWriter
* PrintWriter to which we are storing
* @param indent
* Number of spaces to indent this element
* @param aCluster
* Cluster whose properties are being stored
*
* @exception Exception
* if an exception occurs while storing
*/
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aCluster, StoreDescription parentDesc) throws Exception {
if (aCluster instanceof CatalinaCluster) {
CatalinaCluster cluster = (CatalinaCluster) aCluster;
if (cluster instanceof SimpleTcpCluster) {
SimpleTcpCluster tcpCluster = (SimpleTcpCluster) cluster;
// Store nested <Manager> element
ClusterManager manager = tcpCluster.getManagerTemplate();
if (manager != null) {
storeElement(aWriter, indent, manager);
}
}
// Store nested <Channel> element
Channel channel = cluster.getChannel();
if (channel != null) {
storeElement(aWriter, indent, channel);
}
// Store nested <Deployer> element
ClusterDeployer deployer = cluster.getClusterDeployer();
if (deployer != null) {
storeElement(aWriter, indent, deployer);
}
// Store nested <Valve> element
// ClusterValve are not store at Hosts element, see
Valve[] valves = cluster.getValves();
storeElementArray(aWriter, indent, valves);
if (aCluster instanceof SimpleTcpCluster) {
// Store nested <Listener> elements
LifecycleListener[] listeners = ((SimpleTcpCluster) cluster).findLifecycleListeners();
storeElementArray(aWriter, indent, listeners);
// Store nested <ClusterListener> elements
ClusterListener[] mlisteners = ((SimpleTcpCluster) cluster).findClusterListeners();
List<ClusterListener> clusterListeners = new ArrayList<>();
for (ClusterListener clusterListener : mlisteners) {
if (clusterListener != deployer) {
clusterListeners.add(clusterListener);
}
}
storeElementArray(aWriter, indent, clusterListeners.toArray());
}
}
}
use of org.apache.catalina.tribes.Channel in project tomcat by apache.
the class TestGroupChannelMemberArrival method testMemberArrival.
@Test
public void testMemberArrival() throws Exception {
//purpose of this test is to make sure that we have received all the members
//that we can expect before the start method returns
Thread[] threads = new Thread[channels.length];
for (int i = 0; i < channels.length; i++) {
final Channel channel = channels[i];
Thread t = new Thread() {
@Override
public void run() {
try {
channel.start(Channel.DEFAULT);
} catch (Exception x) {
throw new RuntimeException(x);
}
}
};
threads[i] = t;
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
Thread.sleep(5000);
System.out.println(System.currentTimeMillis() + " All channels started.");
StringBuilder arrivalLengthErrors = new StringBuilder();
for (int i = listeners.length - 1; i >= 0; i--) {
TestMbrListener listener = listeners[i];
synchronized (listener.members) {
if (channels.length - 1 != listener.members.size()) {
arrivalLengthErrors.append("Checking member arrival length for [");
arrivalLengthErrors.append(listener.name);
arrivalLengthErrors.append("]. Was [");
arrivalLengthErrors.append(listener.members.size());
arrivalLengthErrors.append("] but should have been [");
arrivalLengthErrors.append(channels.length - 1);
arrivalLengthErrors.append("]");
arrivalLengthErrors.append('\n');
}
}
}
// Note if this fails for all listeners check multicast is working with
// org.apache.catalina.tribes.TesterMulticast
Assert.assertTrue(arrivalLengthErrors.toString(), arrivalLengthErrors.length() == 0);
System.out.println(System.currentTimeMillis() + " Members arrival counts checked.");
}
use of org.apache.catalina.tribes.Channel 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.Channel in project tomcat by apache.
the class TestDomainFilterInterceptor method testMemberArrival.
@Test
public void testMemberArrival() throws Exception {
//purpose of this test is to make sure that we have received all the members
//that we can expect before the start method returns
Thread[] threads = new Thread[channels.length];
for (int i = 0; i < channels.length; i++) {
final Channel channel = channels[i];
Thread t = new Thread() {
@Override
public void run() {
try {
channel.start(Channel.DEFAULT);
} catch (Exception x) {
throw new RuntimeException(x);
}
}
};
threads[i] = t;
}
for (int i = 0; i < threads.length; i++) threads[i].start();
for (int i = 0; i < threads.length; i++) threads[i].join();
System.out.println("All channels started.");
for (int i = listeners.length - 1; i >= 0; i--) assertEquals("Checking member arrival length", 0, listeners[i].members.size());
}
Aggregations