use of cbit.vcell.message.VCQueueConsumer 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.VCQueueConsumer in project vcell by virtualcell.
the class ConsumerContextJms method run.
public void run() {
bProcessing = true;
System.out.println(toString() + " consumer thread starting.");
while (bProcessing) {
MessageProducerSessionJms temporaryMessageProducerSession = null;
try {
Message jmsMessage = jmsMessageConsumer.receive(CONSUMER_POLLING_INTERVAL_MS);
if (jmsMessage != null) {
// System.out.println(toString()+"===============message received within "+CONSUMER_POLLING_INTERVAL_MS+" ms");
if (vcConsumer instanceof VCQueueConsumer) {
VCQueueConsumer queueConsumer = (VCQueueConsumer) vcConsumer;
VCMessageJms vcMessage = new VCMessageJms(jmsMessage, vcMessagingServiceJms.getDelegate());
vcMessage.loadBlobFile();
vcMessagingServiceJms.getDelegate().onMessageReceived(vcMessage, vcConsumer.getVCDestination());
temporaryMessageProducerSession = new MessageProducerSessionJms(vcMessagingServiceJms);
queueConsumer.getQueueListener().onQueueMessage(vcMessage, temporaryMessageProducerSession);
temporaryMessageProducerSession.commit();
jmsSession.commit();
vcMessage.removeBlobFile();
} else if (vcConsumer instanceof VCTopicConsumer) {
VCTopicConsumer topicConsumer = (VCTopicConsumer) vcConsumer;
VCMessageJms vcMessage = new VCMessageJms(jmsMessage, vcMessagingServiceJms.getDelegate());
vcMessage.loadBlobFile();
vcMessagingServiceJms.getDelegate().onMessageReceived(vcMessage, vcConsumer.getVCDestination());
temporaryMessageProducerSession = new MessageProducerSessionJms(vcMessagingServiceJms);
topicConsumer.getTopicListener().onTopicMessage(vcMessage, temporaryMessageProducerSession);
temporaryMessageProducerSession.commit();
jmsSession.commit();
//
// if we knew this was the only subscriber for this topic, then remove file immediately.
// since we don't know for sure, don't remove the file here.
// instead, we need to periodically remove old Blob files (maybe daily)
//
// vcMessage.removeBlobFile();
} else {
throw new RuntimeException("unexpected VCConsumer type " + vcConsumer);
}
} else {
// System.out.println(toString()+"no message received within "+CONSUMER_POLLING_INTERVAL_MS+" ms");
}
} catch (JMSException e) {
onException(e);
} catch (RollbackException e) {
log.exception(e);
try {
jmsSession.rollback();
} catch (JMSException e1) {
onException(e1);
}
} catch (Exception e) {
log.exception(e);
} finally {
if (temporaryMessageProducerSession != null) {
temporaryMessageProducerSession.close();
}
}
}
System.out.println(toString() + " consumer thread exiting.");
}
use of cbit.vcell.message.VCQueueConsumer 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.VCQueueConsumer 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.VCQueueConsumer in project vcell by virtualcell.
the class HtcSimulationWorker method initQueueConsumer.
private void initQueueConsumer() {
this.sharedMessageProducer = vcMessagingService.createProducerSession();
QueueListener queueListener = new QueueListener() {
@Override
public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
SimulationTask simTask = null;
try {
SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(vcMessage);
simTask = simTaskMessage.getSimulationTask();
if (lg.isInfoEnabled()) {
lg.info("onQueueMessage() run simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
}
PostProcessingChores rd = choresFor(simTask);
HtcProxy clonedHtcProxy = htcProxy.cloneThreadsafe();
if (lg.isInfoEnabled()) {
lg.info("onQueueMessage() submit job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
}
HtcJobID pbsId = submit2PBS(simTask, clonedHtcProxy, rd);
if (lg.isInfoEnabled()) {
lg.info("onQueueMessage() sending 'accepted' message for job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
}
synchronized (sharedMessageProducer) {
WorkerEventMessage.sendAccepted(sharedMessageProducer, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), pbsId);
}
if (lg.isInfoEnabled()) {
lg.info("onQueueMessage() sent 'accepted' message for job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
}
} catch (Exception e) {
lg.error(e.getMessage(), e);
if (simTask != null) {
try {
lg.error("failed to process simTask request: " + e.getMessage() + " for simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName(), e);
synchronized (sharedMessageProducer) {
WorkerEventMessage.sendFailed(sharedMessageProducer, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), SimulationMessage.jobFailed(e.getMessage()));
}
lg.error("sent 'failed' message for simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName(), e);
} catch (VCMessagingException e1) {
lg.error(e1.getMessage(), e);
}
} else {
lg.error("failed to process simTask request: " + e.getMessage(), e);
}
}
}
};
int numHtcworkerThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.htcworkerThreadsProperty, "5"));
this.pooledQueueConsumer = new VCPooledQueueConsumer(queueListener, numHtcworkerThreads, sharedMessageProducer);
this.pooledQueueConsumer.initThreadPool();
VCellQueue queue = VCellQueue.SimJobQueue;
VCMessageSelector selector = vcMessagingService.createSelector(getJobSelector());
String threadName = "SimJob Queue Consumer";
queueConsumer = new VCQueueConsumer(queue, pooledQueueConsumer, selector, threadName, MessageConstants.PREFETCH_LIMIT_SIM_JOB_HTC);
vcMessagingService.addMessageConsumer(queueConsumer);
}
Aggregations