Search in sources :

Example 1 with WorkQueueManager

use of org.apache.cxf.workqueue.WorkQueueManager in project camel by apache.

the class CamelOutputStream method asyncInvokeFromWorkQueue.

protected void asyncInvokeFromWorkQueue(final org.apache.camel.Exchange exchange) throws IOException {
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                syncInvoke(exchange);
            } catch (Throwable e) {
                ((PhaseInterceptorChain) outMessage.getInterceptorChain()).abort();
                outMessage.setContent(Exception.class, e);
                ((PhaseInterceptorChain) outMessage.getInterceptorChain()).unwind(outMessage);
                MessageObserver mo = outMessage.getInterceptorChain().getFaultObserver();
                if (mo == null) {
                    mo = outMessage.getExchange().get(MessageObserver.class);
                }
                mo.onMessage(outMessage);
            }
        }
    };
    try {
        Executor ex = outMessage.getExchange().get(Executor.class);
        if (ex != null) {
            outMessage.getExchange().put(Executor.class.getName() + ".USING_SPECIFIED", Boolean.TRUE);
            ex.execute(runnable);
        } else {
            WorkQueueManager mgr = outMessage.getExchange().get(Bus.class).getExtension(WorkQueueManager.class);
            AutomaticWorkQueue qu = mgr.getNamedWorkQueue("camel-cxf-conduit");
            if (qu == null) {
                qu = mgr.getAutomaticWorkQueue();
            }
            // need to set the time out somewhere
            qu.execute(runnable);
        }
    } catch (RejectedExecutionException rex) {
        if (!hasLoggedAsyncWarning) {
            LOG.warn("Executor rejected background task to retrieve the response.  Suggest increasing the workqueue settings.");
            hasLoggedAsyncWarning = true;
        }
        LOG.info("Executor rejected background task to retrieve the response, running on current thread.");
        syncInvoke(exchange);
    }
}
Also used : Bus(org.apache.cxf.Bus) MessageObserver(org.apache.cxf.transport.MessageObserver) Executor(java.util.concurrent.Executor) AutomaticWorkQueue(org.apache.cxf.workqueue.AutomaticWorkQueue) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with WorkQueueManager

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

the class OSGIBusListener method initComplete.

public void initComplete() {
    ManagedWorkQueueList wqList = bus.getExtension(ManagedWorkQueueList.class);
    if (wqList != null) {
        WorkQueueManager manager = bus.getExtension(WorkQueueManager.class);
        wqList.addAllToWorkQueueManager(manager);
    }
    registerBusAsService();
}
Also used : WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager)

Example 3 with WorkQueueManager

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

the class InternalContextUtils method getExecutor.

/**
 * Get the Executor for this invocation.
 * @param endpoint
 * @return
 */
private static Executor getExecutor(final Message message) {
    Endpoint endpoint = message.getExchange().getEndpoint();
    Executor executor = endpoint.getService().getExecutor();
    if (executor == null || SynchronousExecutor.isA(executor)) {
        // need true asynchrony
        Bus bus = message.getExchange().getBus();
        if (bus != null) {
            WorkQueueManager workQueueManager = bus.getExtension(WorkQueueManager.class);
            Executor autoWorkQueue = workQueueManager.getNamedWorkQueue("ws-addressing");
            executor = autoWorkQueue != null ? autoWorkQueue : workQueueManager.getAutomaticWorkQueue();
        } else {
            executor = OneShotAsyncExecutor.getInstance();
        }
    }
    message.getExchange().put(Executor.class, executor);
    return executor;
}
Also used : Bus(org.apache.cxf.Bus) OneShotAsyncExecutor(org.apache.cxf.workqueue.OneShotAsyncExecutor) Executor(java.util.concurrent.Executor) SynchronousExecutor(org.apache.cxf.workqueue.SynchronousExecutor) Endpoint(org.apache.cxf.endpoint.Endpoint) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager)

Example 4 with WorkQueueManager

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

the class InternalContextUtils method getExecutor.

/**
 * Get the Executor for this invocation.
 * @param endpoint
 * @return
 */
