Search in sources :

Example 6 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class DestinationSequence method waitInQueue.

synchronized boolean waitInQueue(long mn, boolean canSkip, Message message, Continuation continuation) {
    while (true) {
        // can process now if no other in process and this one is next
        if (inProcessNumber == 0) {
            long diff = mn - highNumberCompleted;
            if (diff == 1 || (canSkip && diff > 0)) {
                inProcessNumber = mn;
                return true;
            }
        }
        // can abort now if same message in process or already processed
        if (mn == inProcessNumber || isAcknowledged(mn)) {
            return false;
        }
        if (continuation == null) {
            ContinuationProvider p = message.get(ContinuationProvider.class);
            if (p != null) {
                boolean isOneWay = message.getExchange().isOneWay();
                message.getExchange().setOneWay(false);
                continuation = p.getContinuation();
                message.getExchange().setOneWay(isOneWay);
                message.put(Continuation.class, continuation);
            }
        }
        if (continuation != null) {
            continuation.setObject(message);
            if (continuation.suspend(-1)) {
                continuations.put(mn, continuation);
                throw new SuspendedInvocationException();
            }
        }
        try {
            // if we get here, there isn't a continuation available
            // so we need to block/wait
            wait();
        } catch (InterruptedException ie) {
        // ignore
        }
    }
}
Also used : ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException)

Example 7 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class SseEventSinkContextProviderTest method setUp.

@Before
public void setUp() {
    provider = new SseEventSinkContextProvider();
    final Exchange exchange = mock(Exchange.class);
    final Endpoint endpoint = mock(Endpoint.class);
    final ContinuationProvider continuationProvider = mock(ContinuationProvider.class);
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockAsyncContext ctx = new MockAsyncContext(request, response) {

        @Override
        public void start(Runnable runnable) {
        /* do nothing */
        }
    };
    request.setAsyncContext(ctx);
    message = new MessageImpl();
    message.setExchange(exchange);
    message.put(ContinuationProvider.class.getName(), continuationProvider);
    message.put(AbstractHTTPDestination.HTTP_REQUEST, request);
    when(exchange.getEndpoint()).thenReturn(endpoint);
}
Also used : Exchange(org.apache.cxf.message.Exchange) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Endpoint(org.apache.cxf.endpoint.Endpoint) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockAsyncContext(org.springframework.mock.web.MockAsyncContext) MessageImpl(org.apache.cxf.message.MessageImpl) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Before(org.junit.Before)

Example 8 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class AsyncHTTPConduitTest method start.

