use of cbit.vcell.message.VCMessagingException in project vcell by virtualcell.
the class SimDataServer method dataJobMessage.
/**
* Insert the method's description here.
* Creation date: (3/31/2006 8:48:04 AM)
* @param event cbit.rmi.event.ExportEvent
*/
public void dataJobMessage(cbit.rmi.event.DataJobEvent event) {
try {
VCMessageSession dataSession = vcMessagingService.createProducerSession();
VCMessage dataEventMessage = dataSession.createObjectMessage(event);
dataEventMessage.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_DATA_EVENT_VALUE);
dataEventMessage.setStringProperty(VCMessagingConstants.USERNAME_PROPERTY, event.getUser().getName());
dataSession.sendTopicMessage(VCellTopic.ClientStatusTopic, dataEventMessage);
dataSession.close();
} catch (VCMessagingException ex) {
lg.error(ex.getMessage(), ex);
}
}
use of cbit.vcell.message.VCMessagingException in project vcell by virtualcell.
the class MessageProducerSessionJms method sendRpcMessage.
// public MessageProducerSessionJms(Session session, VCMessagingServiceJms vcMessagingServiceJms) {
// System.out.println("-----\nmpjms MessageProducerSessionJms(Session session, VCMessagingServiceJms vcMessagingServiceJms)\ntmpQCnt="+(++tmpQCnt)+"----------");
// Thread.dumpStack();
// this.vcMessagingServiceJms = vcMessagingServiceJms;
// this.session = session;
// this.bIndependent = false;
// }
public /*synchronized*/
Object sendRpcMessage(VCellQueue queue, VCRpcRequest vcRpcRequest, boolean returnRequired, long timeoutMS, String[] specialProperties, Object[] specialValues, UserLoginInfo userLoginInfo) throws VCMessagingException, VCMessagingInvocationTargetException {
MessageProducer messageProducer = null;
MessageProducerSessionJms tempMessageProducerSessionJms = null;
try {
if (!bIndependent) {
throw new VCMessagingException("cannot invoke RpcMessage from within another transaction, create an independent message producer");
}
Destination destination = session.createQueue(queue.getName());
messageProducer = session.createProducer(destination);
//
// use MessageProducerSessionJms to create the rpcRequest message (allows "Blob" messages to be formed as needed).
//
tempMessageProducerSessionJms = new MessageProducerSessionJms(vcMessagingServiceJms);
// tempMessageProducerSessionJms = new MessageProducerSessionJms(session,vcMessagingServiceJms);
VCMessageJms vcRpcRequestMessage = (VCMessageJms) tempMessageProducerSessionJms.createObjectMessage(vcRpcRequest);
Message rpcMessage = vcRpcRequestMessage.getJmsMessage();
rpcMessage.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, VCMessagingConstants.MESSAGE_TYPE_RPC_SERVICE_VALUE);
rpcMessage.setStringProperty(VCMessagingConstants.SERVICE_TYPE_PROPERTY, vcRpcRequest.getRequestedServiceType().getName());
// rpcMessage.setJMSExpiration(5000);
if (specialValues != null) {
for (int i = 0; i < specialValues.length; i++) {
rpcMessage.setObjectProperty(specialProperties[i], specialValues[i]);
}
}
if (returnRequired) {
rpcMessage.setJMSReplyTo(commonTemporaryQueue);
messageProducer.setTimeToLive(timeoutMS);
messageProducer.send(rpcMessage);
session.commit();
vcMessagingServiceJms.getDelegate().onRpcRequestSent(vcRpcRequest, userLoginInfo, vcRpcRequestMessage);
System.out.println("MessageProducerSessionJms.sendRpcMessage(): looking for reply message with correlationID = " + rpcMessage.getJMSMessageID());
String filter = VCMessagingConstants.JMSCORRELATIONID_PROPERTY + "='" + rpcMessage.getJMSMessageID() + "'";
MessageConsumer replyConsumer = null;
Message replyMessage = null;
try {
replyConsumer = session.createConsumer(commonTemporaryQueue, filter);
replyMessage = replyConsumer.receive(timeoutMS);
} finally {
replyConsumer.close();
}
if (replyMessage == null) {
System.out.println("Request timed out");
}
if (replyMessage == null || !(replyMessage instanceof ObjectMessage)) {
throw new JMSException("Server is temporarily not responding, please try again. If problem persists, contact VCell_Support@uchc.edu." + " (server " + vcRpcRequest.getRequestedServiceType().getName() + ", method " + vcRpcRequest.getMethodName() + ")");
} else {
VCMessageJms vcReplyMessage = new VCMessageJms(replyMessage, vcMessagingServiceJms.getDelegate());
vcReplyMessage.loadBlobFile();
Object returnValue = vcReplyMessage.getObjectContent();
vcReplyMessage.removeBlobFile();
if (returnValue instanceof Exception) {
throw new VCMessagingInvocationTargetException((Exception) returnValue);
} else {
return returnValue;
}
}
} else {
rpcMessage.setJMSReplyTo(commonTemporaryQueue);
messageProducer.setTimeToLive(timeoutMS);
messageProducer.send(rpcMessage);
commit();
vcMessagingServiceJms.getDelegate().onRpcRequestSent(vcRpcRequest, userLoginInfo, vcRpcRequestMessage);
return null;
}
} catch (JMSException e) {
onException(e);
throw new VCMessagingException(e.getMessage(), e);
} finally {
try {
if (tempMessageProducerSessionJms != null) {
tempMessageProducerSessionJms.commit();
tempMessageProducerSessionJms.close();
}
if (messageProducer != null) {
messageProducer.close();
}
// try{Thread.sleep(10000);}catch(Exception e){e.printStackTrace();}
} catch (JMSException e) {
onException(e);
}
}
}
use of cbit.vcell.message.VCMessagingException 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);
}
}
use of cbit.vcell.message.VCMessagingException in project vcell by virtualcell.
the class JavaSimulationExecutable method main.
/**
* Starts the application.
* @param args an array of command-line arguments
*/
public static void main(String[] args) {
VCMessagingService vcMessagingService = null;
JavaSimulationExecutable worker = null;
try {
PropertyLoader.loadProperties();
VCMongoMessage.enabled = false;
vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
vcMessagingService.setDelegate(new ServerMessagingDelegate());
worker = new JavaSimulationExecutable(vcMessagingService, args);
worker.init();
worker.start();
} catch (Throwable ex) {
ex.printStackTrace();
if (worker != null && worker.workerEventSession != null) {
try {
WorkerEventMessage.sendFailed(worker.workerEventSession, worker, worker.simulationTask, ManageUtils.getHostName(), SimulationMessage.jobFailed(ex.getMessage()));
} catch (VCMessagingException e) {
e.printStackTrace();
}
}
} finally {
try {
if (vcMessagingService != null) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
vcMessagingService.close();
}
} catch (VCMessagingException ex) {
ex.printStackTrace(System.out);
}
System.exit(0);
}
}
use of cbit.vcell.message.VCMessagingException in project vcell by virtualcell.
the class SolverPreprocessor method sendFailureAndExit.
/**
* Starts the application.
* @param args an array of command-line arguments
* @throws VCMessagingException
*/
public static void sendFailureAndExit(HTCSolver htcSolver, SimulationTask simTask, String hostName, SimulationMessage simMessage) throws VCMessagingException {
VCMessagingService service = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
service.setDelegate(new ServerMessagingDelegate());
VCMessageSession session = service.createProducerSession();
try {
WorkerEventMessage.sendFailed(session, htcSolver, simTask, hostName, simMessage);
sleep(500);
service.close();
sleep(500);
} catch (VCMessagingException e1) {
e1.printStackTrace();
} finally {
System.exit(-1);
}
}
Aggregations