use of jp.ossc.nimbus.service.queue.AsynchContext in project nimbus by nimbus-org.
the class DistributedSharedContextService method keySet.
public Set keySet(long timeout) throws SharedContextSendException, SharedContextTimeoutException {
Set result = new HashSet();
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0; i < sharedContextArray.length; i++) {
long start = System.currentTimeMillis();
final boolean isNoTimeout = timeout <= 0;
timeout = isNoTimeout ? timeout : timeout - (System.currentTimeMillis() - start);
if (!isNoTimeout && timeout < 0) {
throw new SharedContextTimeoutException("nodeSize=" + sharedContextArray.length + ", responseCount=" + i);
}
result.addAll(sharedContextArray[i].keySet(timeout));
}
} else {
DefaultQueueService responseQueue = new DefaultQueueService();
try {
responseQueue.create();
responseQueue.start();
} catch (Exception e) {
}
responseQueue.accept();
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = new AsynchContext(new KeySetParallelRequest(sharedContextArray[i], timeout), responseQueue);
parallelRequestQueueHandlerContainer.push(asynchContext);
}
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = (AsynchContext) responseQueue.get();
if (asynchContext == null) {
break;
} else {
try {
asynchContext.checkError();
} catch (SharedContextSendException e) {
throw e;
} catch (SharedContextTimeoutException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new SharedContextSendException(th);
}
result.addAll((Set) asynchContext.getOutput());
}
}
}
return result;
}
use of jp.ossc.nimbus.service.queue.AsynchContext in project nimbus by nimbus-org.
the class DistributedSharedContextService method putAll.
public void putAll(Map t, long timeout) throws SharedContextSendException, SharedContextTimeoutException {
final long start = System.currentTimeMillis();
Map distMap = new HashMap();
Iterator entries = t.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
SharedContext context = selectDistributeContext(entry.getKey());
Map map = (Map) distMap.get(context);
if (map == null) {
map = new HashMap();
distMap.put(context, map);
}
map.put(entry.getKey(), entry.getValue());
}
if (parallelRequestQueueHandlerContainer == null) {
int completed = 0;
entries = distMap.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
if (timeout > 0) {
final long currentTimeout = timeout - (start - System.currentTimeMillis());
if (currentTimeout > 0) {
((SharedContext) entry.getKey()).putAll((Map) entry.getValue(), currentTimeout);
} else {
throw new SharedContextTimeoutException("There is a node that is not possible yet putAll. completed=" + completed + "notCompleted=" + (distMap.size() - completed));
}
} else {
((SharedContext) entry.getKey()).putAll((Map) entry.getValue(), timeout);
}
completed++;
}
} else {
DefaultQueueService responseQueue = new DefaultQueueService();
try {
responseQueue.create();
responseQueue.start();
} catch (Exception e) {
}
responseQueue.accept();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
AsynchContext asynchContext = new AsynchContext(new PutAllParallelRequest((SharedContext) entry.getKey(), (Map) entry.getValue(), timeout), responseQueue);
parallelRequestQueueHandlerContainer.push(asynchContext);
}
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = (AsynchContext) responseQueue.get();
if (asynchContext == null) {
break;
} else {
try {
asynchContext.checkError();
} catch (SharedContextSendException e) {
throw e;
} catch (SharedContextTimeoutException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new SharedContextSendException(th);
}
}
}
}
}
use of jp.ossc.nimbus.service.queue.AsynchContext in project nimbus by nimbus-org.
the class DistributedSharedContextService method clearAsynch.
public void clearAsynch() throws SharedContextSendException {
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0; i < sharedContextArray.length; i++) {
sharedContextArray[i].clearAsynch();
}
} else {
DefaultQueueService responseQueue = new DefaultQueueService();
try {
responseQueue.create();
responseQueue.start();
} catch (Exception e) {
}
responseQueue.accept();
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = new AsynchContext(new ClearAsynchParallelRequest(sharedContextArray[i]), responseQueue);
parallelRequestQueueHandlerContainer.push(asynchContext);
}
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = (AsynchContext) responseQueue.get();
if (asynchContext == null) {
break;
} else {
try {
asynchContext.checkError();
} catch (SharedContextSendException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new SharedContextSendException(th);
}
}
}
}
}
use of jp.ossc.nimbus.service.queue.AsynchContext in project nimbus by nimbus-org.
the class DistributedSharedContextService method save.
public synchronized void save(long timeout) throws Exception {
if (isMain()) {
if (contextStore != null) {
if (isClearBeforeSave) {
contextStore.clear();
}
if (parallelRequestQueueHandlerContainer == null) {
for (int i = 0; i < sharedContextArray.length; i++) {
sharedContextArray[i].save(timeout);
}
} else {
DefaultQueueService responseQueue = new DefaultQueueService();
try {
responseQueue.create();
responseQueue.start();
} catch (Exception e) {
}
responseQueue.accept();
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = new AsynchContext(new SaveParallelRequest(sharedContextArray[i], timeout), responseQueue);
parallelRequestQueueHandlerContainer.push(asynchContext);
}
for (int i = 0; i < sharedContextArray.length; i++) {
AsynchContext asynchContext = (AsynchContext) responseQueue.get();
if (asynchContext == null) {
break;
} else {
try {
asynchContext.checkError();
} catch (Exception e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable th) {
// 起きないはず
throw new SharedContextSendException(th);
}
}
}
}
} else {
throw new UnsupportedOperationException();
}
} else {
try {
Message message = serverConnection.createMessage(subject, null);
Set receiveClients = serverConnection.getReceiveClientIds(message);
if (receiveClients.size() != 0) {
message.setObject(new DistributedSharedContextEvent(DistributedSharedContextEvent.EVENT_SAVE, new Long(timeout)));
try {
Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, null, 1, timeout);
Object ret = responses[0].getObject();
responses[0].recycle();
if (ret instanceof Throwable) {
throw new SharedContextSendException((Throwable) ret);
}
} catch (RequestTimeoutException e) {
throw new SharedContextTimeoutException(e);
}
}
} catch (MessageException e) {
throw new SharedContextSendException(e);
} catch (MessageSendException e) {
throw new SharedContextSendException(e);
}
}
}
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;
}
Aggregations