Search in sources :

Example 6 with SynchronizeMonitor

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);
    }
}
Also used : SocketException(java.net.SocketException) MessageCommunicateException(jp.ossc.nimbus.service.publish.MessageCommunicateException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) WaitSynchronizeMonitor(jp.ossc.nimbus.util.WaitSynchronizeMonitor) SynchronizeMonitor(jp.ossc.nimbus.util.SynchronizeMonitor) SocketTimeoutException(java.net.SocketTimeoutException) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageException(jp.ossc.nimbus.service.publish.MessageException) EOFException(java.io.EOFException)

Example 7 with SynchronizeMonitor

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);
}
Also used : SynchronizeMonitor(jp.ossc.nimbus.util.SynchronizeMonitor)

Aggregations

SynchronizeMonitor (jp.ossc.nimbus.util.SynchronizeMonitor)7 WaitSynchronizeMonitor (jp.ossc.nimbus.util.WaitSynchronizeMonitor)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 HashMap (java.util.HashMap)1 MessageCommunicateException (jp.ossc.nimbus.service.publish.MessageCommunicateException)1 MessageException (jp.ossc.nimbus.service.publish.MessageException)1 MessageSendException (jp.ossc.nimbus.service.publish.MessageSendException)1