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;
}
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();
}
}
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;
}
}
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();
}
}
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();
}
}
Aggregations