Search in sources :

Example 6 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class DistributedClientConnectionImpl method connect.

public void connect(Object id) throws ConnectException {
    Object tmpId = null;
    if (id == null) {
        try {
            tmpId = new GlobalUID();
        } catch (UnknownHostException e) {
            throw new ConnectException(e);
        }
    } else {
        tmpId = id;
    }
    if (connectionList.size() > 1) {
        try {
            parallelRequestQueueHandlerContainer = new QueueHandlerContainerService();
            parallelRequestQueueHandlerContainer.create();
            parallelRequestQueueHandlerContainer.setQueueHandlerSize(connectionList.size());
            DefaultQueueService parallelRequestQueue = new DefaultQueueService();
            parallelRequestQueue.create();
            parallelRequestQueue.start();
            parallelRequestQueueHandlerContainer.setQueueService(parallelRequestQueue);
            parallelRequestQueueHandlerContainer.setQueueHandler(new ParallelRequestQueueHandler());
            parallelRequestQueueHandlerContainer.setIgnoreNullElement(true);
            parallelRequestQueueHandlerContainer.setWaitTimeout(1000l);
            parallelRequestQueueHandlerContainer.start();
        } catch (Exception e) {
            throw new ConnectException(e);
        }
    }
    if (parallelRequestQueueHandlerContainer == null) {
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            ClientConnection connection = (ClientConnection) connectionList.get(i);
            connection.setServiceManagerName(serviceManagerName);
            connection.connect(tmpId);
        }
    } else {
        DefaultQueueService responseQueue = new DefaultQueueService();
        try {
            responseQueue.create();
            responseQueue.start();
        } catch (Exception e) {
        }
        responseQueue.accept();
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = new AsynchContext(new ConnectParallelRequest((ClientConnection) connectionList.get(i), tmpId), responseQueue);
            parallelRequestQueueHandlerContainer.push(asynchContext);
        }
        for (int i = 0, imax = connectionList.size(); i < imax; i++) {
            AsynchContext asynchContext = (AsynchContext) responseQueue.get();
            if (asynchContext == null) {
                break;
            } else {
                try {
                    asynchContext.checkError();
                } catch (ConnectException e) {
                    throw e;
                } catch (RuntimeException e) {
                    throw e;
                } catch (Error e) {
                    throw e;
                } catch (Throwable th) {
                    // 起きないはず
                    throw new ConnectException(th);
                }
            }
        }
    }
    this.id = tmpId;
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) UnknownHostException(java.net.UnknownHostException) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) UnknownHostException(java.net.UnknownHostException) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) GlobalUID(jp.ossc.nimbus.util.net.GlobalUID)

Example 7 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class ServerConnectionImpl method initRequestHandle.

private void initRequestHandle(ServiceName requestHandleQueueServiceName, int requestHandleThreadSize) throws Exception {
    if (requestHandleThreadSize >= 1) {
        requestHandleQueueHandlerContainer = new QueueHandlerContainerService();
        requestHandleQueueHandlerContainer.create();
        if (requestHandleQueueServiceName == null) {
            DefaultQueueService requestHandleQueue = new DefaultQueueService();
            requestHandleQueue.create();
            requestHandleQueue.start();
            requestHandleQueueHandlerContainer.setQueueService(requestHandleQueue);
        } else {
            requestHandleQueueHandlerContainer.setQueueServiceName(requestHandleQueueServiceName);
        }
        requestHandleQueueHandlerContainer.setQueueHandlerSize(requestHandleThreadSize);
        requestHandleQueueHandlerContainer.setQueueHandler(new RequestHandleQueueHandler());
        requestHandleQueueHandlerContainer.setIgnoreNullElement(true);
        requestHandleQueueHandlerContainer.setWaitTimeout(1000l);
        requestHandleQueueHandlerContainer.start();
    }
}
Also used : DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Example 8 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class ServerConnectionImpl method initAsynchSend.

