Search in sources :

Example 6 with WorkQueueManager

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

the class UDPDestination method activate.

protected void activate() {
    WorkQueueManager queuem = bus.getExtension(WorkQueueManager.class);
    queue = queuem.getNamedWorkQueue("udp-transport");
    if (queue == null) {
        queue = queuem.getAutomaticWorkQueue();
    }
    try {
        URI uri = new URI(this.getAddress().getAddress().getValue());
        InetSocketAddress isa = null;
        if (StringUtils.isEmpty(uri.getHost())) {
            String s = uri.getSchemeSpecificPart();
            if (s.startsWith("//:")) {
                s = s.substring(3);
            }
            if (s.indexOf('/') != -1) {
                s = s.substring(0, s.indexOf('/'));
            }
            int port = Integer.parseInt(s);
            isa = new InetSocketAddress(port);
        } else {
            isa = new InetSocketAddress(uri.getHost(), uri.getPort());
        }
        DatagramSocket s;
        if (isa.getAddress().isMulticastAddress()) {
            s = new MulticastSocket(null);
            ((MulticastSocket) s).setTimeToLive(1);
            s.bind(new InetSocketAddress(isa.getPort()));
            ((MulticastSocket) s).joinGroup(isa.getAddress());
        } else {
            s = new DatagramSocket(null);
            s.bind(new InetSocketAddress(isa.getAddress(), isa.getPort()));
        }
        s.setReuseAddress(true);
        s.setReceiveBufferSize(64 * 1024);
        s.setSendBufferSize(64 * 1024);
        socket = s;
        queue.execute(new SocketListener());
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.toString());
        throw new RuntimeException(ex);
    }
}
Also used : MulticastSocket(java.net.MulticastSocket) DatagramSocket(java.net.DatagramSocket) InetSocketAddress(java.net.InetSocketAddress) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) URI(java.net.URI) IOException(java.io.IOException)

Example 7 with WorkQueueManager

use of org.apache.cxf.workqueue.WorkQueueManager in project tomee 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 8 with WorkQueueManager

use of org.apache.cxf.workqueue.WorkQueueManager 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 9 with WorkQueueManager

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

the class UDPDestination method activate.

protected void activate() {
    WorkQueueManager queuem = bus.getExtension(WorkQueueManager.class);
    queue = queuem.getNamedWorkQueue("udp-transport");
    if (queue == null) {
        queue = queuem.getAutomaticWorkQueue();
    }
    try {
        URI uri = new URI(this.getAddress().getAddress().getValue());
        InetSocketAddress isa = null;
        if (StringUtils.isEmpty(uri.getHost())) {
            String s = uri.getSchemeSpecificPart();
            if (s.startsWith("//:")) {
                s = s.substring(3);
            }
            if (s.indexOf('/') != -1) {
                s = s.substring(0, s.indexOf('/'));
            }
            int port = Integer.parseInt(s);
            isa = new InetSocketAddress(port);
        } else {
            isa = new InetSocketAddress(uri.getHost(), uri.getPort());
        }
        if (isa.getAddress().isMulticastAddress()) {
            // ouch...
            MulticastSocket socket = new MulticastSocket(null);
            socket.setReuseAddress(true);
            socket.setReceiveBufferSize(64 * 1024);
            socket.setSendBufferSize(64 * 1024);
            socket.setTimeToLive(1);
            socket.setLoopbackMode(false);
            socket.bind(new InetSocketAddress(isa.getPort()));
            socket.setNetworkInterface(findNetworkInterface());
            socket.joinGroup(isa.getAddress());
            mcast = socket;
            queue.execute(new MCastListener());
        } else {
            acceptor = new NioDatagramAcceptor();
            acceptor.setHandler(new UDPIOHandler());
            acceptor.setDefaultLocalAddress(isa);
            DatagramSessionConfig dcfg = acceptor.getSessionConfig();
            dcfg.setReadBufferSize(64 * 1024);
            dcfg.setSendBufferSize(64 * 1024);
            dcfg.setReuseAddress(true);
            acceptor.bind();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
}
Also used : MulticastSocket(java.net.MulticastSocket) InetSocketAddress(java.net.InetSocketAddress) DatagramSessionConfig(org.apache.mina.transport.socket.DatagramSessionConfig) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) URI(java.net.URI) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) NioDatagramAcceptor(org.apache.mina.transport.socket.nio.NioDatagramAcceptor)

Example 10 with WorkQueueManager

use of org.apache.cxf.workqueue.WorkQueueManager 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

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