Search in sources :

Example 1 with GlobalUID

use of jp.ossc.nimbus.util.net.GlobalUID 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)

Aggregations

UnknownHostException (java.net.UnknownHostException)1 AsynchContext (jp.ossc.nimbus.service.queue.AsynchContext)1 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)1 QueueHandlerContainerService (jp.ossc.nimbus.service.queue.QueueHandlerContainerService)1 GlobalUID (jp.ossc.nimbus.util.net.GlobalUID)1