Search in sources :

Example 6 with DefaultQueueService

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

the class ClusterService method startService.

public void startService() throws Exception {
    if (clusterListenerServiceNames != null) {
        for (int i = 0; i < clusterListenerServiceNames.length; i++) {
            listeners.add((ClusterListener) ServiceManagerFactory.getServiceObject(clusterListenerServiceNames[i]));
        }
    }
    if (targetServiceName != null) {
        DefaultClusterListenerService listener = new DefaultClusterListenerService();
        listener.setTargetServiceName(targetServiceName);
        listener.setClusterService(this);
        listener.create();
        listener.start();
        listeners.add(listener);
    }
    uidWithOption = new GlobalUID(localAddress, (optionMap == null || optionMap.size() == 0) ? option : (Serializable) optionMap);
    uidWithOption.setClient(isClient);
    uid = (GlobalUID) uidWithOption.clone();
    uid.setOption(null);
    if (multicastGroupAddress == null && (unicastMemberAddresses == null || unicastMemberAddresses.length == 0)) {
        throw new IllegalArgumentException("MulticastGroupAddress and UnicastMemberAddresses is null.");
    }
    eventQueue = new DefaultQueueService();
    ((Service) eventQueue).create();
    ((Service) eventQueue).start();
    eventQueue.accept();
    connect();
    if (!isClient) {
        synchronized (members) {
            members.clear();
            members.add(uidWithOption);
            if (multicastGroupAddress == null) {
                memberAddresses.add(new InetSocketAddress(uidWithOption.getAddress(), uidWithOption.getUnicastPort()));
            }
        }
    }
    eventHandler = new Daemon(new EventHandler());
    eventHandler.setName("Nimbus Cluster EventHandler " + getServiceNameObject());
    if (threadPriority >= 0) {
        eventHandler.setPriority(threadPriority);
    }
    eventHandler.start();
    clusterMessageReceiver = new Daemon(new MessageReceiver(socket));
    clusterMessageReceiver.setName("Nimbus Cluster MessageReceiver " + getServiceNameObject());
    if (threadPriority >= 0) {
        clusterMessageReceiver.setPriority(threadPriority);
    }
    clusterMessageReceiver.start();
    if (unicastSocket != null) {
        unicastClusterMessageReceiver = new Daemon(new MessageReceiver(unicastSocket));
        unicastClusterMessageReceiver.setName("Nimbus Cluster Unicast MessageReceiver " + getServiceNameObject());
        if (threadPriority >= 0) {
            unicastClusterMessageReceiver.setPriority(threadPriority);
        }
        unicastClusterMessageReceiver.start();
    }
    heartBeater = new Daemon(new HeartBeater());
    if (threadPriority >= 0) {
        heartBeater.setPriority(threadPriority);
    }
    heartBeater.setName("Nimbus Cluster HeartBeater " + getServiceNameObject());
    heartBeater.suspend();
    heartBeater.start();
    if (isJoinOnStart) {
        join();
    }
}
Also used : DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService)

Example 7 with DefaultQueueService

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

the class ClientConnectionImpl method connect.

