Search in sources :

Example 1 with ServerConnectionFactory

use of jp.ossc.nimbus.service.publish.ServerConnectionFactory in project nimbus by nimbus-org.

the class DistributedSharedContextService method startService.

/**
 * サービスの開始処理を行う。<p>
 *
 * @exception Exception サービスの開始処理に失敗した場合
 */
public void startService() throws Exception {
    if (sharedContextKeyDistributorServiceName == null) {
        MD5HashSharedContextKeyDistributorService defaultKeyDistributor = new MD5HashSharedContextKeyDistributorService();
        defaultKeyDistributor.create();
        defaultKeyDistributor.start();
        keyDistributor = defaultKeyDistributor;
    } else {
        keyDistributor = (SharedContextKeyDistributor) ServiceManagerFactory.getServiceObject(sharedContextKeyDistributorServiceName);
    }
    if (contextStoreServiceName != null) {
        contextStore = (ContextStore) ServiceManagerFactory.getServiceObject(contextStoreServiceName);
    }
    if (requestConnectionFactoryServiceName == null) {
        throw new IllegalArgumentException("RequestConnectionFactoryServiceName must be specified.");
    }
    if (sharedContextUpdateListenerServiceNames != null) {
        for (int i = 0; i < sharedContextUpdateListenerServiceNames.length; i++) {
            addSharedContextUpdateListener((SharedContextUpdateListener) ServiceManagerFactory.getServiceObject(sharedContextUpdateListenerServiceNames[i]));
        }
    }
    if (parallelRequestThreadSize > 0) {
        parallelRequestQueueHandlerContainer = new QueueHandlerContainerService();
        parallelRequestQueueHandlerContainer.create();
        parallelRequestQueueHandlerContainer.setQueueHandlerSize(parallelRequestThreadSize);
        if (parallelRequestQueueServiceName == null) {
            DefaultQueueService parallelRequestQueue = new DefaultQueueService();
            parallelRequestQueue.create();
            parallelRequestQueue.start();
            parallelRequestQueueHandlerContainer.setQueueService(parallelRequestQueue);
        } else {
            parallelRequestQueueHandlerContainer.setQueueServiceName(parallelRequestQueueServiceName);
        }
        parallelRequestQueueHandlerContainer.setQueueHandler(new ParallelRequestQueueHandler());
        parallelRequestQueueHandlerContainer.start();
    }
    ServerConnectionFactory factory = (ServerConnectionFactory) ServiceManagerFactory.getServiceObject(requestConnectionFactoryServiceName);
    serverConnection = (RequestServerConnection) factory.getServerConnection();
    messageReceiver = (MessageReceiver) ServiceManagerFactory.getServiceObject(requestConnectionFactoryServiceName);
    clientSubject = subject + CLIENT_SUBJECT_SUFFIX;
    targetMessage = serverConnection.createMessage(subject, null);
    if (clusterServiceName == null) {
        throw new IllegalArgumentException("ClusterServiceName must be specified.");
    }
    cluster = (ClusterService) ServiceManagerFactory.getServiceObject(clusterServiceName);
    if (interpreterServiceName != null) {
        interpreter = (Interpreter) ServiceManagerFactory.getServiceObject(interpreterServiceName);
    }
    sharedContextArray = new SharedContextService[distributedSize];
    for (int i = 0; i < sharedContextArray.length; i++) {
        sharedContextArray[i] = isMainDistributed ? new ForDistributedSharedContextService(i) : new SharedContextService();
        if (isManagedDataNode) {
            sharedContextArray[i].setServiceManagerName(getServiceManagerName());
        }
        sharedContextArray[i].setServiceName(getServiceName() + '$' + i);
        sharedContextArray[i].create();
        sharedContextArray[i].setRequestConnectionFactoryServiceName(requestConnectionFactoryServiceName);
        sharedContextArray[i].setClusterServiceName(clusterServiceName);
        if (clientCacheMapServiceName != null) {
            sharedContextArray[i].setClientCacheMap((CacheMap) ServiceManagerFactory.getServiceObject(clientCacheMapServiceName));
        }
        if (serverCacheMapServiceName != null) {
            sharedContextArray[i].setServerCacheMap((CacheMap) ServiceManagerFactory.getServiceObject(serverCacheMapServiceName));
        }
        if (contextStoreServiceName != null) {
            sharedContextArray[i].setContextStoreServiceName(contextStoreServiceName);
        }
        if (interpreterServiceName != null) {
            sharedContextArray[i].setInterpreterServiceName(interpreterServiceName);
        }
        if (interpretContextVariableName != null) {
            sharedContextArray[i].setInterpretContextVariableName(interpretContextVariableName);
        }
        if (executeQueueServiceName != null) {
            sharedContextArray[i].setExecuteQueueServiceName(executeQueueServiceName);
        }
        if (sharedContextTransactionManagerServiceName != null) {
            sharedContextArray[i].setSharedContextTransactionManagerServiceName(sharedContextTransactionManagerServiceName);
        }
        sharedContextArray[i].setExecuteThreadSize(executeThreadSize);
        sharedContextArray[i].setSubject(subject + "$" + i);
        sharedContextArray[i].setClient(isClient || isRehashEnabled ? true : false);
        sharedContextArray[i].setSynchronizeTimeout(synchronizeTimeout);
        sharedContextArray[i].setDefaultTimeout(defaultTimeout);
        sharedContextArray[i].setSynchronizeOnStart(false);
        sharedContextArray[i].setSaveOnlyMain(true);
        sharedContextArray[i].setClearBeforeSave(false);
        sharedContextArray[i].setLoadOnStart(false);
        sharedContextArray[i].setLoadKeyOnStart(false);
        sharedContextArray[i].setSaveOnStop(false);
        sharedContextArray[i].setWaitConnectAllOnStart(isWaitConnectAllOnStart());
        sharedContextArray[i].setWaitConnectTimeout(waitConnectTimeout);
        if (updateListeners != null) {
            for (int j = 0; j < updateListeners.size(); j++) {
                sharedContextArray[i].addSharedContextUpdateListener((SharedContextUpdateListener) updateListeners.get(j));
            }
        }
        Iterator entries = indexMap.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            if (entry.getValue() instanceof BeanTableIndexKeyFactory) {
                sharedContextArray[i].setIndex((String) entry.getKey(), (BeanTableIndexKeyFactory) entry.getValue());
            } else {
                sharedContextArray[i].setIndex((String) entry.getKey(), (String[]) entry.getValue());
            }
        }
        sharedContextArray[i].start();
    }
    distributeInfo = new DistributeInfo(getId(), distributedSize);
    serverConnection.addServerConnectionListener(this);
    messageReceiver.addSubject(this, isClient ? clientSubject : subject);
    if (!isClient) {
        rehash();
    }
    for (int i = 0; i < sharedContextArray.length; i++) {
        if (sharedContextArray[i].isClient() && sharedContextArray[i].indexManager != null && sharedContextArray[i].indexManager.hasIndex()) {
            sharedContextArray[i].waitConnectMain();
            sharedContextArray[i].synchronize();
        }
    }
    if (isMain()) {
        if (isLoadKeyOnStart) {
            loadKey();
        } else if (isLoadOnStart) {
            load();
        }
    }
}
Also used : QueueHandlerContainerService(jp.ossc.nimbus.service.queue.QueueHandlerContainerService) DefaultQueueService(jp.ossc.nimbus.service.queue.DefaultQueueService) ServerConnectionFactory(jp.ossc.nimbus.service.publish.ServerConnectionFactory) Iterator(java.util.Iterator) CacheMap(jp.ossc.nimbus.service.cache.CacheMap) HashMap(java.util.HashMap) Map(java.util.Map) BeanTableIndexKeyFactory(jp.ossc.nimbus.beans.BeanTableIndexKeyFactory)

