Search in sources :

Example 6 with AutomaticWorkQueueImpl

use of org.apache.cxf.workqueue.AutomaticWorkQueueImpl in project cxf by apache.

the class AsyncHTTPConduitTest method testCallAsyncWithFullWorkQueue.

@Test
public void testCallAsyncWithFullWorkQueue() throws Exception {
    Bus bus = BusFactory.getThreadDefaultBus();
    WorkQueueManager workQueueManager = bus.getExtension(WorkQueueManager.class);
    AutomaticWorkQueueImpl automaticWorkQueue1 = (AutomaticWorkQueueImpl) workQueueManager.getAutomaticWorkQueue();
    updateAddressPort(g, PORT);
    Client client = ClientProxy.getClient(g);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    int asyncExecuteTimeout = 500;
    httpClientPolicy.setAsyncExecuteTimeout(asyncExecuteTimeout);
    http.setClient(httpClientPolicy);
    long repeat = automaticWorkQueue1.getHighWaterMark() + automaticWorkQueue1.getMaxSize() + 1;
    CountDownLatch initialThreadsLatch = new CountDownLatch(automaticWorkQueue1.getHighWaterMark());
    CountDownLatch doneLatch = new CountDownLatch((int) repeat);
    AtomicInteger threadCount = new AtomicInteger();
    for (long i = 0; i < repeat; i++) {
        g.greetMeLaterAsync(-50, res -> {
            try {
                int myCount = threadCount.getAndIncrement();
                if (myCount < automaticWorkQueue1.getHighWaterMark()) {
                    // Sleep long enough so that the workqueue will fill up and then
                    // handleResponseOnWorkqueue will fail for the calls from both
                    // responseReceived and consumeContent
                    Thread.sleep(3L * asyncExecuteTimeout);
                    initialThreadsLatch.countDown();
                } else {
                    Thread.sleep(50);
                }
                initialThreadsLatch.await();
                doneLatch.countDown();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }
    doneLatch.await(30, TimeUnit.SECONDS);
    assertEquals("All responses should be handled eventually", 0, doneLatch.getCount());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Bus(org.apache.cxf.Bus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) AutomaticWorkQueueImpl(org.apache.cxf.workqueue.AutomaticWorkQueueImpl) Client(org.apache.cxf.endpoint.Client) CountDownLatch(java.util.concurrent.CountDownLatch) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) Endpoint(javax.xml.ws.Endpoint) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 7 with AutomaticWorkQueueImpl

use of org.apache.cxf.workqueue.AutomaticWorkQueueImpl in project jbossws-cxf by jbossws.

the class BusHolder method createWorkQueue.

private static AutomaticWorkQueue createWorkQueue(String name, Map<String, String> props) {
    int mqs = parseInt(props.get(Constants.CXF_QUEUE_MAX_QUEUE_SIZE_PROP), 256);
    int initialThreads = parseInt(props.get(Constants.CXF_QUEUE_INITIAL_THREADS_PROP), 0);
    int highWaterMark = parseInt(props.get(Constants.CXF_QUEUE_HIGH_WATER_MARK_PROP), 25);
    int lowWaterMark = parseInt(props.get(Constants.CXF_QUEUE_LOW_WATER_MARK_PROP), 5);
    long dequeueTimeout = parseLong(props.get(Constants.CXF_QUEUE_DEQUEUE_TIMEOUT_PROP), 2 * 60 * 1000L);
    return new AutomaticWorkQueueImpl(mqs, initialThreads, highWaterMark, lowWaterMark, dequeueTimeout, name);
}
Also used : AutomaticWorkQueueImpl(org.apache.cxf.workqueue.AutomaticWorkQueueImpl) DDEndpoint(org.jboss.wsf.stack.cxf.metadata.services.DDEndpoint)

Aggregations

AutomaticWorkQueueImpl (org.apache.cxf.workqueue.AutomaticWorkQueueImpl)7 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Endpoint (javax.xml.ws.Endpoint)2 Bus (org.apache.cxf.Bus)2 Client (org.apache.cxf.endpoint.Client)2 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)2 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)2 WorkQueueManager (org.apache.cxf.workqueue.WorkQueueManager)2 Test (org.junit.Test)2 TimeoutException (java.util.concurrent.TimeoutException)1 AutomaticWorkQueue (org.apache.cxf.workqueue.AutomaticWorkQueue)1 DDEndpoint (org.jboss.wsf.stack.cxf.metadata.services.DDEndpoint)1 Configuration (org.osgi.service.cm.Configuration)1 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1