Package org.apache.cxf.continuations

Examples of org.apache.cxf.continuations.Continuation


        if (provider == null) {
            throw new WebApplicationException(500);
        }
       
        synchronized (suspended) {
            Continuation suspendedCont = suspended.remove(name);
            if (suspendedCont != null) {
                return suspendedCont;
            }
        }
       
View Full Code Here


                    JaxwsServerHandler handler = new JaxwsServerHandler(null);
                    ex.put(JaxwsServerHandler.class, handler);
                    params.add(handler);
                    return ret;
                } else if (cp != null && cp.getContinuation() != null) {
                    final Continuation c = cp.getContinuation();
                    c.suspend(0);
                    JaxwsServerHandler handler = new JaxwsServerHandler(c);
                    ex.put(JaxwsServerHandler.class, handler);
                    params.add(handler);
                    return ret;
                }
View Full Code Here

                    //1 and 2 seconds, with a preference of delaying the earlier
                    //requests longer to create a sort of backlog/contention
                    //with the later requests
                    ContinuationProvider p = (ContinuationProvider)
                        getContext().getMessageContext().get(ContinuationProvider.class.getName());
                    Continuation c = p.getContinuation();
                    if (c.isNew()) {
                        if (cnt < 0) {
                            c.suspend(-cnt);
                        } else {
                            c.suspend(2000 - (cnt % 1000));
                        }
                        return null;
                    }
                    return "Hello, finally! " + cnt;
                }
View Full Code Here

     * @param mn message number
     * @return <code>true</code> if message processing to continue, <code>false</code> if to be dropped
     * @throws RMException if message had already been acknowledged
     */
    boolean applyDeliveryAssurance(long mn, Message message) throws RMException {
        Continuation cont = getContinuation(message);
        RMConfiguration config = destination.getReliableEndpoint().getConfiguration();
        DeliveryAssurance da = config.getDeliveryAssurance();
        boolean canSkip = da != DeliveryAssurance.AT_LEAST_ONCE && da != DeliveryAssurance.EXACTLY_ONCE;
        boolean robust = false;
        boolean robustDelivering = false;
        if (message != null) {
            robust = MessageUtils.isTrue(message.getContextualProperty(Message.ROBUST_ONEWAY));
            if (robust) {
                robustDelivering =
                    MessageUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY));
            }
        }
        if (robust && !robustDelivering) {
            // no check performed if in robust and not in delivering
            removeDeliveringMessageNumber(mn);
            return true;
        }
        if (cont != null && config.isInOrder() && !cont.isNew()) {
            return waitInQueue(mn, canSkip, message, cont);
        }
        if ((da == DeliveryAssurance.EXACTLY_ONCE || da == DeliveryAssurance.AT_MOST_ONCE)
            && (isAcknowledged(mn)
                || (robustDelivering && deliveringMessageNumbers.contains(mn)))) {           
View Full Code Here

            }
        }
    }
    synchronized void wakeupAll() {
        while (!continuations.isEmpty()) {
            Continuation c = continuations.remove(0);
            c.resume();
        }
        notifyAll();
    }
