use of org.apache.catalina.tribes.transport.ReceiverBase in project tomcat by apache.
the class TestTcpFailureDetector method setUp.
@Before
public void setUp() throws Exception {
channel1 = new GroupChannel();
channel2 = new GroupChannel();
((ReceiverBase) channel1.getChannelReceiver()).setHost("localhost");
((ReceiverBase) channel2.getChannelReceiver()).setHost("localhost");
channel1.getMembershipService().setPayload("Channel-1".getBytes("ASCII"));
channel2.getMembershipService().setPayload("Channel-2".getBytes("ASCII"));
mbrlist1 = new TestMbrListener("Channel-1");
mbrlist2 = new TestMbrListener("Channel-2");
tcpFailureDetector1 = new TcpFailureDetector();
tcpFailureDetector2 = new TcpFailureDetector();
channel1.addInterceptor(tcpFailureDetector1);
channel2.addInterceptor(tcpFailureDetector2);
channel1.addMembershipListener(mbrlist1);
channel2.addMembershipListener(mbrlist2);
TesterUtil.addRandomDomain(new ManagedChannel[] { channel1, channel2 });
}
use of org.apache.catalina.tribes.transport.ReceiverBase in project tomcat70 by apache.
the class TestMulticastPackages method testDataSendASYNCM.
@Test
public void testDataSendASYNCM() throws Exception {
final AtomicInteger counter = new AtomicInteger(0);
ReceiverBase rb1 = (ReceiverBase) channel1.getChannelReceiver();
ReceiverBase rb2 = (ReceiverBase) channel2.getChannelReceiver();
rb1.setUdpRxBufSize(1024 * 1024 * 10);
rb2.setUdpRxBufSize(1024 * 1024 * 10);
rb1.setUdpTxBufSize(1024 * 1024 * 10);
rb2.setUdpTxBufSize(1024 * 1024 * 10);
System.err.println("Starting NO_ACK");
Thread[] threads = new Thread[threadCount];
for (int x = 0; x < threads.length; x++) {
threads[x] = new Thread() {
@Override
public void run() {
try {
long start = System.currentTimeMillis();
for (int i = 0; i < msgCount; i++) {
int cnt = counter.getAndAdd(1);
channel1.send(new Member[] { channel2.getLocalMember(false) }, Data.createRandomData(1024, cnt), Channel.SEND_OPTIONS_MULTICAST | Channel.SEND_OPTIONS_ASYNCHRONOUS);
// Thread.currentThread().sleep(10);
}
System.out.println("Thread[" + this.getName() + "] sent " + msgCount + " messages in " + (System.currentTimeMillis() - start) + " ms.");
} catch (Exception x) {
x.printStackTrace();
return;
}
}
};
}
for (int x = 0; x < threads.length; x++) {
threads[x].start();
}
for (int x = 0; x < threads.length; x++) {
threads[x].join();
}
// sleep for 50 sec, let the other messages in
long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < 25000 && msgCount * threadCount != listener1.count.get()) Thread.sleep(500);
System.err.println("Finished NO_ACK [" + listener1.count + "]");
System.out.println("Sent " + counter.get() + " messages. Received " + listener1.count + " Highest msg received:" + listener1.maxIdx);
System.out.print("Missing messages:");
printMissingMsgs(listener1.nrs, counter.get());
Assert.assertEquals("Checking success messages.", msgCount * threadCount, listener1.count.get());
}
use of org.apache.catalina.tribes.transport.ReceiverBase in project tomcat70 by apache.
the class ChannelCoordinator method internalStart.
/**
* Starts up the channel. This can be called multiple times for individual services to start
* The svc parameter can be the logical or value of any constants
* @param svc int value of <BR>
* DEFAULT - will start all services <BR>
* MBR_RX_SEQ - starts the membership receiver <BR>
* MBR_TX_SEQ - starts the membership broadcaster <BR>
* SND_TX_SEQ - starts the replication transmitter<BR>
* SND_RX_SEQ - starts the replication receiver<BR>
* @throws ChannelException if a startup error occurs or the service is already started.
*/
protected synchronized void internalStart(int svc) throws ChannelException {
try {
boolean valid = false;
// make sure we don't pass down any flags that are unrelated to the bottom layer
svc = svc & Channel.DEFAULT;
// we have already started up all components
if (startLevel == Channel.DEFAULT)
return;
// nothing to start
if (svc == 0)
return;
if (svc == (svc & startLevel))
throw new ChannelException("Channel already started for level:" + svc);
// listens to with the local membership settings
if (Channel.SND_RX_SEQ == (svc & Channel.SND_RX_SEQ)) {
clusterReceiver.setMessageListener(this);
if (clusterReceiver instanceof ReceiverBase) {
((ReceiverBase) clusterReceiver).setChannel(getChannel());
}
clusterReceiver.start();
// synchronize, big time FIXME
Member localMember = getChannel().getLocalMember(false);
if (localMember instanceof StaticMember) {
// static member
StaticMember staticMember = (StaticMember) localMember;
staticMember.setHost(getClusterReceiver().getHost());
staticMember.setPort(getClusterReceiver().getPort());
staticMember.setSecurePort(getClusterReceiver().getSecurePort());
} else {
// multicast member
membershipService.setLocalMemberProperties(getClusterReceiver().getHost(), getClusterReceiver().getPort(), getClusterReceiver().getSecurePort(), getClusterReceiver().getUdpPort());
}
valid = true;
}
if (Channel.SND_TX_SEQ == (svc & Channel.SND_TX_SEQ)) {
if (clusterSender instanceof ReplicationTransmitter) {
((ReplicationTransmitter) clusterSender).setChannel(getChannel());
}
valid = true;
clusterSender.start();
}
if (Channel.MBR_RX_SEQ == (svc & Channel.MBR_RX_SEQ)) {
membershipService.setMembershipListener(this);
if (membershipService instanceof McastService) {
((McastService) membershipService).setMessageListener(this);
((McastService) membershipService).setChannel(getChannel());
}
membershipService.start(MembershipService.MBR_RX);
valid = true;
}
if (Channel.MBR_TX_SEQ == (svc & Channel.MBR_TX_SEQ)) {
if (membershipService instanceof McastService) {
((McastService) membershipService).setChannel(getChannel());
}
membershipService.start(MembershipService.MBR_TX);
valid = true;
}
if (!valid) {
throw new IllegalArgumentException("Invalid start level, valid levels are:SND_RX_SEQ,SND_TX_SEQ,MBR_TX_SEQ,MBR_RX_SEQ");
}
startLevel = (startLevel | svc);
} catch (ChannelException cx) {
throw cx;
} catch (Exception x) {
throw new ChannelException(x);
}
}
use of org.apache.catalina.tribes.transport.ReceiverBase in project tomcat by apache.
the class ChannelCreator method createChannel.
public static Channel createChannel(String[] args) throws Exception {
String bind = "auto";
int port = 4001;
String mbind = null;
boolean gzip = false;
int tcpseltimeout = 5000;
int tcpthreadcount = 4;
int acktimeout = 15000;
String mcastaddr = "228.0.0.5";
int mcastport = 45565;
long mcastfreq = 500;
long mcastdrop = 2000;
boolean order = false;
int ordersize = Integer.MAX_VALUE;
boolean frag = false;
int fragsize = 1024;
int autoBind = 10;
ArrayList<Member> staticMembers = new ArrayList<>();
Properties transportProperties = new Properties();
String transport = "org.apache.catalina.tribes.transport.nio.PooledParallelSender";
String receiver = "org.apache.catalina.tribes.transport.nio.NioReceiver";
boolean async = false;
// 50MB
int asyncsize = 1024 * 1024 * 50;
boolean throughput = false;
boolean failuredetect = false;
for (int i = 0; i < args.length; i++) {
if ("-bind".equals(args[i])) {
bind = args[++i];
} else if ("-port".equals(args[i])) {
port = Integer.parseInt(args[++i]);
} else if ("-autobind".equals(args[i])) {
autoBind = Integer.parseInt(args[++i]);
} else if ("-tcpselto".equals(args[i])) {
tcpseltimeout = Integer.parseInt(args[++i]);
} else if ("-tcpthreads".equals(args[i])) {
tcpthreadcount = Integer.parseInt(args[++i]);
} else if ("-gzip".equals(args[i])) {
gzip = true;
} else if ("-async".equals(args[i])) {
async = true;
} else if ("-failuredetect".equals(args[i])) {
failuredetect = true;
} else if ("-asyncsize".equals(args[i])) {
asyncsize = Integer.parseInt(args[++i]);
System.out.println("Setting MessageDispatchInterceptor.maxQueueSize=" + asyncsize);
} else if ("-static".equals(args[i])) {
String d = args[++i];
String h = d.substring(0, d.indexOf(':'));
String p = d.substring(h.length() + 1);
Member m = new MemberImpl(h, Integer.parseInt(p), 2000);
staticMembers.add(m);
} else if ("-throughput".equals(args[i])) {
throughput = true;
} else if ("-order".equals(args[i])) {
order = true;
} else if ("-ordersize".equals(args[i])) {
ordersize = Integer.parseInt(args[++i]);
System.out.println("Setting OrderInterceptor.maxQueue=" + ordersize);
} else if ("-frag".equals(args[i])) {
frag = true;
} else if ("-fragsize".equals(args[i])) {
fragsize = Integer.parseInt(args[++i]);
System.out.println("Setting FragmentationInterceptor.maxSize=" + fragsize);
} else if ("-ackto".equals(args[i])) {
acktimeout = Integer.parseInt(args[++i]);
} else if ("-transport".equals(args[i])) {
transport = args[++i];
} else if (args[i] != null && args[i].startsWith("transport.")) {
String key = args[i];
String val = args[++i];
transportProperties.setProperty(key, val);
} else if ("-receiver".equals(args[i])) {
receiver = args[++i];
} else if ("-maddr".equals(args[i])) {
mcastaddr = args[++i];
} else if ("-mport".equals(args[i])) {
mcastport = Integer.parseInt(args[++i]);
} else if ("-mfreq".equals(args[i])) {
mcastfreq = Long.parseLong(args[++i]);
} else if ("-mdrop".equals(args[i])) {
mcastdrop = Long.parseLong(args[++i]);
} else if ("-mbind".equals(args[i])) {
mbind = args[++i];
}
}
System.out.println("Creating receiver class=" + receiver);
Class<?> cl = Class.forName(receiver, true, ChannelCreator.class.getClassLoader());
ReceiverBase rx = (ReceiverBase) cl.getConstructor().newInstance();
rx.setAddress(bind);
rx.setPort(port);
rx.setSelectorTimeout(tcpseltimeout);
rx.setMaxThreads(tcpthreadcount);
rx.setMinThreads(tcpthreadcount);
rx.getBind();
rx.setRxBufSize(43800);
rx.setTxBufSize(25188);
rx.setAutoBind(autoBind);
ReplicationTransmitter ps = new ReplicationTransmitter();
System.out.println("Creating transport class=" + transport);
MultiPointSender sender = (MultiPointSender) Class.forName(transport, true, ChannelCreator.class.getClassLoader()).getConstructor().newInstance();
sender.setTimeout(acktimeout);
sender.setMaxRetryAttempts(2);
sender.setRxBufSize(43800);
sender.setTxBufSize(25188);
for (Object o : transportProperties.keySet()) {
String key = (String) o;
IntrospectionUtils.setProperty(sender, key, transportProperties.getProperty(key));
}
ps.setTransport(sender);
McastService service = new McastService();
service.setAddress(mcastaddr);
if (mbind != null) {
service.setMcastBindAddress(mbind);
}
service.setFrequency(mcastfreq);
service.setMcastDropTime(mcastdrop);
service.setPort(mcastport);
ManagedChannel channel = new GroupChannel();
channel.setChannelReceiver(rx);
channel.setChannelSender(ps);
channel.setMembershipService(service);
if (throughput) {
channel.addInterceptor(new ThroughputInterceptor());
}
if (gzip) {
channel.addInterceptor(new GzipInterceptor());
}
if (frag) {
FragmentationInterceptor fi = new FragmentationInterceptor();
fi.setMaxSize(fragsize);
channel.addInterceptor(fi);
}
if (order) {
OrderInterceptor oi = new OrderInterceptor();
oi.setMaxQueue(ordersize);
channel.addInterceptor(oi);
}
if (async) {
MessageDispatchInterceptor mi = new MessageDispatchInterceptor();
mi.setMaxQueueSize(asyncsize);
channel.addInterceptor(mi);
System.out.println("Added MessageDispatchInterceptor");
}
if (failuredetect) {
TcpFailureDetector tcpfi = new TcpFailureDetector();
channel.addInterceptor(tcpfi);
}
if (staticMembers.size() > 0) {
StaticMembershipInterceptor smi = new StaticMembershipInterceptor();
for (Member staticMember : staticMembers) {
smi.addStaticMember(staticMember);
}
channel.addInterceptor(smi);
}
byte[] domain = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
channel.getMembershipService().setDomain(domain);
DomainFilterInterceptor filter = new DomainFilterInterceptor();
filter.setDomain(domain);
channel.addInterceptor(filter);
return channel;
}
use of org.apache.catalina.tribes.transport.ReceiverBase in project tomcat by apache.
the class TestNonBlockingCoordinator method setUp.
@Before
public void setUp() throws Exception {
LogManager.getLogManager().getLogger("org.apache.catalina.tribes.group.interceptors.TestNonBlockingCoordinator").setLevel(Level.ALL);
try {
log.info("Setup");
channels = new GroupChannel[CHANNEL_COUNT];
coordinators = new NonBlockingCoordinator[CHANNEL_COUNT];
Thread[] threads = new Thread[CHANNEL_COUNT];
for (int i = 0; i < CHANNEL_COUNT; i++) {
channels[i] = new GroupChannel();
((ReceiverBase) channels[i].getChannelReceiver()).setHost("localhost");
coordinators[i] = new NonBlockingCoordinator();
channels[i].addInterceptor(coordinators[i]);
TcpFailureDetector tcpFailureDetector = new TcpFailureDetector();
// Double default timeout - mainly for loaded CI systems
tcpFailureDetector.setReadTestTimeout(tcpFailureDetector.getReadTestTimeout() * 2);
channels[i].addInterceptor(tcpFailureDetector);
final int j = i;
threads[i] = new Thread() {
@Override
public void run() {
try {
channels[j].start(Channel.DEFAULT);
} catch (Exception x) {
x.printStackTrace();
}
}
};
}
TesterUtil.addRandomDomain(channels);
for (int i = 0; i < CHANNEL_COUNT; i++) {
threads[i].start();
}
for (int i = 0; i < CHANNEL_COUNT; i++) {
threads[i].join();
}
// Allow up to 30s for cluster to form once all the nodes have been
// started
int count = 0;
Member member = null;
boolean electionComplete = false;
while (!electionComplete && count < 300) {
electionComplete = true;
member = coordinators[0].getCoordinator();
if (member == null) {
electionComplete = false;
} else {
for (int i = 0; i < CHANNEL_COUNT; i++) {
electionComplete = electionComplete && (member.equals(coordinators[i].getCoordinator()));
}
}
Thread.sleep(100);
count++;
}
} finally {
LogManager.getLogManager().getLogger("org.apache.catalina.tribes.group.interceptors.TestNonBlockingCoordinator").setLevel(Level.INFO);
}
}
Aggregations