Search in sources :

Example 11 with VCMessageSession

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();
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) RpcSimServerProxy(org.vcell.rest.rpc.RpcSimServerProxy) VCMessageSession(cbit.vcell.message.VCMessageSession) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) BigString(org.vcell.util.BigString) UserLoginInfo(org.vcell.util.document.UserLoginInfo) SimulationRep(cbit.vcell.modeldb.SimulationRep) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) UseridIDExistsException(org.vcell.util.UseridIDExistsException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException)

Example 12 with VCMessageSession

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);
}
Also used : TopicListener(cbit.vcell.message.VCTopicConsumer.TopicListener) VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCMessage(cbit.vcell.message.VCMessage) VCTopicConsumer(cbit.vcell.message.VCTopicConsumer) VCMessageSession(cbit.vcell.message.VCMessageSession) FileNotFoundException(java.io.FileNotFoundException) VCMessagingException(cbit.vcell.message.VCMessagingException)

Example 13 with VCMessageSession

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);
    }
}
Also used : VCMessage(cbit.vcell.message.VCMessage) VCMessageSession(cbit.vcell.message.VCMessageSession) VCMessagingException(cbit.vcell.message.VCMessagingException)

Example 14 with VCMessageSession

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);
    }
}
Also used : VCMessage(cbit.vcell.message.VCMessage) VCMessageSession(cbit.vcell.message.VCMessageSession) VCMessagingException(cbit.vcell.message.VCMessagingException)

Example 15 with VCMessageSession

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);
    }
}
Also used : SimpleMessagingDelegate(cbit.vcell.message.SimpleMessagingDelegate) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCMessageSession(cbit.vcell.message.VCMessageSession) VCPooledQueueConsumer(cbit.vcell.message.VCPooledQueueConsumer) VCMessagingService(cbit.vcell.message.VCMessagingService) VCRpcRequest(cbit.vcell.message.VCRpcRequest) VCMessagingException(cbit.vcell.message.VCMessagingException) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessagingException(cbit.vcell.message.VCMessagingException) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler)

Aggregations

VCMessageSession (cbit.vcell.message.VCMessageSession)18 KeyValue (org.vcell.util.document.KeyValue)9 VCMessage (cbit.vcell.message.VCMessage)8 VCMessagingException (cbit.vcell.message.VCMessagingException)7 User (org.vcell.util.document.User)7 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)6 BigString (org.vcell.util.BigString)6 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)6 UserLoginInfo (org.vcell.util.document.UserLoginInfo)6 VCMessagingService (cbit.vcell.message.VCMessagingService)5 SimulationRep (cbit.vcell.modeldb.SimulationRep)5 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)5 XmlParseException (cbit.vcell.xml.XmlParseException)5 DataAccessException (org.vcell.util.DataAccessException)5 MappingException (cbit.vcell.mapping.MappingException)4 MathException (cbit.vcell.math.MathException)4 MatrixException (cbit.vcell.matrix.MatrixException)4 VCMessageSelector (cbit.vcell.message.VCMessageSelector)4 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)4 ModelException (cbit.vcell.model.ModelException)4