use of jp.ossc.nimbus.service.resource.jmsqueue.QueueTransanctionResource in project nimbus by nimbus-org.
the class DefaultFacadeCallService method syncParallelFacadeCallByJMS.
protected FacadeValue[] syncParallelFacadeCallByJMS(FacadeValue[] values, long timeout) {
if (mResourceFactory == null || mJndiFinder == null) {
throw new UnsupportedOperationException();
}
QueueTransanctionResource res = null;
try {
res = (QueueTransanctionResource) mResourceFactory.makeResource(null);
QueueConnection connection = res.getConnectionObject();
connection.start();
} catch (Exception e) {
throw new ServiceException("DefaultFacadeCallService021", "Exception", e);
}
QueueSession qs = (QueueSession) res.getObject();
ObjectMessage msg = null;
QueueSender qsender = null;
try {
Queue q = null;
if (this.mQueueName == null) {
q = (Queue) this.mJndiFinder.lookup();
} else {
q = (Queue) this.mJndiFinder.lookup(mQueueName);
}
qsender = qs.createSender(q);
TemporaryQueue[] replyQueues = new TemporaryQueue[values.length];
for (int i = 0; i < values.length; i++) {
setHeaderFromThreadContext(values[i]);
replyQueues[i] = qs.createTemporaryQueue();
msg = createJMSMessage(qs, values[i], replyQueues[i]);
qsender.send(msg, deliveryMode, priority, timeToLive);
}
try {
qsender.close();
qsender = null;
} catch (JMSException e) {
}
long procTime = 0;
FacadeValue[] result = new FacadeValue[values.length];
for (int i = 0; i < values.length; i++) {
QueueReceiver receiver = null;
try {
receiver = qs.createReceiver(replyQueues[i]);
long start = System.currentTimeMillis();
long curTimeout = timeout - procTime;
if (curTimeout < 0) {
curTimeout = 1;
}
ObjectMessage replyMessage = (ObjectMessage) receiver.receive(curTimeout);
procTime += System.currentTimeMillis() - start;
if (replyMessage != null) {
Object ret = replyMessage.getObject();
if (ret instanceof RuntimeException) {
throw (RuntimeException) ret;
} else {
result[i] = (FacadeValue) ret;
}
}
} finally {
if (receiver != null) {
try {
receiver.close();
} catch (JMSException e) {
}
}
try {
replyQueues[i].delete();
} catch (JMSException e) {
}
replyQueues[i] = null;
}
}
return result;
} catch (JMSException e4) {
throw new ServiceException("DefaultFacadeCallService022", "JMSException", e4);
} catch (NamingException e) {
throw new ServiceException("DefaultFacadeCallService023", "NamingException", e);
} finally {
if (qsender != null) {
try {
qsender.close();
qsender = null;
} catch (JMSException e) {
}
}
try {
res.close();
} catch (Exception e1) {
}
}
}
use of jp.ossc.nimbus.service.resource.jmsqueue.QueueTransanctionResource in project nimbus by nimbus-org.
the class DefaultAsynchCallInterceptorService method invokeInternal.
protected Object invokeInternal(Object inputObj, jp.ossc.nimbus.service.aspect.interfaces.InterceptorChain interceptChain, jp.ossc.nimbus.service.aop.InterceptorChain chain) throws Throwable {
Object ret = null;
Object input = inputObj;
if (chain != null) {
input = ((MethodInvocationContext) input).getParameters()[0];
}
if (input instanceof ObjectMessage) {
ObjectMessage msg = (ObjectMessage) input;
FacadeValue in = null;
if (isIgnoreRedelivery) {
try {
if (msg.getJMSRedelivered()) {
return ret;
}
} catch (JMSException e) {
throw new InterceptorException("getJMSRedelivered JMSException", e);
}
}
if (redeliveryInterval > 0) {
try {
if (msg.getJMSRedelivered()) {
Thread.sleep(redeliveryInterval);
}
} catch (InterruptedException e) {
} catch (JMSException e) {
throw new InterceptorException("getJMSRedelivered JMSException", e);
}
}
try {
in = (FacadeValue) msg.getObject();
} catch (JMSException e) {
throw new InterceptorException("getObject JMSException", e);
}
try {
if (interceptChain != null) {
ret = interceptChain.invokeChain(in);
} else {
final MethodInvocationContext context = (MethodInvocationContext) inputObj;
context.setParameters(new Object[] { in });
ret = chain.invokeNext(context);
}
} catch (TargetUncheckedException e) {
Throwable th = e.getCause();
if (th instanceof RuntimeException) {
if (queueSessionFactory != null) {
try {
Queue replyQueue = (Queue) msg.getJMSReplyTo();
if (replyQueue == null) {
throw e;
}
} catch (JMSException e2) {
throw new InterceptorException("Unexpected Exception", e2);
}
}
ret = th;
} else {
throw new InterceptorException("Unexpected Exception", th);
}
} catch (TargetCheckedException e) {
// ここに飛んでくることはない。
// コマンド層でキャッチされ処理済みのはず。
e.printStackTrace();
}
if (queueSessionFactory != null) {
try {
Queue replyQueue = (Queue) msg.getJMSReplyTo();
if (replyQueue != null) {
QueueTransanctionResource resource = null;
try {
resource = (QueueTransanctionResource) queueSessionFactory.makeResource(null);
QueueSession session = (QueueSession) resource.getObject();
QueueSender sender = session.createSender(replyQueue);
sender.send(session.createObjectMessage((Serializable) ret), deliveryMode, priority, timeToLive);
} finally {
if (resource != null) {
resource.close();
}
}
}
} catch (Exception e) {
throw new InterceptorException("Unexpected Exception", e);
}
}
} else {
if (interceptChain != null) {
ret = interceptChain.invokeChain(input);
} else {
ret = chain.invokeNext((InvocationContext) inputObj);
}
}
return ret;
}
Aggregations