View Full Code Here

        OperationResourceInfo ori = cxfExchange.get(OperationResourceInfo.class);       
        if (ori.isSubResourceLocator()) {
            // don't delegate the sub resource locator call to camel processor
            return method.invoke(serviceObject, paramArray);
        }
        Continuation continuation;
        if (!endpoint.isSynchronous() && (continuation = getContinuation(cxfExchange)) != null) {
            LOG.trace("Calling the Camel async processors.");
            return asyncInvoke(cxfExchange, serviceObject, method, paramArray, continuation);
        } else {
            LOG.trace("Calling the Camel sync processors.");
View Full Code Here

        ServerFactoryBean svrBean = endpoint.createServerFactoryBean();
        svrBean.setInvoker(new Invoker() {
            // we receive a CXF request when this method is called
            public Object invoke(Exchange cxfExchange, Object o) {
                LOG.trace("Received CXF Request: {}", cxfExchange);               
                Continuation continuation;
                if (!endpoint.isSynchronous() && isAsyncInvocationSupported(cxfExchange)
                    && (continuation = getContinuation(cxfExchange)) != null) {
                    LOG.trace("Calling the Camel async processors.");
                    return asyncInvoke(cxfExchange, continuation);
                } else {
                    LOG.trace("Calling the Camel sync processors.");
                    return syncInvoke(cxfExchange);
                }
            }
            // NOTE this code cannot work with CXF 2.2.x and JMSContinuation
            // as it doesn't break out the interceptor chain when we call it
            private Object asyncInvoke(Exchange cxfExchange, final Continuation continuation) {
                synchronized (continuation) {
                    if (continuation.isNew()) {
                        final org.apache.camel.Exchange camelExchange = prepareCamelExchange(cxfExchange);
                       
                        // Now we don't set up the timeout value
                        LOG.trace("Suspending continuation of exchangeId: {}", camelExchange.getExchangeId());
                       
                        // The continuation could be called before the suspend is called
                        continuation.suspend(cxfEndpoint.getContinuationTimeout());

                        // use the asynchronous API to process the exchange
                        getAsyncProcessor().process(camelExchange, new AsyncCallback() {
                            public void done(boolean doneSync) {
                                // make sure the continuation resume will not be called before the suspend method in other thread
                                synchronized (continuation) {
                                    LOG.trace("Resuming continuation of exchangeId: {}", camelExchange.getExchangeId());
                                    // resume processing after both, sync and async callbacks
                                    continuation.setObject(camelExchange);
                                    continuation.resume();
                                }
                            }
                        });
                       
                    } else if (continuation.isResumed()) {
                        org.apache.camel.Exchange camelExchange = (org.apache.camel.Exchange)continuation.getObject();
                        try {
                            setResponseBack(cxfExchange, camelExchange);
                        } finally {
                            CxfConsumer.this.doneUoW(camelExchange);
                        }

                    }
                }
                return null;
            }
            private Continuation getContinuation(Exchange cxfExchange) {
                ContinuationProvider provider =
                    (ContinuationProvider)cxfExchange.getInMessage().get(ContinuationProvider.class.getName());
                Continuation continuation = provider == null ? null : provider.getContinuation();
                // Make sure we don't return the JMSContinuation, as it doesn't support the Continuation we wants
                // Don't want to introduce the dependency of cxf-rt-transprot-jms here
                if (continuation != null && continuation.getClass().getName().equals("org.apache.cxf.transport.jms.continuations.JMSContinuation")) {
                    return null;
                } else {
                    return continuation;
                }
            }
View Full Code Here

        OperationResourceInfo ori = cxfExchange.get(OperationResourceInfo.class);       
        if (ori.isSubResourceLocator()) {
            // don't delegate the sub resource locator call to camel processor
            return method.invoke(serviceObject, paramArray);
        }
        Continuation continuation = getContinuation(cxfExchange);
        // Only calling the continuation API for CXF 2.3.x
        if (continuation != null && !endpoint.isSynchronous() && Version.getCurrentVersion().startsWith("2.3")) {
            return asyncInvoke(cxfExchange, serviceObject, method, paramArray, continuation);
        } else {
            return syncInvoke(cxfExchange, serviceObject, method, paramArray);
View Full Code Here

    public void testGetNewContinuation() {
        Message m = new MessageImpl();
        m.setExchange(new ExchangeImpl());
        JMSContinuationProvider provider =
            new JMSContinuationProvider(null, m, null, null, null, null);
        Continuation cw = provider.getContinuation();
        assertTrue(cw.isNew());
        assertSame(cw, m.get(JMSContinuation.class));
    }
View Full Code Here

    @Resource
    private WebServiceContext context;
   
    public String sayHi(String firstName, String secondName) {
       
        Continuation continuation = getContinuation(firstName);
        if (continuation == null) {
            throw new RuntimeException("Failed to get continuation");
        }
        synchronized (continuation) {
            if (continuation.isNew()) {
                Object userObject = secondName != null && secondName.length() > 0
                                    ? secondName : null;
                continuation.setObject(userObject);
                suspendInvocation(firstName, continuation);
            } else {
                if (!continuation.isResumed()) {
                    throw new RuntimeException("No timeout expected");
                }
                StringBuilder sb = new StringBuilder();
                sb.append(firstName);
               
                // if the actual parameter is not null
                if (secondName != null && secondName.length() > 0) {
                    String surname = continuation.getObject().toString();
                    sb.append(' ').append(surname);
                }
                System.out.println("Saying hi to " + sb.toString());
                return "Hi " + sb.toString();
            }
View Full Code Here

TOP

Related Classes of org.apache.cxf.continuations.Continuation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.