Search in sources :

Example 1 with QueueTransanctionResource

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) {
        }
    }
}
Also used : NamingException(javax.naming.NamingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) QueueTransanctionResource(jp.ossc.nimbus.service.resource.jmsqueue.QueueTransanctionResource) NamingException(javax.naming.NamingException) Queue(javax.jms.Queue)

Example 2 with QueueTransanctionResource

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;
}
Also used : MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) InterceptorException(jp.ossc.nimbus.service.aspect.interfaces.InterceptorException) TargetUncheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetUncheckedException) TargetCheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException) InterceptorException(jp.ossc.nimbus.service.aspect.interfaces.InterceptorException) TargetUncheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetUncheckedException) QueueTransanctionResource(jp.ossc.nimbus.service.resource.jmsqueue.QueueTransanctionResource) MethodInvocationContext(jp.ossc.nimbus.service.aop.MethodInvocationContext) InvocationContext(jp.ossc.nimbus.service.aop.InvocationContext) TargetCheckedException(jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException)

Aggregations

QueueTransanctionResource (jp.ossc.nimbus.service.resource.jmsqueue.QueueTransanctionResource)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RemoteException (java.rmi.RemoteException)1 Queue (javax.jms.Queue)1 NamingException (javax.naming.NamingException)1 InvocationContext (jp.ossc.nimbus.service.aop.InvocationContext)1 MethodInvocationContext (jp.ossc.nimbus.service.aop.MethodInvocationContext)1 InterceptorException (jp.ossc.nimbus.service.aspect.interfaces.InterceptorException)1 TargetCheckedException (jp.ossc.nimbus.service.aspect.interfaces.TargetCheckedException)1 TargetUncheckedException (jp.ossc.nimbus.service.aspect.interfaces.TargetUncheckedException)1