use of cbit.vcell.message.VCMessageSession in project vcell by virtualcell.
the class RestDatabaseService method stopSimulation.
public SimulationRep stopSimulation(BiomodelSimulationStopServerResource resource, User vcellUser) throws PermissionException, ObjectNotFoundException, DataAccessException, SQLException {
// resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
String simId = resource.getAttribute(VCellApiApplication.SIMULATIONID);
KeyValue simKey = new KeyValue(simId);
SimulationRep simRep = getSimulationRep(simKey);
if (simRep == null) {
throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
}
User owner = simRep.getOwner();
if (!owner.compareEqual(vcellUser)) {
throw new PermissionException("not authorized to stop simulation");
}
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
try {
userLoginInfo.setUser(vcellUser);
} catch (Exception e) {
e.printStackTrace();
throw new DataAccessException(e.getMessage());
}
RpcSimServerProxy rpcSimServerProxy = new RpcSimServerProxy(userLoginInfo, rpcSession);
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
rpcSimServerProxy.stopSimulation(vcellUser, vcSimID);
return simRep;
} finally {
rpcSession.close();
}
}
use of cbit.vcell.message.VCMessageSession in project vcell by virtualcell.
the class ServiceProvider method initControlTopicListener.
/**
* Insert the method's description here.
* Creation date: (11/19/2001 5:29:47 PM)
*/
public void initControlTopicListener() {
if (bSlaveMode) {
return;
}
TopicListener listener = new TopicListener() {
public void onTopicMessage(VCMessage message, VCMessageSession session) {
try {
String msgType = message.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
String serviceID = null;
if (msgType == null) {
return;
}
if (msgType.equals(MessageConstants.MESSAGE_TYPE_ISSERVICEALIVE_VALUE)) {
VCMessage reply = session.createObjectMessage(ServiceProvider.this.serviceInstanceStatus);
reply.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_IAMALIVE_VALUE);
reply.setStringProperty(MessageConstants.SERVICE_ID_PROPERTY, serviceInstanceStatus.getID());
if (lg.isTraceEnabled())
lg.trace("sending reply [" + reply.toString() + "]");
if (message.getReplyTo() != null) {
reply.setCorrelationID(message.getMessageID());
session.sendTopicMessage((VCellTopic) message.getReplyTo(), reply);
} else {
session.sendTopicMessage(VCellTopic.DaemonControlTopic, reply);
}
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_ASKPERFORMANCESTATUS_VALUE)) {
VCMessage reply = session.createObjectMessage(serviceInstanceStatus);
reply.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_REPLYPERFORMANCESTATUS_VALUE);
reply.setStringProperty(MessageConstants.SERVICE_ID_PROPERTY, serviceInstanceStatus.getID());
session.sendTopicMessage(VCellTopic.DaemonControlTopic, reply);
if (lg.isTraceEnabled())
lg.trace("sending reply [" + reply.toString() + "]");
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_STOPSERVICE_VALUE)) {
serviceID = message.getStringProperty(MessageConstants.SERVICE_ID_PROPERTY);
if (serviceID != null && serviceID.equalsIgnoreCase(serviceInstanceStatus.getID())) {
stopService();
}
}
} catch (Exception ex) {
lg.error(ex.getMessage(), ex);
}
}
};
VCMessageSelector selector = vcMessagingService.createSelector(getDaemonControlFilter());
String threadName = "Daemon Control Topic Consumer";
vcTopicConsumer = new VCTopicConsumer(VCellTopic.DaemonControlTopic, listener, selector, threadName, MessageConstants.PREFETCH_LIMIT_DAEMON_CONTROL);
vcMessagingService.addMessageConsumer(vcTopicConsumer);
}
use of cbit.vcell.message.VCMessageSession in project vcell by virtualcell.
the class SimDataServer method exportMessage.
/**
* Insert the method's description here.
* Creation date: (7/29/2003 10:34:11 AM)
* @param event cbit.rmi.event.ExportEvent
*/
public void exportMessage(cbit.rmi.event.ExportEvent event) {
try {
VCMessageSession dataSession = vcMessagingService.createProducerSession();
VCMessage exportEventMessage = dataSession.createObjectMessage(event);
exportEventMessage.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_EXPORT_EVENT_VALUE);
exportEventMessage.setStringProperty(VCMessagingConstants.USERNAME_PROPERTY, event.getUser().getName());
dataSession.sendTopicMessage(VCellTopic.ClientStatusTopic, exportEventMessage);
dataSession.close();
} catch (VCMessagingException ex) {
lg.error(ex.getMessage(), ex);
}
}
use of cbit.vcell.message.VCMessageSession 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.VCMessageSession 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