Example 2 with ServerConnectionFactory

use of jp.ossc.nimbus.service.publish.ServerConnectionFactory in project nimbus by nimbus-org.

the class CodeMasterNotifyActionService method execute.

/**
 * {@link jp.ossc.nimbus.service.codemaster.CodeMasterFinder CodeMasterFinder}に更新通知を送信する。<p>
 * リソースのフォーマットは、以下。<br>
 * <pre>
 * masterName
 * dateId
 * dataId
 * dataAndDataBindScript
 * </pre>
 * masterNameは、更新通知の対象となるマスタ名を指定する。<br>
 * dateIdは、{@link CodeMasterNotifyBean}に設定する更新日時のDateオブジェクトを設定するもので、同一テストケース中に、このTestActionより前に、更新日時のDateオブジェクトを戻すテストアクションが存在する場合は、そのアクションIDを指定する。また、同一シナリオ中に、このTestActionより前に、更新日時のDateオブジェクトを戻すテストアクションが存在する場合は、テストケースIDとアクションIDをカンマ区切りで指定する。空行を指定した場合は、更新日時のDateオブジェクトをTestActionの結果から取得しない。<br>
 * dataIdは、{@link CodeMasterNotifyBean}に設定する更新引数のオブジェクトを設定するもので、同一テストケース中に、このTestActionより前に、更新引数のオブジェクトを戻すテストアクションが存在する場合は、そのアクションIDを指定する。また、同一シナリオ中に、このTestActionより前に、更新引数のオブジェクトを戻すテストアクションが存在する場合は、テストケースIDとアクションIDをカンマ区切りで指定する。空行を指定した場合は、更新引数のオブジェクトをTestActionの結果から取得しない。<br>
 * dataAndDataBindScriptは、{@link CodeMasterNotifyBean}に設定する更新日時と更新引数を設定するスクリプトを指定する。スクリプトは、{@link Interpreter#evaluate(String,Map)}で評価され、引数の変数マップには、"context"で{@link TestContext}、"notifyBean"で{@link CodeMasterNotifyBean}が渡される。<br>
 *
 * @param context コンテキスト
 * @param actionId アクションID
 * @param resource リソース
 * @return 送信に使用した{@link CodeMasterNotifyBean}
 */
