use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class DistributedClientConnectionImpl method close.
public void close() {
try {
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0, imax = connectionList.size(); i < imax; i++) {
try {
((ClientConnection) connectionList.get(i)).close();
} catch (RuntimeException e) {
}
}
} 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 CloseParallelRequest((ClientConnection) connectionList.get(i)), 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 (Throwable th) {
// 起きないはず
}
}
}
}
if (parallelRequestQueueHandlerContainer != null) {
parallelRequestQueueHandlerContainer.stop();
parallelRequestQueueHandlerContainer.destroy();
parallelRequestQueueHandlerContainer = null;
}
} finally {
id = null;
}
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService 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.DefaultQueueService in project nimbus by nimbus-org.
the class DistributedClientConnectionImpl method removeSubject.
public void removeSubject(String subject, String[] keys) throws MessageSendException {
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0, imax = connectionList.size(); i < imax; i++) {
((ClientConnection) connectionList.get(i)).removeSubject(subject, keys);
}
} 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 RemoveSubjectParallelRequest((ClientConnection) connectionList.get(i), subject, keys), 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 (MessageSendException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new MessageSendException(th);
}
}
}
}
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService in project nimbus by nimbus-org.
the class DistributedClientConnectionImpl method addSubject.
public void addSubject(String subject) throws MessageSendException {
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0, imax = connectionList.size(); i < imax; i++) {
((ClientConnection) connectionList.get(i)).addSubject(subject);
}
} 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 AddSubjectParallelRequest((ClientConnection) connectionList.get(i), subject), 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 (MessageSendException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new MessageSendException(th);
}
}
}
}
}
use of jp.ossc.nimbus.service.queue.DefaultQueueService 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();
}
}
Aggregations