use of jp.ossc.nimbus.service.publish.MessageException 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.publish.MessageException in project nimbus by nimbus-org.
the class DistributedSharedContextService method setRehashEnabled.
public void setRehashEnabled(boolean isEnabled) throws SharedContextSendException, SharedContextTimeoutException {
if (getState() == STARTED) {
try {
Message message = serverConnection.createMessage(subject, Integer.toString(DistributedSharedContextEvent.EVENT_REHASH_SWITCH));
message.setSubject(clientSubject, null);
Set receiveClients = serverConnection.getReceiveClientIds(message);
if (receiveClients.size() != 0) {
message.setObject(new DistributedSharedContextEvent(DistributedSharedContextEvent.EVENT_REHASH_SWITCH, isEnabled ? Boolean.TRUE : Boolean.FALSE));
try {
Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, null, 0, defaultTimeout);
for (int i = 0; i < responses.length; i++) {
Object ret = responses[i].getObject();
responses[i].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);
}
}
isRehashEnabled = isEnabled;
}
use of jp.ossc.nimbus.service.publish.MessageException in project nimbus by nimbus-org.
the class DistributedSharedContextService method displayDistributeInfo.
public String displayDistributeInfo() throws SharedContextSendException, SharedContextTimeoutException {
DistributeGrid grid = new DistributeGrid();
try {
Message message = serverConnection.createMessage(subject, Integer.toString(DistributedSharedContextEvent.EVENT_GET_DIST_INFO));
Set receiveClients = serverConnection.getReceiveClientIds(message);
if (!isClient) {
grid.addDistributeInfo(distributeInfo);
}
if (receiveClients.size() != 0) {
long timeout = rehashTimeout;
message.setObject(new DistributedSharedContextEvent(DistributedSharedContextEvent.EVENT_GET_DIST_INFO, new Long(timeout)));
try {
Message[] responses = serverConnection.request(message, isClient ? clientSubject : subject, null, 0, timeout);
for (int i = 0; i < responses.length; i++) {
grid.addDistributeInfo((DistributeInfo) responses[i].getObject());
responses[i].recycle();
}
} catch (RequestTimeoutException e) {
throw new SharedContextTimeoutException(e);
}
}
} catch (MessageException e) {
throw new SharedContextSendException(e);
} catch (MessageSendException e) {
throw new SharedContextSendException(e);
}
return grid.toString();
}
use of jp.ossc.nimbus.service.publish.MessageException in project nimbus by nimbus-org.
the class SharedQueueService method onRequestMessage.
public Message onRequestMessage(Object sourceId, int sequence, Message message, String responseSubject, String responseKey) {
SharedContextEvent event = null;
try {
event = (SharedContextEvent) message.getObject();
} catch (MessageException e) {
e.printStackTrace();
message.recycle();
return null;
}
Message result = null;
switch(event.type) {
case SharedQueueEvent.EVENT_LOCK_FIRST:
message.recycle();
result = onLockFirst(event, sourceId, sequence, responseSubject, responseKey);
break;
default:
result = super.onRequestMessage(sourceId, sequence, message, responseSubject, responseKey);
}
return result;
}
use of jp.ossc.nimbus.service.publish.MessageException in project nimbus by nimbus-org.
the class MessageImpl method getObject.
public Object getObject() throws MessageException {
if (object == null && serializedBytes != null) {
synchronized (serializedBytes) {
if (object != null) {
return object;
}
try {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(serializedBytes));
object = ois.readObject();
} catch (IOException e) {
throw new MessageException(e);
} catch (ClassNotFoundException e) {
throw new MessageException(e);
}
}
}
return object;
}
Aggregations