Search in sources :

Example 1 with SynchronizeMonitor

use of jp.ossc.nimbus.util.SynchronizeMonitor in project nimbus by nimbus-org.

the class DefaultBeanFlowInvokerFactoryService method stopService.

/**
 * サービスの停止処理を行う。<p>
 *
 * @exception Exception サービスの停止処理に失敗した場合
 */
public void stopService() throws Exception {
    if (isCollectJournalMetrics) {
        System.out.println(displayJournalMetricsInfo());
        resetJournalMetrics();
    }
    if (asynchInvokeQueueHandlerContainer != null) {
        asynchInvokeQueueHandlerContainer.release();
        asynchInvokeQueueHandlerContainer = null;
    }
    if (defaultRmFactory != null) {
        defaultRmFactory.stop();
        defaultRmFactory.destroy();
        defaultRmFactory = null;
    }
    mRmFactory = null;
    mFlowConfigMap.clear();
    mExecFlowList.clear();
    mAliasFlowConfigMap.clear();
    for (Iterator iterator = mSuspendKeyMap.values().iterator(); iterator.hasNext(); ) {
        SynchronizeMonitor obj = (SynchronizeMonitor) iterator.next();
        obj.notifyAllMonitor();
    }
    mSuspendKeyMap.clear();
    mIgnoreKeyMap.clear();
}
Also used : SynchronizeMonitor(jp.ossc.nimbus.util.SynchronizeMonitor)

Example 2 with SynchronizeMonitor

use of jp.ossc.nimbus.util.SynchronizeMonitor in project nimbus by nimbus-org.

the class DefaultBeanFlowInvokerFactoryService method resume.

// DefaultBeanFlowInvokerFactoryServiceMBeanのJavaDoc
public void resume(String key) {
    synchronized (mSuspendKeyMap) {
        SynchronizeMonitor ret = (SynchronizeMonitor) mSuspendKeyMap.get(key);
        if (ret != null) {
            ret.notifyAllMonitor();
            mSuspendKeyMap.remove(key);
        }
    }
    synchronized (mExecFlowList) {
        for (int i = 0; i < mExecFlowList.size(); i++) {
            BeanFlowMonitor monitor = (BeanFlowMonitor) mExecFlowList.get(i);
            if (key.equals(monitor.getFlowName())) {
                monitor.resume();
            }
        }
    }
}
Also used : SynchronizeMonitor(jp.ossc.nimbus.util.SynchronizeMonitor)

Example 3 with SynchronizeMonitor

use of jp.ossc.nimbus.util.SynchronizeMonitor in project nimbus by nimbus-org.

the class HttpResponseCacheInterceptorService method getHttpResponseCache.

private HttpResponseCache getHttpResponseCache(String path) throws InterruptedException {
    HttpResponseCache responseCache = (HttpResponseCache) cacheMap.get(path);
    if (responseCache != null) {
        return responseCache;
    }
    SynchronizeMonitor waitMonitor = (SynchronizeMonitor) lockMap.get(path);
    if (waitMonitor == null) {
        responseCache = (HttpResponseCache) cacheMap.get(path);
        if (responseCache == null) {
            waitMonitor = (SynchronizeMonitor) lockMap.putIfAbsent(path, new WaitSynchronizeMonitor());
        } else {
            return responseCache;
        }
    }
    if (waitMonitor == null) {
        return null;
    }
    waitMonitor.initMonitor();
    if (waitTimeout > 0) {
        if (waitMonitor.waitMonitor(waitTimeout)) {
            return getHttpResponseCache(path);
        } else {
            return null;
        }
    } else {
        waitMonitor.waitMonitor();
        return getHttpResponseCache(path);
    }
}
Also used : SynchronizeMonitor(jp.ossc.nimbus.util.SynchronizeMonitor) WaitSynchronizeMonitor(jp.ossc.nimbus.util.WaitSynchronizeMonitor) WaitSynchronizeMonitor(jp.ossc.nimbus.util.WaitSynchronizeMonitor)

Example 4 with SynchronizeMonitor

use of jp.ossc.nimbus.util.SynchronizeMonitor in project nimbus by nimbus-org.

the class HttpResponseCacheInterceptorService method invokeFilter.

/**
 * リクエストされたURIのキャッシュが存在する場合は、レスポンスを復元してレスポンスする。そうでない場合は、レスポンスをラップして、次のインターセプタを呼び出し、レスポンスをURI単位にキャッシュする。<p>
 * サービスが開始されていない場合は、何もせずに次のインターセプタを呼び出す。<br>
 *
 * @param context 呼び出しのコンテキスト情報
 * @param chain 次のインターセプタを呼び出すためのチェーン
 * @return 呼び出し結果の戻り値
 * @exception Throwable 呼び出し先で例外が発生した場合、またはこのインターセプタで任意の例外が発生した場合。但し、本来呼び出される処理がthrowしないRuntimeException以外の例外をthrowしても、呼び出し元には伝播されない。
 */