public Object execute(TestContext context, String actionId, Reader resource) throws Exception {
    BufferedReader br = new BufferedReader(resource);
    CodeMasterNotifyBean notifyBean = new CodeMasterNotifyBean();
    TopicSession session = null;
    if (jndiFinder != null && jmsTopicSessionFactory != null) {
        notifyBean.setJndiFinder(jndiFinder);
        session = (TopicSession) jmsTopicSessionFactory.getSession();
        notifyBean.setResource(session);
        notifyBean.setTopicName(topicName);
    } else {
        ServerConnectionFactory scf = serverConnectionFactory;
        if (serverConnectionFactory == null && serverConnectionFactoryServiceName != null) {
            scf = (ServerConnectionFactory) ServiceManagerFactory.getServiceObject(serverConnectionFactoryServiceName);
        }
        notifyBean.setServerConnection(scf.getServerConnection());
        notifyBean.setSubject(subject);
    }
    try {
        String masterName = br.readLine();
        if (masterName == null || masterName.length() == 0) {
            throw new Exception("Unexpected EOF on masterName");
        }
        notifyBean.setMasterFlowKey(masterName);
        final String dateId = br.readLine();
        if (dateId != null && dateId.length() != 0) {
            Object actionResult = null;
            if (dateId.indexOf(",") == -1) {
                actionResult = context.getTestActionResult(dateId);
            } else {
                String[] ids = dateId.split(",");
                if (ids.length != 2) {
                    throw new Exception("Illegal dateId format. id=" + dateId);
                }
                actionResult = context.getTestActionResult(ids[0], ids[1]);
            }
            if (actionResult == null) {
                throw new Exception("TestActionResult not found. id=" + dateId);
            }
            if (!(actionResult instanceof Date)) {
                throw new Exception("TestActionResult is not instance of Date. type=" + actionResult.getClass());
            }
            notifyBean.setDate((Date) actionResult);
        }
        final String dataId = br.readLine();
        if (dataId != null && dataId.length() != 0) {
            Object actionResult = null;
            if (dataId.indexOf(",") == -1) {
                actionResult = context.getTestActionResult(dataId);
            } else {
                String[] ids = dataId.split(",");
                if (ids.length != 2) {
                    throw new Exception("Illegal dataId format. id=" + dataId);
                }
                actionResult = context.getTestActionResult(ids[0], ids[1]);
            }
            if (actionResult == null) {
                throw new Exception("TestActionResult not found. id=" + dataId);
            }
            notifyBean.setData(actionResult);
        }
        String dataAndDataBindScript = null;
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try {
            String line = null;
            while ((line = br.readLine()) != null) {
                pw.println(line);
            }
            pw.flush();
            dataAndDataBindScript = sw.toString();
            if (dataAndDataBindScript.length() == 0) {
                dataAndDataBindScript = null;
            }
        } finally {
            sw.close();
            pw.close();
        }
        if (dataAndDataBindScript != null) {
            if (interpreter == null) {
                throw new UnsupportedOperationException("Interpreter is null.");
            }
            final Map params = new HashMap();
            params.put("context", context);
            params.put("notifyBean", notifyBean);
            interpreter.evaluate(dataAndDataBindScript, params);
        }
        notifyBean.addMessageAndSend();
    } finally {
        br.close();
        br = null;
        if (session != null) {
            session.close();
        }
    }
    return notifyBean;
}
Also used : TopicSession(javax.jms.TopicSession) HashMap(java.util.HashMap) Date(java.util.Date) CodeMasterNotifyBean(jp.ossc.nimbus.service.codemaster.CodeMasterNotifyBean) ServerConnectionFactory(jp.ossc.nimbus.service.publish.ServerConnectionFactory) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) HashMap(java.util.HashMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 3 with ServerConnectionFactory

use of jp.ossc.nimbus.service.publish.ServerConnectionFactory in project nimbus by nimbus-org.

the class ServerConnectionSendActionService method execute.

/**
 * リソースの内容を読み込んで、{@link ServerConnection}に{@link Message}を送信する。<p>
 * リソースのフォーマットは、以下。<br>
 * <pre>
 * subject,key
 *
 * objectId
 * objectScript
 * </pre>
 * subjectは、{@link Message}に設定するサブジェクトを指定する。keyは、{@link Message}に設定するキーを指定する。サブジェクトを複数設定する場合は、改行して指定する。サブジェクト指定の終了には、空行を挿入する。<br>
 * objectIdは、{@link Message}に設定するオブジェクトを指定するもので、同一テストケース中に、このTestActionより前に、オブジェクトを戻すテストアクションが存在する場合は、そのアクションIDを指定する。また、同一シナリオ中に、このTestActionより前に、オブジェクトを戻すテストアクションが存在する場合は、テストケースIDとアクションIDをカンマ区切りで指定する。空行を指定した場合は、オブジェクトをTestActionの結果から取得しない。<br>
 * objectScriptは、{@link Message}に設定するオブジェクトを生成するスクリプトを指定する。スクリプトは、{@link Interpreter#evaluate(String,Map)}で評価され、引数の変数マップには、"context"で{@link TestContext}、"preResult"でpreResultが渡される。<br>
 * objectId、objectScriptの両方が指定されていない場合は、preResultを使用する。<br>
 *
 * @param context コンテキスト
 * @param actionId アクションID
 * @param preResult 更新クエリに対する引数オブジェクト
 * @param resource リソース
 * @return 送信したメッセージ
 */
public Object execute(TestContext context, String actionId, Object preResult, Reader resource) throws Exception {
    BufferedReader br = new BufferedReader(resource);
    Message message = null;
    Object object = preResult;
    ServerConnectionFactory scf = serverConnectionFactory;
    if (serverConnectionFactory == null && serverConnectionFactoryServiceName != null) {
        scf = (ServerConnectionFactory) ServiceManagerFactory.getServiceObject(serverConnectionFactoryServiceName);
    }
    final ServerConnection con = scf.getServerConnection();
    try {
        String subjectAndKey = br.readLine();
        if (subjectAndKey == null || subjectAndKey.length() == 0) {
            throw new Exception("Unexpected EOF on subject and key");
        }
        do {
            String[] subjectAndKeyArray = CSVReader.toArray(subjectAndKey, ',', '\\', null, null, true, false, true, true);
            if (subjectAndKeyArray == null || subjectAndKeyArray.length == 0 || subjectAndKeyArray.length > 2) {
                throw new Exception("Illegal subject and key format. subjectAndKey=" + subjectAndKey);
            }
            if (message == null) {
                message = con.createMessage(subjectAndKeyArray[0], subjectAndKeyArray.length == 2 ? subjectAndKeyArray[1] : null);
            } else {
                message.setSubject(subjectAndKeyArray[0], subjectAndKeyArray.length == 2 ? subjectAndKeyArray[1] : null);
            }
        } while ((subjectAndKey = br.readLine()) != null && subjectAndKey.length() != 0);
        final String objectId = br.readLine();
        if (objectId != null && objectId.length() != 0) {
            Object actionResult = null;
            if (objectId.indexOf(",") == -1) {
                actionResult = context.getTestActionResult(objectId);
            } else {
                String[] ids = objectId.split(",");
                if (ids.length != 2) {
                    throw new Exception("Illegal objectId format. id=" + objectId);
                }
                actionResult = context.getTestActionResult(ids[0], ids[1]);
            }
            if (actionResult == null) {
                throw new Exception("TestActionResult not found. id=" + objectId);
            }
            object = actionResult;
        }
        String objectScript = null;
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try {
            String line = null;
            while ((line = br.readLine()) != null) {
                pw.println(line);
            }
            pw.flush();
            objectScript = sw.toString();
            if (objectScript.length() == 0) {
                objectScript = null;
            }
        } finally {
            sw.close();
            pw.close();
        }
        if (objectScript != null) {
            if (interpreter == null) {
                throw new UnsupportedOperationException("Interpreter is null.");
            }
            final Map params = new HashMap();
            params.put("context", context);
            params.put("preResult", preResult);
            object = interpreter.evaluate(objectScript, params);
        }
        if (object != null) {
            message.setObject(object);
        }
        con.send(message);
    } finally {
        br.close();
        br = null;
    }
    return message;
}
Also used : Message(jp.ossc.nimbus.service.publish.Message) HashMap(java.util.HashMap) ServerConnection(jp.ossc.nimbus.service.publish.ServerConnection) ServerConnectionFactory(jp.ossc.nimbus.service.publish.ServerConnectionFactory) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) HashMap(java.util.HashMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Aggregations

HashMap (java.util.HashMap)3 Map (java.util.Map)3 ServerConnectionFactory (jp.ossc.nimbus.service.publish.ServerConnectionFactory)3 BufferedReader (java.io.BufferedReader)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Date (java.util.Date)1 Iterator (java.util.Iterator)1 TopicSession (javax.jms.TopicSession)1 BeanTableIndexKeyFactory (jp.ossc.nimbus.beans.BeanTableIndexKeyFactory)1 CacheMap (jp.ossc.nimbus.service.cache.CacheMap)1 CodeMasterNotifyBean (jp.ossc.nimbus.service.codemaster.CodeMasterNotifyBean)1 Message (jp.ossc.nimbus.service.publish.Message)1 ServerConnection (jp.ossc.nimbus.service.publish.ServerConnection)1 DefaultQueueService (jp.ossc.nimbus.service.queue.DefaultQueueService)1 QueueHandlerContainerService (jp.ossc.nimbus.service.queue.QueueHandlerContainerService)1