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