use of cbit.vcell.message.RollbackException 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.RollbackException 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);
}
use of cbit.vcell.message.RollbackException in project vcell by virtualcell.
the class TestQueues method main.
public static void main(String[] args) throws Exception {
try {
PropertyLoader.loadProperties();
VCMessagingService messagingService = new VCMessagingServiceEmbedded();
messagingService.setDelegate(new SimpleMessagingDelegate());
final Calculator calculator = new Calculator();
// creating one messageProducer session
ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
for (int i = 0; i < NUM_PRODUCERS; i++) {
sessions.add(messagingService.createProducerSession());
}
int sum = 0;
for (int i = 0; i < NUM_MESSAGES; i++) {
for (int s = 0; s < NUM_PRODUCERS; s++) {
sum++;
VCMessageSession session = sessions.get(s);
VCMessage message = session.createTextMessage("message " + i + " from session " + s);
session.sendQueueMessage(VCellTestQueue.JimQueue, message, false, 100000L);
session.commit();
}
Thread.sleep(2000);
}
System.out.println("Correct sum is " + sum);
Thread.sleep(30);
// create N comsumers
for (int i = 0; i < NUM_COMSUMERS; i++) {
QueueListener listener = new QueueListener() {
public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
// new Thread()
System.out.println("timestampMS=" + vcMessage.getTimestampMS() + ", " + toString() + ", elapsedTimeS=" + ((System.currentTimeMillis() - vcMessage.getTimestampMS()) / 1000.0) + ", Received: " + vcMessage.getTextContent());
// int number = Integer.parseInt(vcMessage.getTextContent());
calculator.add(1);
}
};
VCQueueConsumer queueConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, listener, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== Consumer Thread " + i, 1);
messagingService.addMessageConsumer(queueConsumer);
}
while (calculator.getSum() < sum) {
System.out.println("calculator sum = " + calculator.getSum());
Thread.sleep(1000);
}
System.out.println("calculator sum = " + calculator.getSum());
System.out.println("main program calling closeAll()");
messagingService.close();
System.out.println("main program exiting");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
Aggregations