private void initAsynchSend(ServiceName queueServiceName, ServiceName queueFactoryServiceName, int asynchSendThreadSize, boolean isMulticast) throws Exception {
    if (asynchSendThreadSize <= 0) {
        return;
    }
    asynchAcceptQueueHandlerContainer = new QueueHandlerContainerService();
    asynchAcceptQueueHandlerContainer.create();
    if (queueServiceName == null) {
        DefaultQueueService acceptQueue = new DefaultQueueService();
        acceptQueue.create();
        acceptQueue.start();
        asynchAcceptQueueHandlerContainer.setQueueService(acceptQueue);
    } else {
        asynchAcceptQueueHandlerContainer.setQueueServiceName(queueServiceName);
    }
    asynchAcceptQueueHandlerContainer.setQueueHandlerSize(1);
    asynchAcceptQueueHandlerContainer.setQueueHandler(new AsynchAcceptQueueHandler());
    asynchAcceptQueueHandlerContainer.setIgnoreNullElement(true);
    asynchAcceptQueueHandlerContainer.setWaitTimeout(1000l);
    asynchAcceptQueueHandlerContainer.start();
    if (!isMulticast) {
        queueSelector = new ClientDistributedQueueSelector();
        queueSelector.create();
        queueSelector.setDistributedSize(asynchSendThreadSize);
        if (queueFactoryServiceName != null) {
            queueSelector.setQueueFactoryServiceName(queueFactoryServiceName);
        }
        queueSelector.start();
        DistributedQueueHandlerContainerService distributedQueueHandlerContainer = new DistributedQueueHandlerContainerService();
        distributedQueueHandlerContainer.create();
        distributedQueueHandlerContainer.setDistributedQueueSelector(queueSelector);
        distributedQueueHandlerContainer.setQueueHandler(new SendQueueHandler());
        distributedQueueHandlerContainer.setIgnoreNullElement(true);
        distributedQueueHandlerContainer.setWaitTimeout(1000l);
        distributedQueueHandlerContainer.start();
        asynchSendQueueHandlerContainer = distributedQueueHandlerContainer;
    }
}
Also used : DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Example 9 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class ServerConnectionImpl method initSend.