private synchronized void connect(Object id, boolean isReconnect) throws ConnectException {
    if (socket != null) {
        return;
    }
    isConnected = false;
    try {
        try {
            if (socketFactory == null) {
                socket = new Socket(address, port, getBindAddress(), getBindPort());
            } else {
                socket = socketFactory.createSocket(address, port, getBindAddress(), getBindPort());
            }
            if (responseTimeout > 0) {
                socket.setSoTimeout((int) responseTimeout);
            }
            if (!isReconnect) {
                if (receiveAddress != null) {
                    receiveGroup = InetAddress.getByName(receiveAddress);
                    InetAddress bindAddress = getUDPBindAddress();
                    if (bindAddress == null) {
                        receiveSocket = receiveGroup.isMulticastAddress() ? new MulticastSocket(receivePort) : new DatagramSocket(receivePort);
                    } else {
                        final InetSocketAddress address = new InetSocketAddress(bindAddress, receivePort);
                        receiveSocket = receiveGroup.isMulticastAddress() ? new MulticastSocket(address) : new DatagramSocket(address);
                    }
                    if (receiveGroup.isMulticastAddress()) {
                        NetworkInterface[] networkInterfaces = getNetworkInterfaces();
                        if (networkInterfaces == null) {
                            ((MulticastSocket) receiveSocket).joinGroup(receiveGroup);
                        } else {
                            for (int i = 0; i < networkInterfaces.length; i++) {
                                ((MulticastSocket) receiveSocket).joinGroup(new InetSocketAddress(receiveGroup, receivePort), networkInterfaces[i]);
                            }
                        }
                    }
                } else {
                    InetAddress bindAddress = getUDPBindAddress();
                    if (bindAddress == null) {
                        receiveSocket = new DatagramSocket(receivePort);
                    } else {
                        receiveSocket = new DatagramSocket(new InetSocketAddress(bindAddress, receivePort));
                    }
                }
                if (receivePort == 0) {
                    receivePortReal = receiveSocket.getLocalPort();
                } else {
                    receivePortReal = receivePort;
                }
                if (receiveSocket != null) {
                    try {
                        int receiveBufferSize = receiveSocket.getReceiveBufferSize();
                        if (receiveBufferSize < windowSize) {
                            receiveSocket.setReceiveBufferSize(windowSize);
                        }
                    } catch (SocketException e) {
                    }
                }
            }
        } catch (UnknownHostException e) {
            throw new ConnectException(e);
        } catch (NumberFormatException e) {
            throw new ConnectException(e);
        } catch (IOException e) {
            throw new ConnectException(e);
        }
        if (receivePacketQueue == null) {
            receivePacketQueue = new DefaultQueueService();
            try {
                receivePacketQueue.create();
                receivePacketQueue.start();
            } catch (Exception e) {
                throw new ConnectException(e);
            }
        }
        if (packetReceiveDaemon == null) {
            packetReceiveDaemon = new Daemon(new PacketReceiver());
            packetReceiveDaemon.setDaemon(true);
            packetReceiveDaemon.setName("Nimbus Publish(UDP) ClientConnection PacketReceiver " + socket.getLocalSocketAddress());
            packetReceiveDaemon.start();
        }
        if (replyReceiveDaemon == null) {
            replyReceiveDaemon = new Daemon(new ReplyReceiver());
            replyReceiveDaemon.setDaemon(true);
            replyReceiveDaemon.setName("Nimbus Publish(UDP) ClientConnection ReplyReceiver " + socket.getLocalSocketAddress());
            replyReceiveDaemon.start();
        }
        if (messageReceiveDaemon == null) {
            messageReceiveDaemon = new Daemon(new MessageReceiver());
            messageReceiveDaemon.setDaemon(true);
            messageReceiveDaemon.setName("Nimbus Publish(UDP) ClientConnection MessageReceiver " + socket.getLocalSocketAddress());
        }
        if (missingWindowCheckDaemon == null) {
            missingWindowCheckDaemon = new Daemon(new MissingWindowChecker((MessageReceiver) messageReceiveDaemon.getDaemonRunnable()));
            missingWindowCheckDaemon.setDaemon(true);
            missingWindowCheckDaemon.setName("Nimbus Publish(UDP) ClientConnection MissingWindowChecker " + socket.getLocalSocketAddress());
            ((MessageReceiver) messageReceiveDaemon.getDaemonRunnable()).setPacketReceiver((PacketReceiver) packetReceiveDaemon.getDaemonRunnable());
            ((MessageReceiver) messageReceiveDaemon.getDaemonRunnable()).setMissingWindowChecker((MissingWindowChecker) missingWindowCheckDaemon.getDaemonRunnable());
        }
        messageReceiveDaemon.start();
        missingWindowCheckDaemon.start();
        this.id = id == null ? socket.getLocalSocketAddress() : id;
        try {
            IdMessage message = new IdMessage(this.id);
            message.setReceivePort(receivePortReal);
            send(message, isAcknowledge);
        } catch (IOException e) {
            throw new ConnectException(e);
        } catch (ClassNotFoundException e) {
            throw new ConnectException(e);
        }
        if (serverServiceName != null) {
            ServiceManager manager = ServiceManagerFactory.findManager(serviceManagerName == null ? serverServiceName.getServiceManagerName() : serviceManagerName);
            if (manager != null) {
                final ClientConnectionService ccs = new ClientConnectionService();
                try {
                    String name = serverServiceName.getServiceName() + '$' + socket.getLocalSocketAddress();
                    name = name.replaceAll(":", "\\$");
                    if (!manager.isRegisteredService(name) && manager.registerService(name, ccs)) {
                        serviceName = ccs.getServiceNameObject();
                        manager.createService(ccs.getServiceName());
                        manager.startService(ccs.getServiceName());
                    }
                } catch (Exception e) {
                    throw new ConnectException(e);
                }
            }
        }
    } catch (ConnectException e) {
        if (socket != null) {
            try {
                socket.close();
            } catch (IOException e2) {
            }
            socket = null;
        }
        if (!isReconnect && receiveSocket != null) {
            receiveSocket.close();
            receiveSocket = null;
        }
        throw e;
    }
    isConnected = true;
    isServerClosed = false;
}
Also used : MulticastSocket(java.net.MulticastSocket) SocketException(java.net.SocketException) InetSocketAddress(java.net.InetSocketAddress) ServiceManager(jp.ossc.nimbus.core.ServiceManager) ConnectException(jp.ossc.nimbus.service.publish.ConnectException) UnknownHostException(java.net.UnknownHostException) NetworkInterface(java.net.NetworkInterface) IOException(java.io.IOException) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) ConnectException(jp.ossc.nimbus.service.publish.ConnectException) EOFException(java.io.EOFException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Daemon(jp.ossc.nimbus.daemon.Daemon) DatagramSocket(java.net.DatagramSocket) InetAddress(java.net.InetAddress) Socket(java.net.Socket) DatagramSocket(java.net.DatagramSocket) MulticastSocket(java.net.MulticastSocket)

Example 8 with DefaultQueueService

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

the class ServerConnectionImpl method initSend.

private void initSend(ServiceName sendQueueServiceName, int sendThreadSize, boolean isMulticast) throws Exception {
    if (!isMulticast && sendThreadSize >= 1) {
        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.setIgnoreNullElement(true);
        sendQueueHandlerContainer.setWaitTimeout(1000l);
        sendQueueHandlerContainer.start();
        sendResponseQueue = new DefaultQueueService();
        try {
            sendResponseQueue.create();
            sendResponseQueue.start();
        } catch (Exception e) {
            throw new MessageSendException(e);
        }
        sendResponseQueue.accept();
    }
}
Also used : DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageCreateException(jp.ossc.nimbus.service.publish.MessageCreateException) EOFException(java.io.EOFException) CancelledKeyException(java.nio.channels.CancelledKeyException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) MessageException(jp.ossc.nimbus.service.publish.MessageException) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Example 9 with DefaultQueueService

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

the class ServerConnectionImpl method send.

public void send(Message message) throws MessageSendException {
    addSendMessageCache((MessageImpl) message);
    if (clients.size() == 0) {
        return;
    }
    ClientImpl[] clientArray = (ClientImpl[]) clients.values().toArray(new ClientImpl[clients.size()]);
    if (sendQueueHandlerContainer == null) {
        for (int i = 0; i < clientArray.length; i++) {
            if (!clientArray[i].isStartReceive() || !clientArray[i].isTargetMessage(message)) {
                continue;
            }
            clientArray[i].send((MessageImpl) message);
        }
    } else {
        DefaultQueueService responseQueue = new DefaultQueueService();
        try {
            responseQueue.create();
            responseQueue.start();
        } catch (Exception e) {
            throw new MessageSendException(e);
        }
        responseQueue.accept();
        for (int i = 0; i < clientArray.length; i++) {
            if (!clientArray[i].isStartReceive() || !clientArray[i].isTargetMessage(message)) {
                clientArray[i] = null;
                continue;
            }
            sendQueueHandlerContainer.push(new AsynchContext(new SendRequest(clientArray[i], (MessageImpl) message), responseQueue));
        }
        List errorClients = new ArrayList();
        for (int i = 0; i < clientArray.length; i++) {
            if (clientArray[i] == null) {
                continue;
            }
            AsynchContext asynchContext = (AsynchContext) responseQueue.get();
            if (asynchContext.getThrowable() != null) {
                errorClients.add(((SendRequest) asynchContext.getInput()).client);
            }
        }
        if (errorClients.size() != 0) {
            throw new MessageSendException("Send error : clients=" + errorClients + ", message=" + message);
        }
    }
}
Also used : MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) ArrayList(java.util.ArrayList) AsynchContext(jp.ossc.nimbus.service.queue.AsynchContext) ArrayList(java.util.ArrayList) List(java.util.List) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageException(jp.ossc.nimbus.service.publish.MessageException) ConnectException(jp.ossc.nimbus.service.publish.ConnectException) MessageCreateException(jp.ossc.nimbus.service.publish.MessageCreateException)