private static Executor getExecutor(final Message message) {
    Endpoint endpoint = message.getExchange().getEndpoint();
    Executor executor = endpoint.getService().getExecutor();
    if (executor == null || SynchronousExecutor.isA(executor)) {
        // need true asynchrony
        Bus bus = message.getExchange().getBus();
        if (bus != null) {
            WorkQueueManager workQueueManager = bus.getExtension(WorkQueueManager.class);
            Executor autoWorkQueue = workQueueManager.getNamedWorkQueue("ws-addressing");
            executor = autoWorkQueue != null ? autoWorkQueue : workQueueManager.getAutomaticWorkQueue();
        } else {
            executor = OneShotAsyncExecutor.getInstance();
        }
    }
    message.getExchange().put(Executor.class, executor);
    return executor;
}
Also used : Bus(org.apache.cxf.Bus) OneShotAsyncExecutor(org.apache.cxf.workqueue.OneShotAsyncExecutor) Executor(java.util.concurrent.Executor) SynchronousExecutor(org.apache.cxf.workqueue.SynchronousExecutor) Endpoint(org.apache.cxf.endpoint.Endpoint) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager)

Example 5 with WorkQueueManager

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

the class ManagedBusTest method doManagedBusTest.

private void doManagedBusTest(Bus bus, String expect, String reject, int port) throws Exception {
    InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
    assertNotNull(im);
    InstrumentationManagerImpl imi = (InstrumentationManagerImpl) im;
    assertEquals("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi", imi.getJMXServiceURL());
    assertTrue(imi.isEnabled());
    assertNotNull(imi.getMBeanServer());
    WorkQueueManager manager = bus.getExtension(WorkQueueManager.class);
    MBeanServer mbs = im.getMBeanServer();
    ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=WorkQueueManager,*");
    Set<?> s = mbs.queryNames(name, null);
    StringBuilder b = new StringBuilder();
    for (ObjectName o : CastUtils.cast(s, ObjectName.class)) {
        b.append(o.toString());
        assertTrue("expected " + expect + " in object name: " + o, o.toString().indexOf("bus.id=" + expect + ",") != -1);
        assertTrue("unexpected " + reject + " in object name: " + o, o.toString().indexOf("bus.id=" + reject + ",") == -1);
        b.append("\n");
    }
    assertEquals("Size is wrong: " + b.toString(), 1, s.size());
    assertNotNull(manager.getNamedWorkQueue("testQueue"));
    manager.getAutomaticWorkQueue();
    name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=WorkQueues,*");
    s = mbs.queryNames(name, null);
    b = new StringBuilder();
    for (ObjectName o : CastUtils.cast(s, ObjectName.class)) {
        b.append(o.toString());
        assertTrue("expected " + expect + " in object name: " + o, o.toString().indexOf("bus.id=" + expect + ",") != -1);
        assertTrue("unexpected " + reject + " in object name: " + o, o.toString().indexOf("bus.id=" + reject + ",") == -1);
        b.append("\n");
    }
    assertEquals("Size is wrong: " + b.toString(), 2, s.size());
    Iterator<?> it = s.iterator();
    while (it.hasNext()) {
        ObjectName n = (ObjectName) it.next();
        Long result = (Long) mbs.invoke(n, "getWorkQueueMaxSize", new Object[0], new String[0]);
        assertEquals(result, Long.valueOf(256));
        Integer hwm = (Integer) mbs.invoke(n, "getHighWaterMark", new Object[0], new String[0]);
        if (n.toString().contains("testQueue")) {
            assertEquals(hwm, Integer.valueOf(50));
        } else {
            assertEquals(hwm, Integer.valueOf(25));
        }
    }
    name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME + ":type=Bus,*");
    s = mbs.queryNames(name, null);
    assertTrue(s.size() == 1);
    it = s.iterator();
    while (it.hasNext()) {
        ObjectName n = (ObjectName) it.next();
        Object[] params = { Boolean.FALSE };
        String[] sig = { "boolean" };
        mbs.invoke(n, "shutdown", params, sig);
    }
    bus.shutdown(true);
}
Also used : InstrumentationManager(org.apache.cxf.management.InstrumentationManager) ObjectName(javax.management.ObjectName) InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) MBeanServer(javax.management.MBeanServer)

Aggregations

WorkQueueManager (org.apache.cxf.workqueue.WorkQueueManager)11 Executor (java.util.concurrent.Executor)4 IOException (java.io.IOException)3 Bus (org.apache.cxf.Bus)3 AutomaticWorkQueue (org.apache.cxf.workqueue.AutomaticWorkQueue)3 InetSocketAddress (java.net.InetSocketAddress)2 MulticastSocket (java.net.MulticastSocket)2 URI (java.net.URI)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 OneShotAsyncExecutor (org.apache.cxf.workqueue.OneShotAsyncExecutor)2 SynchronousExecutor (org.apache.cxf.workqueue.SynchronousExecutor)2 WorkQueue (org.apache.cxf.workqueue.WorkQueue)2 DatagramSocket (java.net.DatagramSocket)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 MBeanServer (javax.management.MBeanServer)1