use of jp.ossc.nimbus.service.queue.AsynchContext in project nimbus by nimbus-org.
the class ServerConnectionImpl method sendAsynch.
public void sendAsynch(Message message) {
if (asynchSendQueueHandlerContainer == null) {
throw new UnsupportedOperationException();
}
addSendMessageCache((MessageImpl) message);
if (clients.size() == 0) {
return;
}
ClientImpl[] clientArray = (ClientImpl[]) clients.values().toArray(new ClientImpl[clients.size()]);
for (int i = 0; i < clientArray.length; i++) {
if (!clientArray[i].isStartReceive() || !clientArray[i].isTargetMessage(message)) {
continue;
}
asynchSendQueueHandlerContainer.push(new AsynchContext(new SendRequest(clientArray[i], (MessageImpl) message)));
}
}
use of jp.ossc.nimbus.service.queue.AsynchContext 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);
}
}
}
use of jp.ossc.nimbus.service.queue.AsynchContext in project nimbus by nimbus-org.
the class ServerConnectionImpl method send.
public synchronized void send(Message message) throws MessageSendException {
long startTime = System.currentTimeMillis();
if (clients.size() == 0) {
addSendMessageCache((MessageImpl) message);
return;
}
try {
if (sendQueueHandlerContainer == null) {
List currentClients = new ArrayList();
final Iterator clientItr = clients.iterator();
while (clientItr.hasNext()) {
ClientImpl client = (ClientImpl) clientItr.next();
if (!client.isStartReceive() || !client.isTargetMessage(message)) {
continue;
}
currentClients.add(client);
}
int retryCount = -1;
while (currentClients.size() != 0 && retryCount < maxSendRetryCount) {
Iterator itr = currentClients.iterator();
while (itr.hasNext()) {
ClientImpl client = (ClientImpl) itr.next();
try {
client.send(message);
itr.remove();
} catch (MessageSendException e) {
if (logger != null) {
if ((retryCount + 1) >= maxSendRetryCount) {
if (sendErrorRetryOverMessageId != null) {
logger.write(sendErrorRetryOverMessageId, new Object[] { client, message }, e);
}
} else {
if (sendErrorMessageId != null) {
logger.write(sendErrorMessageId, new Object[] { client, message }, e);
}
}
}
}
}
retryCount++;
}
if (currentClients.size() != 0) {
throw new MessageSendException("Send error : clients=" + currentClients + ", message=" + message);
}
((MessageImpl) message).setSend(true);
} else {
final Map sendContexts = new HashMap();
final Iterator clientItr = clients.iterator();
while (clientItr.hasNext()) {
ClientImpl client = (ClientImpl) clientItr.next();
if (!client.isStartReceive() || !client.isTargetMessage(message)) {
continue;
}
SendRequest sendRequest = createSendRequest(client, (MessageImpl) message);
AsynchContext asynchContext = createAsynchContext(sendRequest, sendResponseQueue);
sendContexts.put(client, asynchContext);
sendQueueHandlerContainer.push(asynchContext);
}
Throwable th = null;
for (int i = 0, imax = sendContexts.size(); i < imax; i++) {
AsynchContext asynchContext = (AsynchContext) sendResponseQueue.get();
if (asynchContext == null) {
Iterator itr = sendContexts.values().iterator();
while (itr.hasNext()) {
((AsynchContext) itr.next()).cancel();
}
throw new MessageSendException("Interrupted the waiting for a response sent : clients=" + sendContexts.keySet() + ", message=" + message, new InterruptedException());
} else if (asynchContext.isCancel()) {
i--;
continue;
} else if (asynchContext.getThrowable() == null) {
sendContexts.remove(((SendRequest) asynchContext.getInput()).client);
} else {
th = asynchContext.getThrowable();
}
recycleAsynchContext(asynchContext);
}
if (sendContexts.size() != 0) {
throw new MessageSendException("Send error : clients=" + sendContexts.keySet() + ", message=" + message, th);
}
((MessageImpl) message).setSend(true);
}
} finally {
addSendMessageCache((MessageImpl) message);
sendProcessTime += (System.currentTimeMillis() - startTime);
}
}
use of jp.ossc.nimbus.service.queue.AsynchContext in project nimbus by nimbus-org.
the class ServerConnectionImpl method createAsynchContext.
protected AsynchContext createAsynchContext(SendRequest input, Queue queue) {
AsynchContext result = null;
if (asynchContextBuffer.size() != 0) {
synchronized (asynchContextBuffer) {
if (asynchContextBuffer.size() != 0) {
result = (AsynchContext) asynchContextBuffer.remove(0);
result.setInput(input);
result.setResponseQueue(queue);
}
}
}
if (result == null) {
result = new AsynchContext(input, queue);
}
return result;
}
use of jp.ossc.nimbus.service.queue.AsynchContext in project nimbus by nimbus-org.
the class DistributedClientConnectionImpl method removeSubject.
public void removeSubject(String subject) throws MessageSendException {
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0, imax = connectionList.size(); i < imax; i++) {
((ClientConnection) connectionList.get(i)).removeSubject(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 RemoveSubjectParallelRequest((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);
}
}
}
}
}
Aggregations