use of cbit.vcell.message.VCellQueue in project vcell by virtualcell.
the class VCMessagingServiceActiveMQ method createConsumer.
@Override
public MessageConsumer createConsumer(Session jmsSession, VCDestination vcDestination, VCMessageSelector vcSelector, int prefetchLimit) throws JMSException {
Destination jmsDestination;
MessageConsumer jmsMessageConsumer;
if (vcDestination instanceof VCellQueue) {
jmsDestination = jmsSession.createQueue(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
} else {
jmsDestination = jmsSession.createTopic(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
}
if (vcSelector == null) {
jmsMessageConsumer = jmsSession.createConsumer(jmsDestination);
} else {
jmsMessageConsumer = jmsSession.createConsumer(jmsDestination, vcSelector.getSelectionString());
}
return jmsMessageConsumer;
}
use of cbit.vcell.message.VCellQueue in project vcell by virtualcell.
the class VCMessagingServiceEmbedded method createConsumer.
@Override
public MessageConsumer createConsumer(Session jmsSession, VCDestination vcDestination, VCMessageSelector vcSelector, int prefetchLimit) throws JMSException, VCMessagingException {
if (!initialized) {
initialized = true;
init();
}
Destination jmsDestination;
MessageConsumer jmsMessageConsumer;
if (vcDestination instanceof VCellQueue) {
jmsDestination = jmsSession.createQueue(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
} else {
jmsDestination = jmsSession.createTopic(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
}
if (vcSelector == null) {
jmsMessageConsumer = jmsSession.createConsumer(jmsDestination);
} else {
jmsMessageConsumer = jmsSession.createConsumer(jmsDestination, vcSelector.getSelectionString());
}
return jmsMessageConsumer;
}
use of cbit.vcell.message.VCellQueue 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.VCellQueue in project vcell by virtualcell.
the class RpcRestlet method handle.
@Override
public void handle(Request req, Response response) {
if (req.getMethod().equals(Method.POST)) {
String destination = null;
String method = null;
try {
VCellApiApplication application = ((VCellApiApplication) getApplication());
User vcellUser = application.getVCellUser(req.getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
HttpRequest request = (HttpRequest) req;
String username = vcellUser.getName();
String userkey = vcellUser.getID().toString();
destination = request.getHeaders().getFirstValue("Destination");
method = request.getHeaders().getFirstValue("Method");
String returnRequired = request.getHeaders().getFirstValue("ReturnRequired");
String timeoutMS = request.getHeaders().getFirstValue("TimeoutMS");
String compressed = request.getHeaders().getFirstValue("Compressed");
String klass = request.getHeaders().getFirstValue("Class");
StringBuffer buffer = new StringBuffer();
buffer.append("username=" + username + ", userkey=" + userkey + ", destination=" + destination + ", method=" + method + "\n");
buffer.append("returnRequired=" + returnRequired + ", timeoutMS=" + timeoutMS + ", compressed=" + compressed + "\n");
buffer.append("class=" + klass);
System.out.println(buffer.toString());
req.bufferEntity();
Serializable rpcRequestBodyObject = VCellApiClient.fromCompressedSerialized(req.getEntity().getStream());
if (!(rpcRequestBodyObject instanceof VCellApiRpcBody)) {
throw new RuntimeException("expecting post content of type VCellApiRpcBody");
}
VCellApiRpcBody rpcBody = (VCellApiRpcBody) rpcRequestBodyObject;
RpcServiceType st = null;
VCellQueue queue = null;
switch(rpcBody.rpcRequest.rpcDestination) {
case DataRequestQueue:
{
st = RpcServiceType.DATA;
queue = VCellQueue.DataRequestQueue;
break;
}
case DbRequestQueue:
{
st = RpcServiceType.DB;
queue = VCellQueue.DbRequestQueue;
break;
}
case SimReqQueue:
{
st = RpcServiceType.DISPATCH;
queue = VCellQueue.SimReqQueue;
break;
}
default:
{
throw new RuntimeException("unsupported RPC Destination: " + rpcBody.rpcDestination);
}
}
VCellApiRpcRequest vcellapiRpcRequest = rpcBody.rpcRequest;
Object[] arglist = vcellapiRpcRequest.args;
String[] specialProperties = rpcBody.specialProperties;
Object[] specialValues = rpcBody.specialValues;
VCRpcRequest vcRpcRequest = new VCRpcRequest(vcellUser, st, method, arglist);
VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
RpcService rpcService = vcellApiApplication.getRpcService();
Serializable result = rpcService.sendRpcMessage(queue, vcRpcRequest, new Boolean(rpcBody.returnedRequired), specialProperties, specialValues, new UserLoginInfo(username, null));
byte[] serializedResultObject = VCellApiClient.toCompressedSerialized(result);
response.setStatus(Status.SUCCESS_OK, "rpc method=" + method + " succeeded");
response.setEntity(new ByteArrayRepresentation(serializedResultObject));
} catch (Exception e) {
getLogger().severe("internal error invoking " + destination + ":" + method + "(): " + e.getMessage());
e.printStackTrace();
response.setStatus(Status.SERVER_ERROR_INTERNAL);
response.setEntity("internal error invoking " + destination + ":" + method + "(): " + e.getMessage(), MediaType.TEXT_PLAIN);
}
}
}
Aggregations