Search in sources :

Example 1 with WorkQueue

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

the class UDPConduit method dataReceived.

private void dataReceived(Message message, IoBuffer buf, boolean async, boolean multi) {
    synchronized (message.getExchange()) {
        if (message.getExchange().getInMessage() == null) {
            final Message inMessage = new MessageImpl();
            IoSessionInputStream ins = new IoSessionInputStream(buf);
            inMessage.setContent(InputStream.class, ins);
            inMessage.put(IoSessionInputStream.class, ins);
            message.getExchange().setInMessage(inMessage);
            inMessage.setExchange(message.getExchange());
            Map<String, Object> mp = null;
            if (multi) {
                mp = new HashMap<>(message.getExchange());
            }
            if (async) {
                WorkQueueManager queuem = bus.getExtension(WorkQueueManager.class);
                WorkQueue queue = queuem.getNamedWorkQueue("udp-conduit");
                if (queue == null) {
                    queue = queuem.getAutomaticWorkQueue();
                }
                queue.execute(new Runnable() {

                    public void run() {
                        incomingObserver.onMessage(inMessage);
                    }
                });
            } else {
                incomingObserver.onMessage(inMessage);
                if (!message.getExchange().isSynchronous() || multi) {
                    message.getExchange().setInMessage(null);
                    message.getExchange().setInFaultMessage(null);
                }
            }
            if (mp != null) {
                Collection<String> s = new ArrayList<>(message.getExchange().keySet());
                for (String s2 : s) {
                    message.getExchange().remove(s2);
                }
                message.getExchange().putAll(mp);
            }
        } else {
            IoSessionInputStream ins = message.getExchange().getInMessage().get(IoSessionInputStream.class);
            ins.setBuffer(buf);
        }
    }
}
Also used : Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) MessageImpl(org.apache.cxf.message.MessageImpl) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) WorkQueue(org.apache.cxf.workqueue.WorkQueue)

Example 2 with WorkQueue

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

the class JMSFactory method createWorkQueueExecutor.

/**
 * Get workqueue from workqueue manager. Return an executor that will never reject messages and
 * instead block when all threads are used.
 *
 * @param bus
 * @param name
 * @return
 */
public static Executor createWorkQueueExecutor(Bus bus, String name) {
    WorkQueueManager manager = bus.getExtension(WorkQueueManager.class);
    if (manager != null) {
        AutomaticWorkQueue workQueue1 = manager.getNamedWorkQueue(name);
        final WorkQueue workQueue = (workQueue1 == null) ? manager.getAutomaticWorkQueue() : workQueue1;
        return new Executor() {

            @Override
            public void execute(Runnable command) {
                workQueue.execute(command, 0);
            }
        };
    }
    return Executors.newFixedThreadPool(20);
}
Also used : Executor(java.util.concurrent.Executor) AutomaticWorkQueue(org.apache.cxf.workqueue.AutomaticWorkQueue) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) WorkQueue(org.apache.cxf.workqueue.WorkQueue) AutomaticWorkQueue(org.apache.cxf.workqueue.AutomaticWorkQueue)

Aggregations

WorkQueue (org.apache.cxf.workqueue.WorkQueue)2 WorkQueueManager (org.apache.cxf.workqueue.WorkQueueManager)2 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 Message (org.apache.cxf.message.Message)1 MessageImpl (org.apache.cxf.message.MessageImpl)1 AutomaticWorkQueue (org.apache.cxf.workqueue.AutomaticWorkQueue)1