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
}
}
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations