use of org.apache.catalina.tribes.ManagedChannel in project tomcat by apache.
the class LoadTest method main.
public static void main(String[] args) throws Exception {
boolean send = true;
boolean debug = false;
long pause = 0;
int count = 1000000;
int stats = 10000;
boolean breakOnEx = false;
int threads = 1;
boolean shutdown = false;
int startoptions = Channel.DEFAULT;
int channelOptions = Channel.SEND_OPTIONS_DEFAULT;
if (args.length == 0) {
args = new String[] { "-help" };
}
for (int i = 0; i < args.length; i++) {
if ("-threads".equals(args[i])) {
threads = Integer.parseInt(args[++i]);
} else if ("-count".equals(args[i])) {
count = Integer.parseInt(args[++i]);
System.out.println("Sending " + count + " messages.");
} else if ("-pause".equals(args[i])) {
pause = Long.parseLong(args[++i]) * 1000;
} else if ("-break".equals(args[i])) {
breakOnEx = true;
} else if ("-shutdown".equals(args[i])) {
shutdown = true;
} else if ("-stats".equals(args[i])) {
stats = Integer.parseInt(args[++i]);
System.out.println("Stats every " + stats + " message");
} else if ("-sendoptions".equals(args[i])) {
channelOptions = Integer.parseInt(args[++i]);
System.out.println("Setting send options to " + channelOptions);
} else if ("-startoptions".equals(args[i])) {
startoptions = Integer.parseInt(args[++i]);
System.out.println("Setting start options to " + startoptions);
} else if ("-size".equals(args[i])) {
size = Integer.parseInt(args[++i]) - 4;
System.out.println("Message size will be:" + (size + 4) + " bytes");
} else if ("-mode".equals(args[i])) {
if ("receive".equals(args[++i]))
send = false;
} else if ("-debug".equals(args[i])) {
debug = true;
} else if ("-help".equals(args[i])) {
usage();
System.exit(1);
}
}
ManagedChannel channel = (ManagedChannel) ChannelCreator.createChannel(args);
LoadTest test = new LoadTest(channel, send, count, debug, pause, stats, breakOnEx);
test.channelOptions = channelOptions;
LoadMessage msg = new LoadMessage();
messageSize = LoadMessage.getMessageSize(msg);
channel.addChannelListener(test);
channel.addMembershipListener(test);
channel.start(startoptions);
Runtime.getRuntime().addShutdownHook(new Shutdown(channel));
while (threads > 1) {
Thread t = new Thread(test);
t.setDaemon(true);
t.start();
threads--;
test = new LoadTest(channel, send, count, debug, pause, stats, breakOnEx);
test.channelOptions = channelOptions;
}
test.run();
if (shutdown && send)
channel.stop(Channel.DEFAULT);
System.out.println("System test complete, sleeping to let threads finish.");
Thread.sleep(60 * 1000 * 60);
}
use of org.apache.catalina.tribes.ManagedChannel in project tomcat by apache.
the class MapDemo method main.
@SuppressWarnings("unused")
public static void main(String[] args) throws Exception {
long start = System.currentTimeMillis();
//create a channel object
ManagedChannel channel = (ManagedChannel) ChannelCreator.createChannel(args);
//define a map name, unless one is defined as a paramters
String mapName = "MapDemo";
if (args.length > 0 && (!args[args.length - 1].startsWith("-"))) {
mapName = args[args.length - 1];
}
//start the channel
channel.start(Channel.DEFAULT);
//listen for shutdown
Runtime.getRuntime().addShutdownHook(new Shutdown(channel));
//create a map demo object
new MapDemo(channel, mapName);
//put the main thread to sleep until we are done
System.out.println("System test complete, time to start=" + (System.currentTimeMillis() - start) + " ms. Sleeping to let threads finish.");
Thread.sleep(60 * 1000 * 60);
}
use of org.apache.catalina.tribes.ManagedChannel 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.ManagedChannel 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.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()).newInstance();
sender.setTimeout(acktimeout);
sender.setMaxRetryAttempts(2);
sender.setRxBufSize(43800);
sender.setTxBufSize(25188);
Iterator<Object> i = transportProperties.keySet().iterator();
while (i.hasNext()) {
String key = (String) i.next();
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 (int x = 0; x < staticMembers.size(); x++) {
smi.addStaticMember(staticMembers.get(x));
}
channel.addInterceptor(smi);
}
byte[] domain = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
((McastService) channel.getMembershipService()).setDomain(domain);
DomainFilterInterceptor filter = new DomainFilterInterceptor();
filter.setDomain(domain);
channel.addInterceptor(filter);
return channel;
}
use of org.apache.catalina.tribes.ManagedChannel in project tomcat by apache.
the class EchoRpcTest method main.
public static void main(String[] args) throws Exception {
long pause = 3000;
int count = 1000000;
int stats = 10000;
String name = "EchoRpcId";
int options = RpcChannel.ALL_REPLY;
long timeout = 15000;
String message = "EchoRpcMessage";
if (args.length == 0) {
usage();
System.exit(1);
}
for (int i = 0; i < args.length; i++) {
if ("-threads".equals(args[i])) {
// Not used
} else if ("-count".equals(args[i])) {
count = Integer.parseInt(args[++i]);
System.out.println("Sending " + count + " messages.");
} else if ("-pause".equals(args[i])) {
pause = Long.parseLong(args[++i]) * 1000;
} else if ("-break".equals(args[i])) {
// Not used
} else if ("-stats".equals(args[i])) {
stats = Integer.parseInt(args[++i]);
System.out.println("Stats every " + stats + " message");
} else if ("-timeout".equals(args[i])) {
timeout = Long.parseLong(args[++i]);
} else if ("-message".equals(args[i])) {
message = args[++i];
} else if ("-name".equals(args[i])) {
name = args[++i];
} else if ("-mode".equals(args[i])) {
if ("all".equals(args[++i]))
options = RpcChannel.ALL_REPLY;
else if ("first".equals(args[i]))
options = RpcChannel.FIRST_REPLY;
else if ("majority".equals(args[i]))
options = RpcChannel.MAJORITY_REPLY;
} else if ("-debug".equals(args[i])) {
// Not used
} else if ("-help".equals(args[i])) {
usage();
System.exit(1);
}
}
ManagedChannel channel = (ManagedChannel) ChannelCreator.createChannel(args);
EchoRpcTest test = new EchoRpcTest(channel, name, count, message, pause, options, timeout);
channel.start(Channel.DEFAULT);
Runtime.getRuntime().addShutdownHook(new Shutdown(channel));
test.run();
System.out.println("System test complete, sleeping to let threads finish.");
Thread.sleep(60 * 1000 * 60);
}
Aggregations