public Object invokeFilter(ServletFilterInvocationContext context, InterceptorChain chain) throws Throwable {
    if (getState() == STARTED) {
        final HttpServletRequest request = (HttpServletRequest) context.getServletRequest();
        final StringBuilder pathBuf = new StringBuilder();
        String path = request.getContextPath();
        if (path != null) {
            pathBuf.append(path);
        }
        path = request.getServletPath();
        if (path != null) {
            pathBuf.append(path);
        }
        path = request.getPathInfo();
        if (path != null) {
            pathBuf.append(path);
        }
        if (isContainsQuery) {
            path = request.getQueryString();
            if (path != null) {
                pathBuf.append('?').append(path);
            }
        }
        path = pathBuf.toString();
        HttpResponseCache responseCache = null;
        try {
            responseCache = getHttpResponseCache(path);
        } catch (InterruptedException e) {
        }
        if (responseCache != null) {
            responseCache.applyResponse(context.getServletResponse());
            return null;
        }
        SynchronizeMonitor lockMonitor = (SynchronizeMonitor) lockMap.get(path);
        HttpResponseCacheHttpServletResponseWrapper responseWrapper = new HttpResponseCacheHttpServletResponseWrapper((HttpServletResponse) context.getServletResponse());
        try {
            context.setServletResponse(responseWrapper);
            Object ret = chain.invokeNext(context);
            ServletResponse response = context.getServletResponse();
            if (response instanceof HttpResponseCacheHttpServletResponseWrapper) {
                HttpResponseCacheHttpServletResponseWrapper rw = (HttpResponseCacheHttpServletResponseWrapper) response;
                HttpResponseCache cache = rw.toHttpResponseCache();
                if (responseStatusForCache == cache.status) {
                    cacheMap.put(path, cache);
                }
                rw.flushBuffer();
                context.setServletResponse(rw.getResponse());
            } else {
                while ((response instanceof ServletResponseWrapper) && !(response instanceof HttpResponseCacheHttpServletResponseWrapper)) {
                    response = ((ServletResponseWrapper) response).getResponse();
                }
                if (response instanceof HttpResponseCacheHttpServletResponseWrapper) {
                    HttpResponseCacheHttpServletResponseWrapper rw = (HttpResponseCacheHttpServletResponseWrapper) response;
                    HttpResponseCache cache = rw.toHttpResponseCache();
                    if (responseStatusForCache == cache.status) {
                        cacheMap.put(path, cache);
                    }
                    rw.flushBuffer();
                }
            }
            return ret;
        } finally {
            lockMap.remove(path);
            if (lockMonitor != null) {
                lockMonitor.notifyAllMonitor();
            }
            context.setServletResponse(responseWrapper.getResponse());
        }
    } else {
        return chain.invokeNext(context);
    }
}
Also used : SynchronizeMonitor(jp.ossc.nimbus.util.SynchronizeMonitor) WaitSynchronizeMonitor(jp.ossc.nimbus.util.WaitSynchronizeMonitor)

Example 5 with SynchronizeMonitor

use of jp.ossc.nimbus.util.SynchronizeMonitor in project nimbus by nimbus-org.

the class ClientConnectionImpl method send.

private void send(ClientMessage message) throws IOException, MessageSendException {
    SynchronizeMonitor responseMonitor = null;
    Short reqId = null;
    boolean isBye = message.getMessageType() == ClientMessage.MESSAGE_BYE;
    try {
        if (!isBye && isAcknowledge) {
            if (requestMonitorMap == null) {
                requestMonitorMap = new HashMap();
            }
            synchronized (requestMonitorMap) {
                message.setRequestId(requestId++);
                responseMonitor = new WaitSynchronizeMonitor();
                responseMonitor.initMonitor();
                reqId = new Short(message.getRequestId());
                requestMonitorMap.put(reqId, responseMonitor);
            }
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        if (externalizer == null) {
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(message);
            oos.flush();
        } else {
            externalizer.writeExternal(message, baos);
        }
        byte[] bytes = baos.toByteArray();
        synchronized (this) {
            if (socket == null) {
                throw new MessageSendException("No connected.");
            }
            DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
            dos.writeInt(bytes.length);
            dos.write(bytes);
            dos.flush();
        }
        if (!isBye && isAcknowledge) {
            try {
                if (!responseMonitor.waitMonitor(responseTimeout)) {
                    throw new MessageSendException("Acknowledge is timed out.");
                }
            } catch (InterruptedException e) {
                throw new MessageSendException("Acknowledge is interrupted.", e);
            }
        }
    } finally {
        if (!isBye && isAcknowledge) {
            synchronized (requestMonitorMap) {
                requestMonitorMap.remove(reqId);
            }
        }
    }
}
Also used : WaitSynchronizeMonitor(jp.ossc.nimbus.util.WaitSynchronizeMonitor) SynchronizeMonitor(jp.ossc.nimbus.util.SynchronizeMonitor) MessageSendException(jp.ossc.nimbus.service.publish.MessageSendException) HashMap(java.util.HashMap) DataOutputStream(java.io.DataOutputStream) WaitSynchronizeMonitor(jp.ossc.nimbus.util.WaitSynchronizeMonitor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

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