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;
}
use of jp.ossc.nimbus.service.publish.MessageException in project nimbus by nimbus-org.
the class ClientConnectionImpl method receive.
private Message receive() throws MessageCommunicateException {
if (socket == null) {
return null;
}
int length = 0;
try {
DataInputStream dis = new DataInputStream(socket.getInputStream());
length = dis.readInt();
if (length <= 0) {
return null;
}
if (receiveBytes == null || receiveBytes.length < length) {
receiveBytes = new byte[length];
}
dis.readFully(receiveBytes, 0, length);
ByteArrayInputStream bais = new ByteArrayInputStream(receiveBytes, 0, length);
MessageImpl message = MessageImpl.read(bais, externalizer, messageBuffer);
message.setClientConnection(this);
if (message != null) {
final short messageType = message.getMessageType();
switch(messageType) {
case MessageImpl.MESSAGE_TYPE_SERVER_CLOSE:
if (serverCloseMessageId != null) {
ServiceManagerFactory.getLogger().write(serverCloseMessageId, new Object[] { this });
}
isServerClosed = true;
close();
return null;
case MessageImpl.MESSAGE_TYPE_SERVER_RESPONSE:
if (isAcknowledge && requestMonitorMap != null) {
synchronized (requestMonitorMap) {
Object reqId = null;
try {
reqId = message.getObject();
} catch (MessageException e) {
return null;
}
SynchronizeMonitor responseMonitor = (SynchronizeMonitor) requestMonitorMap.get(reqId);
if (responseMonitor != null) {
responseMonitor.notifyAllMonitor();
}
}
}
return null;
case MessageImpl.MESSAGE_TYPE_APPLICATION:
default:
break;
}
}
return message;
} catch (SocketTimeoutException e) {
return null;
} catch (SocketException e) {
if (isClosing || !isConnected) {
return null;
}
if (reconnectCount > 0) {
if (receiveWarnMessageId != null) {
ServiceManagerFactory.getLogger().write(receiveWarnMessageId, new Object[] { this }, e);
}
reconnect();
return receive();
} else {
close();
return null;
}
} catch (EOFException e) {
if (isClosing || !isConnected) {
return null;
}
if (reconnectCount > 0) {
if (receiveWarnMessageId != null) {
ServiceManagerFactory.getLogger().write(receiveWarnMessageId, new Object[] { this }, e);
}
reconnect();
return receive();
} else if (length == 0) {
close();
return null;
} else {
throw new MessageCommunicateException("length=" + length + ", receiveBytes=" + (receiveBytes == null ? "null" : Integer.toString(receiveBytes.length)), e);
}
} catch (IOException e) {
if (isClosing || !isConnected) {
return null;
}
throw new MessageCommunicateException(e);
} catch (ClassNotFoundException e) {
if (isClosing || !isConnected) {
return null;
}
throw new MessageCommunicateException(e);
}
}
use of jp.ossc.nimbus.service.publish.MessageException in project nimbus by nimbus-org.
the class DistributedSharedContextService method load.
public synchronized void load(long timeout) throws Exception {
if (isMain()) {
if (contextStore != null) {
contextStore.load(this);
} 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_LOAD));
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 getServerMemberIdSet.
public Set getServerMemberIdSet() {
if (serverConnection == null) {
return new HashSet();
}
try {
Message message = serverConnection.createMessage(subject, null);
Set result = serverConnection.getReceiveClientIds(message);
if (!isClient) {
result.add(getId());
}
return result;
} catch (MessageException e) {
return new HashSet();
}
}
use of jp.ossc.nimbus.service.publish.MessageException in project nimbus by nimbus-org.
the class DistributedSharedContextService method loadKey.
public synchronized void loadKey(long timeout) throws Exception {
if (isMain()) {
if (contextStore != null) {
contextStore.loadKey(this);
} 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_LOAD_KEY));
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);
}
}
}
Aggregations