use of cbit.vcell.message.VCRpcMessageHandler in project vcell by virtualcell.
the class TestBlobRpcMessages method main.
public static void main(String[] args) throws Exception {
try {
PropertyLoader.loadProperties();
// System.getProperties().setProperty(PropertyLoader.jmsURL,"tcp://nrcamdev5.cam.uchc.edu:61616");
VCMessagingService messagingService = new VCMessagingServiceActiveMQ();
messagingService.setDelegate(new SimpleMessagingDelegate());
// reading message and computing sum
// create N comsumers
MyRpcServer myRpcServer = new MyRpcServer();
for (int i = 0; i < NUM_COMSUMERS; i++) {
VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellTestQueue.JimQueue);
VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, rpcMessageHandler, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== RPC Consumer Thread " + i, 1);
messagingService.addMessageConsumer(rpcConsumer);
}
// creating one messageProducer session
ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
for (int i = 0; i < NUM_PRODUCERS; i++) {
sessions.add(messagingService.createProducerSession());
}
for (int i = 0; i < NUM_MESSAGES; i++) {
for (int s = 0; s < NUM_PRODUCERS; s++) {
VCMessageSession session = sessions.get(s);
try {
//
// create simple RPC request for service "Testing_Service"
//
User user = new User("schaff", new KeyValue("17"));
byte[] array1 = new byte[20000000];
byte[] array2 = new byte[20000000];
VCRpcRequest rpcRequest = new VCRpcRequest(user, RpcServiceType.TESTING_SERVICE, "concat", new Object[] { array1, array2 });
//
// send request and block for response (or timeout).
// RPC invocations don't need commits.
//
Object returnValue = session.sendRpcMessage(VCellTestQueue.JimQueue, rpcRequest, true, 20000, null, null, null);
//
if (returnValue instanceof byte[]) {
System.out.println("concat(byte[" + array1.length + "], byte[" + array2.length + "]) ===> byte[" + (((byte[]) returnValue).length) + "]");
} else {
System.out.println("unexpected return value of " + returnValue);
}
} catch (VCMessagingInvocationTargetException e) {
e.printStackTrace(System.out);
System.out.println("the rpc service threw an exception");
e.getTargetException().printStackTrace(System.out);
}
}
}
System.out.println("main program calling closeAll()");
messagingService.close();
System.out.println("main program exiting");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of cbit.vcell.message.VCRpcMessageHandler in project vcell by virtualcell.
the class DatabaseServer method init.
public void init() throws Exception {
int numDatabaseThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.databaseThreadsProperty, "5"));
this.sharedProducerSession = vcMessagingService.createProducerSession();
rpcMessageHandler = new VCRpcMessageHandler(databaseServerImpl, VCellQueue.DbRequestQueue);
this.pooledQueueConsumer = new VCPooledQueueConsumer(rpcMessageHandler, numDatabaseThreads, sharedProducerSession);
this.pooledQueueConsumer.initThreadPool();
rpcConsumer = new VCQueueConsumer(VCellQueue.DbRequestQueue, this.pooledQueueConsumer, null, "Database RPC Server Thread", MessageConstants.PREFETCH_LIMIT_DB_REQUEST);
vcMessagingService.addMessageConsumer(rpcConsumer);
initControlTopicListener();
}
use of cbit.vcell.message.VCRpcMessageHandler in project vcell by virtualcell.
the class SimulationDispatcher method init.
public void init() {
//
// set up consumer for WorkerEvent messages
//
QueueListener workerEventListener = new QueueListener() {
public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
onWorkerEventMessage(vcMessage, session);
}
};
VCMessageSelector workerEventSelector = null;
String threadName = "Worker Event Consumer";
workerEventConsumer = new VCQueueConsumer(VCellQueue.WorkerEventQueue, workerEventListener, workerEventSelector, threadName, MessageConstants.PREFETCH_LIMIT_WORKER_EVENT);
vcMessagingService.addMessageConsumer(workerEventConsumer);
//
// set up consumer for Simulation Request (non-blocking RPC) messages
//
SimulationService simServiceImpl = new SimulationServiceImpl();
VCMessageSelector simRequestSelector = null;
threadName = "Sim Request Consumer";
this.rpcMessageHandler = new VCRpcMessageHandler(simServiceImpl, VCellQueue.SimReqQueue);
simRequestConsumer = new VCQueueConsumer(VCellQueue.SimReqQueue, rpcMessageHandler, simRequestSelector, threadName, MessageConstants.PREFETCH_LIMIT_SIM_REQUEST);
vcMessagingService.addMessageConsumer(simRequestConsumer);
this.dispatcherQueueSession = vcMessagingService.createProducerSession();
this.dispatchThread = new DispatchThread();
this.dispatchThread.start();
initControlTopicListener();
this.simMonitorThreadSession = vcMessagingService.createProducerSession();
this.simMonitor = new SimulationMonitor();
}
use of cbit.vcell.message.VCRpcMessageHandler in project vcell by virtualcell.
the class SimDataServer method init.
public void init() throws Exception {
String dataRequestFilter = "(" + VCMessagingConstants.MESSAGE_TYPE_PROPERTY + "='" + VCMessagingConstants.MESSAGE_TYPE_RPC_SERVICE_VALUE + "') " + " AND (" + VCMessagingConstants.SERVICE_TYPE_PROPERTY + "='" + ServiceType.DATA.getName() + "')";
String exportOnlyFilter = "(" + ServiceType.DATAEXPORT.getName() + " is NOT NULL)";
String dataOnlyFilter = "(" + ServiceType.DATAEXPORT.getName() + " is NULL)";
VCMessageSelector selector;
ServiceType serviceType = serviceInstanceStatus.getType();
int numThreads;
if (serviceType == ServiceType.DATAEXPORT) {
selector = vcMessagingService.createSelector(dataRequestFilter + " AND " + exportOnlyFilter);
numThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.exportdataThreadsProperty, "3"));
} else if (serviceType == ServiceType.DATA) {
selector = vcMessagingService.createSelector(dataRequestFilter + " AND " + dataOnlyFilter);
numThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.simdataThreadsProperty, "5"));
} else {
throw new RuntimeException("expecting either Service type of " + ServiceType.DATA + " or " + ServiceType.DATAEXPORT);
}
this.sharedProducerSession = vcMessagingService.createProducerSession();
rpcMessageHandler = new VCRpcMessageHandler(dataServerImpl, VCellQueue.DataRequestQueue);
this.pooledQueueConsumer = new VCPooledQueueConsumer(rpcMessageHandler, numThreads, sharedProducerSession);
this.pooledQueueConsumer.initThreadPool();
rpcConsumer = new VCQueueConsumer(VCellQueue.DataRequestQueue, pooledQueueConsumer, selector, serviceType.getName() + " RPC Server Thread", MessageConstants.PREFETCH_LIMIT_DATA_REQUEST);
vcMessagingService.addMessageConsumer(rpcConsumer);
initControlTopicListener();
}
use of cbit.vcell.message.VCRpcMessageHandler in project vcell by virtualcell.
the class TestRPC method main.
public static void main(String[] args) throws Exception {
try {
PropertyLoader.loadProperties();
VCMessagingService messagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
messagingService.setDelegate(new SimpleMessagingDelegate());
// reading message and computing sum
// create N comsumers
MyRpcServer myRpcServer = new MyRpcServer();
VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellTestQueue.JimQueue);
VCPooledQueueConsumer pooledQueueConsumer = new VCPooledQueueConsumer(rpcMessageHandler, NUM_THREADS, messagingService.createProducerSession());
pooledQueueConsumer.initThreadPool();
VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, pooledQueueConsumer, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== RPC Consumer Master Thread ", 1000);
// VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellQueue.JimQueue, log);
// VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellQueue.JimQueue, rpcMessageHandler, null, "Queue["+VCellQueue.JimQueue.getName()+"] ==== RPC Consumer Master Thread ", 1000);
messagingService.addMessageConsumer(rpcConsumer);
for (int i = 0; i < NUM_MESSAGES; i++) {
// creating one messageProducer session
final VCMessageSession messageSession = messagingService.createProducerSession();
class MyTask implements Runnable {
int msgNum;
MyTask(int msgNum) {
this.msgNum = msgNum;
}
public void run() {
try {
//
// create simple RPC request for service "Testing_Service"
//
User user = new User("schaff", new KeyValue("17"));
Integer n1 = new Integer(msgNum);
Integer n2 = new Integer(msgNum + 1);
VCRpcRequest rpcRequest = new VCRpcRequest(user, RpcServiceType.TESTING_SERVICE, "add", new Object[] { n1, n2 });
//
// send request and block for response (or timeout).
// RPC invocations don't need commits.
//
Object returnValue = messageSession.sendRpcMessage(VCellTestQueue.JimQueue, rpcRequest, true, 20000, null, null, null);
//
if (returnValue instanceof Integer) {
System.out.println("add(" + n1 + "," + n2 + ") ===> " + returnValue);
} else {
System.out.println("unexpected return value of " + returnValue);
}
} catch (VCMessagingInvocationTargetException e) {
e.printStackTrace(System.out);
System.out.println("the rpc service threw an exception");
e.getTargetException().printStackTrace(System.out);
} catch (VCMessagingException e) {
e.printStackTrace();
}
}
}
;
new Thread(new MyTask(i)).start();
}
Thread.sleep(2000);
System.out.println("main program calling closeAll()");
pooledQueueConsumer.shutdownAndAwaitTermination();
messagingService.close();
System.out.println("main program exiting");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
Aggregations