Example 10 with DefaultQueueService

use of jp.ossc.nimbus.service.queue.DefaultQueueService 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.setIgnoreNullElement(true);
        sendQueueHandlerContainer.setWaitTimeout(1000l);
        sendQueueHandlerContainer.start();
        sendResponseQueue = new DefaultQueueService();
        try {
            sendResponseQueue.create();
            sendResponseQueue.start();
        } catch (Exception e) {
            throw new MessageSendException(e);
        }
        sendResponseQueue.accept();
    }
}
Also used : DistributedQueueHandlerContainerService(jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService) QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) MessageCreateException(jp.ossc.nimbus.service.publish.MessageCreateException) EOFException(java.io.EOFException) CancelledKeyException(java.nio.channels.CancelledKeyException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) MessageException(jp.ossc.nimbus.service.publish.MessageException) ClosedSelectorException(java.nio.channels.ClosedSelectorException)

Aggregations

DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)32 AsynchContext (jp.ossc.nimbus.service.queue.AsynchContext)20 MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)14 MessageException (jp.ossc.nimbus.service.publish.MessageException)13 EvaluateException (jp.ossc.nimbus.service.interpreter.EvaluateException)11 IndexNotFoundException (jp.ossc.nimbus.beans.IndexNotFoundException)10 IndexPropertyAccessException (jp.ossc.nimbus.beans.IndexPropertyAccessException)10 RequestTimeoutException (jp.ossc.nimbus.service.publish.RequestTimeoutException)10 QueueHandlerContainerService (jp.ossc.nimbus.service.queue.QueueHandlerContainerService)10 UnknownHostException (java.net.UnknownHostException)9 DistributedQueueHandlerContainerService (jp.ossc.nimbus.service.queue.DistributedQueueHandlerContainerService)6 EOFException (java.io.EOFException)3 IOException (java.io.IOException)3 SocketException (java.net.SocketException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 CacheMap (jp.ossc.nimbus.service.cache.CacheMap)3 MessageCreateException (jp.ossc.nimbus.service.publish.MessageCreateException)3