Search in sources :

Example 6 with BeanFlowInvoker

use of jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker in project nimbus by nimbus-org.

the class BeanFlowJournalMetricsInterceptorService method invoke.

/**
 * メトリクスを取得して、次のインターセプタを呼び出す。<p>
 * サービスが開始されていない場合や{@link #setEnabled(boolean) setEnabled(false)}に設定されている場合は、メトリクス取得を行わずに次のインターセプタを呼び出す。<br>
 *
 * @param context 呼び出しのコンテキスト情報
 * @param chain 次のインターセプタを呼び出すためのチェーン
 * @return 呼び出し結果の戻り値
 * @exception Throwable 呼び出し先で例外が発生した場合、またはこのインターセプタで任意の例外が発生した場合。但し、本来呼び出される処理がthrowしないRuntimeException以外の例外をthrowしても、呼び出し元には伝播されない。
 */
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
    long start = 0;
    boolean isError = false;
    boolean isException = false;
    try {
        return chain.invokeNext(context);
    } catch (Exception e) {
        isException = true;
        throw e;
    } catch (Error err) {
        isError = true;
        throw err;
    } finally {
        if (getState() == STARTED && isEnabled() && journal != null) {
            String journalStr = journal.getCurrentJournalString(editorFinder);
            if (performanceRecorder != null) {
                performanceRecorder.recordValue(System.currentTimeMillis(), journalStr == null ? 0 : journalStr.length());
            }
            Object target = context.getTargetObject();
            if (target instanceof BeanFlowInvoker) {
                BeanFlowInvoker invoker = (BeanFlowInvoker) target;
                String flow = invoker.getFlowName();
                MetricsInfo metricsInfo = null;
                metricsInfo = (MetricsInfo) metricsInfos.get(flow);
                if (metricsInfo == null) {
                    metricsInfo = new MetricsInfo(flow, isCalculateOnlyNormal);
                    MetricsInfo old = (MetricsInfo) metricsInfos.putIfAbsent(flow, metricsInfo);
                    if (old != null) {
                        metricsInfo = old;
                    }
                }
                metricsInfo.calculate(journalStr == null ? 0 : journalStr.length(), isException, isError);
            }
        }
    }
}
Also used : BeanFlowInvoker(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker)

Example 7 with BeanFlowInvoker

use of jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker in project nimbus by nimbus-org.

the class DefaultBeanFlowInvokerFactoryServiceTest method testCreateFlow_DI.

/**
 * DefaultBeanFlowInvokerFactoryService#createFlow()を検査する。
 * DI形式によるサービス定義を読み込む。
 */
public void testCreateFlow_DI() {
    try {
        ServiceManagerFactory.loadManager(SERVICE_DEFINITION_FILE_PATH);
        BeanFlowInvokerFactory beanFlowInvokerFactory = (BeanFlowInvokerFactory) ServiceManagerFactory.getServiceObject(SERVICE_MANAGER_NAME, SERVICE_NAME_DI);
        BeanFlowInvoker beanFlowInvoker = beanFlowInvokerFactory.createFlow(BEANFLOW_NAME);
        beanFlowInvoker.invokeFlow(null);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    } finally {
        ServiceManagerFactory.unloadManager(SERVICE_DEFINITION_FILE_PATH);
    }
}
Also used : BeanFlowInvokerFactory(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvokerFactory) BeanFlowInvoker(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker)

Example 8 with BeanFlowInvoker

use of jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker in project nimbus by nimbus-org.

the class BeanFlowMetricsInterceptorService method invoke.

/**
 * メトリクスを取得して、次のインターセプタを呼び出す。<p>
 * サービスが開始されていない場合や{@link #setEnabled(boolean) setEnabled(false)}に設定されている場合は、メトリクス取得を行わずに次のインターセプタを呼び出す。<br>
 *
 * @param context 呼び出しのコンテキスト情報
 * @param chain 次のインターセプタを呼び出すためのチェーン
 * @return 呼び出し結果の戻り値
 * @exception Throwable 呼び出し先で例外が発生した場合、またはこのインターセプタで任意の例外が発生した場合。但し、本来呼び出される処理がthrowしないRuntimeException以外の例外をthrowしても、呼び出し元には伝播されない。
 */
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
    long start = 0;
    boolean isError = false;
    boolean isException = false;
    if (getState() == STARTED && isEnabled()) {
        start = System.currentTimeMillis();
    }
    try {
        return chain.invokeNext(context);
    } catch (Exception e) {
        isException = true;
        throw e;
    } catch (Error err) {
        isError = true;
        throw err;
    } finally {
        if (getState() == STARTED && isEnabled()) {
            long end = System.currentTimeMillis();
            if (performanceRecorder != null) {
                performanceRecorder.record(start, end);
            }
            Object target = context.getTargetObject();
            if (target instanceof BeanFlowInvoker) {
                BeanFlowInvoker invoker = (BeanFlowInvoker) target;
                String flow = invoker.getFlowName();
                MetricsInfo metricsInfo = (MetricsInfo) metricsInfos.get(flow);
                if (metricsInfo == null) {
                    metricsInfo = new MetricsInfo(flow, isCalculateOnlyNormal);
                    MetricsInfo old = (MetricsInfo) metricsInfos.putIfAbsent(flow, metricsInfo);
                    if (old != null) {
                        metricsInfo = old;
                    }
                }
                metricsInfo.calculate(end - start, isException, isError);
            }
        }
    }
}
Also used : BeanFlowInvoker(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker)

