use of jp.ossc.nimbus.util.SynchronizeMonitor 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.util.SynchronizeMonitor in project nimbus by nimbus-org.
the class DefaultBeanFlowInvokerFactoryService method createFlow.
public BeanFlowInvoker createFlow(String key, String caller, boolean isOverwride) {
if (mRefreshedTime != null && mRefreshPlanTime.after(mRefreshedTime)) {
if (mRefreshPlanTime.before(new Date())) {
reload();
}
}
BeanFlowInvoker blFlowConfig = createFlowInternal(key, caller, isOverwride);
key = blFlowConfig.getFlowName();
// 無効メッセ-ジの場合
Object ignore = mIgnoreKeyMap.get(key);
if (ignore != null) {
return null;
}
// サスペンドメッセージの場合
SynchronizeMonitor suspend = (SynchronizeMonitor) mSuspendKeyMap.get(key);
if (suspend != null) {
try {
suspend.initMonitor();
suspend.waitMonitor();
} catch (InterruptedException e) {
}
}
if (interceptorChainFactory == null) {
return blFlowConfig;
}
final InterceptorChain chain = interceptorChainFactory.getInterceptorChain(key);
if (chain == null) {
return blFlowConfig;
}
return new WrappedBeanFlowInvoker(blFlowConfig, chain);
}
Aggregations