@BeforeClass
public static void start() throws Exception {
    Bus b = createStaticBus();
    b.setProperty(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
    b.setProperty("org.apache.cxf.transport.http.async.MAX_CONNECTIONS", 501);
    BusFactory.setThreadDefaultBus(b);
    AsyncHTTPConduitFactory hcf = (AsyncHTTPConduitFactory) b.getExtension(HTTPConduitFactory.class);
    assertEquals(501, hcf.getMaxConnections());
    ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort", new org.apache.hello_world_soap_http.GreeterImpl() {

        public String greetMeLater(long cnt) {
            // use the continuations so the async client can
            // have a ton of connections, use less threads
            // 
            // mimic a slow server by delaying somewhere between
            // 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;
        }

        public String greetMe(String me) {
            if (me.equals(FILL_BUFFER)) {
                return String.join("", Collections.nCopies(16093, " "));
            } else {
                return "Hello " + me;
            }
        }
    });
    StringBuilder builder = new StringBuilder("NaNaNa");
    for (int x = 0; x < 50; x++) {
        builder.append(" NaNaNa ");
    }
    request = builder.toString();
    URL wsdl = AsyncHTTPConduitTest.class.getResource("/wsdl/hello_world_services.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService();
    assertNotNull("Service is null", service);
    g = service.getSoapPort();
    assertNotNull("Port is null", g);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Bus(org.apache.cxf.Bus) Continuation(org.apache.cxf.continuations.Continuation) HTTPConduitFactory(org.apache.cxf.transport.http.HTTPConduitFactory) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Endpoint(javax.xml.ws.Endpoint) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 9 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class NettyHttpConduitTest method start.

@Before
public void start() throws Exception {
    Bus b = createStaticBus();
    b.setProperty(NettyHttpConduit.USE_ASYNC, NettyHttpConduitFactory.UseAsyncPolicy.ALWAYS);
    BusFactory.setThreadDefaultBus(b);
    ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort", new org.apache.hello_world_soap_http.GreeterImpl() {

        public String greetMeLater(long cnt) {
            // use the continuations so the async client can
            // have a ton of connections, use less threads
            // 
            // mimic a slow server by delaying somewhere between
            // 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;
        }

        public String greetMe(String me) {
            if (me.equals(FILL_BUFFER)) {
                return String.join("", Collections.nCopies(16093, " "));
            } else {
                return "Hello " + me;
            }
        }
    });
    StringBuilder builder = new StringBuilder("NaNaNa");
    for (int x = 0; x < 50; x++) {
        builder.append(" NaNaNa ");
    }
    request = builder.toString();
    URL wsdl = NettyHttpConduitTest.class.getResource("/wsdl/hello_world_services.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService();
    assertNotNull("Service is null", service);
    g = service.getSoapPort();
    assertNotNull("Port is null", g);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Bus(org.apache.cxf.Bus) Continuation(org.apache.cxf.continuations.Continuation) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Endpoint(javax.xml.ws.Endpoint) URL(java.net.URL) Before(org.junit.Before)

Example 10 with ContinuationProvider

use of org.apache.cxf.continuations.ContinuationProvider in project cxf by apache.

the class ThrottlingInterceptor method handleMessage.

@Override
public void handleMessage(Message message) throws Fault {
    ThrottleResponse rsp = manager.getThrottleResponse(getPhase(), message);
    if (rsp == null) {
        return;
    }
    message.getExchange().put(ThrottleResponse.class, rsp);
    if (rsp.getResponseCode() >= 300) {
        createOutMessage(message);
        message.getInterceptorChain().doInterceptStartingAt(message, OutgoingChainInterceptor.class.getName());
        return;
    }
    long l = rsp.getDelay();
    if (l > 0) {
        ContinuationProvider cp = message.get(ContinuationProvider.class);
        if (cp == null) {
            LOG.warning("No ContinuationProvider available, sleeping on current thread");
            try {
                Thread.sleep(l);
            } catch (InterruptedException e) {
            // ignore
            }
            return;
        }
        Continuation c = cp.getContinuation();
        c.suspend(l);
    }
}
Also used : Continuation(org.apache.cxf.continuations.Continuation) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) OutgoingChainInterceptor(org.apache.cxf.interceptor.OutgoingChainInterceptor)

Aggregations

ContinuationProvider (org.apache.cxf.continuations.ContinuationProvider)13 Continuation (org.apache.cxf.continuations.Continuation)9 URL (java.net.URL)3 Endpoint (javax.xml.ws.Endpoint)3 Bus (org.apache.cxf.Bus)3 SOAPService (org.apache.hello_world_soap_http.SOAPService)3 Message (org.apache.cxf.message.Message)2 HTTPConduitFactory (org.apache.cxf.transport.http.HTTPConduitFactory)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 Method (java.lang.reflect.Method)1 FutureTask (java.util.concurrent.FutureTask)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 UriInfo (javax.ws.rs.core.UriInfo)1 MessageContext (javax.xml.ws.handler.MessageContext)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 UseAsyncMethod (org.apache.cxf.annotations.UseAsyncMethod)1 UseNio (org.apache.cxf.annotations.UseNio)1 SuspendedInvocationException (org.apache.cxf.continuations.SuspendedInvocationException)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1