Example 9 with BeanFlowInvoker

use of jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker in project nimbus by nimbus-org.

the class ConsoleBeanFlowCoverageRepoterService method report.

private void report(PrintWriter pw) throws IOException {
    final Map resourceMap = new TreeMap();
    final Iterator flowNames = beanFlowInvokerFactory.getBeanFlowKeySet().iterator();
    while (flowNames.hasNext()) {
        BeanFlowInvoker invoker = beanFlowInvokerFactory.createFlow((String) flowNames.next());
        Map coverageMap = (Map) resourceMap.get(invoker.getResourcePath());
        if (coverageMap == null) {
            coverageMap = new TreeMap();
            resourceMap.put(invoker.getResourcePath(), coverageMap);
        }
        coverageMap.put(invoker.getFlowName(), invoker.getBeanFlowCoverage());
        invoker.end();
    }
    final Iterator resources = resourceMap.entrySet().iterator();
    while (resources.hasNext()) {
        Map.Entry resource = (Map.Entry) resources.next();
        pw.println("///////////////////////////////////////////////////////");
        pw.println("fileName:" + resource.getKey());
        Map coverageMap = (Map) resource.getValue();
        final Iterator coverages = coverageMap.entrySet().iterator();
        while (coverages.hasNext()) {
            Map.Entry flowCoverage = (Map.Entry) coverages.next();
            pw.println("#######################################################");
            pw.println("flowName:" + flowCoverage.getKey());
            BeanFlowCoverage coverage = (BeanFlowCoverage) flowCoverage.getValue();
            pw.println("coverage:" + coverage.getCoveredElementCount() + "/" + coverage.getElementCount() + "(" + (int) ((double) coverage.getCoveredElementCount() / (double) coverage.getElementCount() * 100.0d) + "%)");
            if (isDetail) {
                pw.println(coverage);
            }
        }
    }
    pw.flush();
}
Also used : BeanFlowInvoker(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker)

Example 10 with BeanFlowInvoker

use of jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker in project nimbus by nimbus-org.

the class WeakReferenceCodeMasterService method initMasterHash.

/**
 * マスタ管理テーブルを初期化する
 * @throws ServiceException
 */
private void initMasterHash() throws ServiceException {
    for (int cnt = 0; cnt < mMasterNames.length; cnt++) {
        final String bfname = mMasterNames[cnt];
        final BeanFlowInvoker invoker = mBFInvokerFactory.createFlow(bfname);
        if (invoker == null) {
            // BeanFlowInvokerFactoryは無効キーでNULLを返します
            throw new ServiceException("WeakReferenceCodeMasterService001", "Cannot specify Invoker with key ->" + bfname);
        }
        // 時系列管理マスタテーブルを作成
        TimeManageMaster tmgr = new TimeManageMaster();
        tmgr.setMasterName(bfname);
        // マスタに登録
        this.mMaster.put(bfname, tmgr);
        Object outMaster = null;
        try {
            // BeanFlowを実行する
            outMaster = invoker.invokeFlow(null);
        } catch (Exception e) {
            throw new ServiceException("WeakReferenceCodeMasterService002", "Exception occured in Invoker with key ->" + bfname, e);
        }
        if (outMaster != null) {
            // コードマスタを登録する(内部で弱参照に変換される)
            tmgr.addMaster(new Date(), outMaster);
        }
    }
}
Also used : ServiceException(jp.ossc.nimbus.lang.ServiceException) BeanFlowInvoker(jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker) ServiceException(jp.ossc.nimbus.lang.ServiceException) Date(java.util.Date)

Aggregations

BeanFlowInvoker (jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvoker)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 NoSuchPropertyException (jp.ossc.nimbus.beans.NoSuchPropertyException)3 ServiceException (jp.ossc.nimbus.lang.ServiceException)3 BeanFlowInvokerFactory (jp.ossc.nimbus.service.beancontrol.interfaces.BeanFlowInvokerFactory)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 Date (java.util.Date)2 DeploymentException (jp.ossc.nimbus.core.DeploymentException)2 ConvertException (jp.ossc.nimbus.util.converter.ConvertException)2 SAXException (org.xml.sax.SAXException)2 SAXParseException (org.xml.sax.SAXParseException)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ServletRequest (javax.servlet.ServletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1