private void initSend(ServiceName sendQueueServiceName, int sendThreadSize) throws Exception {
    if (sendThreadSize >= 2) {
        sendQueueHandlerContainer = new QueueHandlerContainerService();
        sendQueueHandlerContainer.create();
        if (sendQueueServiceName == null) {
            DefaultQueueService sendQueue = new DefaultQueueService();
            sendQueue.create();
            sendQueue.start();
            sendQueueHandlerContainer.setQueueService(sendQueue);
        } else {
            sendQueueHandlerContainer.setQueueServiceName(sendQueueServiceName);
        }
        sendQueueHandlerContainer.setQueueHandlerSize(sendThreadSize);
        sendQueueHandlerContainer.setQueueHandler(new SendQueueHandler());
        sendQueueHandlerContainer.start();
    }
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Example 10 with QueueHandlerContainerService

use of jp.ossc.nimbus.service.queue.QueueHandlerContainerService in project nimbus by nimbus-org.

the class MessageReceiverService method startService.

public void startService() throws Exception {
    if (messageQueueDistributedSize > 1) {
        messageQueueSelector = new MessageDistributedQueueSelector();
        messageQueueSelector.setServiceManagerName(getServiceManagerName());
        messageQueueSelector.setServiceName(getServiceName() + "$MessageQueueSelector");
        messageQueueSelector.create();
        messageQueueSelector.setDistributedSize(messageQueueDistributedSize);
        if (messageQueueFactoryServiceName != null) {
            messageQueueSelector.setQueueFactoryServiceName(messageQueueFactoryServiceName);
        }
        messageQueueSelector.start();
        DistributedQueueHandlerContainerService queueHandlerContainer = new DistributedQueueHandlerContainerService();
        queueHandlerContainer.setServiceManagerName(getServiceManagerName());
        queueHandlerContainer.setServiceName(getServiceName() + "$MessageQueueHandlerContainer");
        queueHandlerContainer.create();
        queueHandlerContainer.setDistributedQueueSelector(messageQueueSelector);
        queueHandlerContainer.setQueueHandler(new MessageQueueHandler());
        queueHandlerContainer.setIgnoreNullElement(true);
        queueHandlerContainer.setWaitTimeout(1000l);
        queueHandlerContainer.start();
        messageQueueHandlerContainer = queueHandlerContainer;
    } else if (messageQueueDistributedSize == 1) {
        QueueHandlerContainerService queueHandlerContainer = new QueueHandlerContainerService();
        queueHandlerContainer.setServiceManagerName(getServiceManagerName());
        queueHandlerContainer.setServiceName(getServiceName() + "$MessageQueueHandlerContainer");
        queueHandlerContainer.create();
        queueHandlerContainer.setQueueServiceName(messageQueueFactoryServiceName);
        queueHandlerContainer.setQueueHandler(new MessageQueueHandler());
        queueHandlerContainer.setIgnoreNullElement(true);
        queueHandlerContainer.setWaitTimeout(1000l);
        queueHandlerContainer.start();
        messageQueueHandlerContainer = queueHandlerContainer;
    }
    if (messageListenerQueueDistributedSize > 0) {
        messageListenerQueueSelector = new MessageListenerDistributedQueueSelector();
        messageListenerQueueSelector.setServiceManagerName(getServiceManagerName());
        messageListenerQueueSelector.setServiceName(getServiceName() + "$MessageListenerQueueSelector");
        messageListenerQueueSelector.create();
        messageListenerQueueSelector.setDistributedSize(messageListenerQueueDistributedSize);
        if (messageListenerQueueFactoryServiceName != null) {
            messageListenerQueueSelector.setQueueFactoryServiceName(messageListenerQueueFactoryServiceName);
        }
        messageListenerQueueSelector.start();
        messageListenerQueueHandlerContainer = new DistributedQueueHandlerContainerService();
        messageListenerQueueHandlerContainer.setServiceManagerName(getServiceManagerName());
        messageListenerQueueHandlerContainer.setServiceName(getServiceName() + "$MessageListenerQueueHandlerContainer");
        messageListenerQueueHandlerContainer.create();
        messageListenerQueueHandlerContainer.setDistributedQueueSelector(messageListenerQueueSelector);
        messageListenerQueueHandlerContainer.setQueueHandler(new MessageListenerQueueHandler());
        messageListenerQueueHandlerContainer.setIgnoreNullElement(true);
        messageListenerQueueHandlerContainer.setWaitTimeout(1000l);
        messageListenerQueueHandlerContainer.start();
    }
    if (messageLatencyPerformanceRecorderServiceName != null) {
        messageLatencyPerformanceRecorder = (PerformanceRecorder) ServiceManagerFactory.getServiceObject(messageLatencyPerformanceRecorderServiceName);
    }
    clientConnection = new WrappedClientConnection();
    if (isConnectOnStart) {
        connect();
    }
    if (registeredListenerMap.size() != 0) {
        final Iterator listenerEntries = registeredListenerMap.entrySet().iterator();
        while (listenerEntries.hasNext()) {
            final Map.Entry listenerEntry = (Map.Entry) listenerEntries.next();
            Object listenerObj = listenerEntry.getKey();
            MessageListener listener = null;
            if (listenerObj instanceof ServiceName) {
                listener = (MessageListener) ServiceManagerFactory.getServiceObject((ServiceName) listenerObj);
            } else {
                listener = (MessageListener) listenerObj;
            }
            final Map subjectMap = (Map) listenerEntry.getValue();
            final Iterator subjectEntries = subjectMap.entrySet().iterator();
            while (subjectEntries.hasNext()) {
                final Map.Entry subjectEntry = (Map.Entry) subjectEntries.next();
                String subject = (String) subjectEntry.getKey();
                Set keySet = (Set) subjectEntry.getValue();
                if (keySet.remove(null)) {
                    addSubject(listener, subject);
                }
                addSubject(listener, subject, (String[]) keySet.toArray(new String[keySet.size()]));
            }
        }
    }
    if (isStartReceiveOnStart) {
        startReceive();
    }
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) ServiceName(jp.ossc.nimbus.core.ServiceName) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

QueueHandlerContainerService (jp.ossc.nimbus.service.queue.QueueHandlerContainerService)12 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)10 DistributedQueueHandlerContainerService (jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService)7 EOFException (java.io.EOFException)2 IOException (java.io.IOException)2 SocketException (java.net.SocketException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 CancelledKeyException (java.nio.channels.CancelledKeyException)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 ClosedSelectorException (java.nio.channels.ClosedSelectorException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 MessageCreateException (jp.ossc.nimbus.service.publish.MessageCreateException)2 MessageException (jp.ossc.nimbus.service.publish.MessageException)2 MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)2 AsynchContext (jp.ossc.nimbus.service.queue.AsynchContext)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1 HashSet (java.util.HashSet)1