Search in sources :

Example 1 with Logger

use of jp.ossc.nimbus.service.log.Logger in project nimbus by nimbus-org.

the class DefaultServiceManagerService method getValueOfText.

private Object getValueOfText(ObjectMetaData objData, Type type, String textValue) throws Exception {
    final Logger logger = getLogger();
    // システムプロパティの置換
    textValue = Utility.replaceSystemProperty(textValue);
    // サービスローダ構成プロパティの置換
    textValue = Utility.replaceServiceLoderConfig(textValue, objData.getServiceLoader().getConfig());
    // マネージャプロパティの置換
    textValue = Utility.replaceManagerProperty(this, textValue);
    // サーバプロパティの置換
    textValue = Utility.replaceServerProperty(textValue);
    Class typeClass = null;
    if (type instanceof Class) {
        typeClass = (Class) type;
    } else if (type instanceof ParameterizedType) {
        typeClass = (Class) ((ParameterizedType) type).getRawType();
    } else {
        return textValue;
    }
    final PropertyEditor editor = objData.getServiceLoader().findEditor(typeClass);
    if (editor == null) {
        logger.write(SVCM_00040, typeClass);
        return null;
    }
    if (editor instanceof ServiceNameEditor) {
        ((ServiceNameEditor) editor).setServiceManagerName(objData.getManagerName());
    } else if (editor instanceof ServiceNameArrayEditor) {
        ((ServiceNameArrayEditor) editor).setServiceManagerName(objData.getManagerName());
    } else if (editor instanceof ServiceNameRefEditor) {
        ((ServiceNameRefEditor) editor).setServiceManagerName(objData.getManagerName());
    } else if (editor instanceof ServiceNameRefArrayEditor) {
        ((ServiceNameRefArrayEditor) editor).setServiceManagerName(objData.getManagerName());
    } else if (editor instanceof ParameterizedTypePropertyEditor && type instanceof ParameterizedType) {
        ((ParameterizedTypePropertyEditor) editor).setServiceLoader(objData.getServiceLoader());
        ((ParameterizedTypePropertyEditor) editor).setServiceManager(this);
        ((ParameterizedTypePropertyEditor) editor).setParameterizedType((ParameterizedType) type);
    }
    editor.setAsText(textValue);
    return editor.getValue();
}
Also used : Logger(jp.ossc.nimbus.service.log.Logger)

Example 2 with Logger

use of jp.ossc.nimbus.service.log.Logger in project nimbus by nimbus-org.

the class DefaultServiceManagerService method waitRegistrationManagerProcess.

/**
 * 依存するサービスマネージャの登録を待機して、登録されたタイミングで状態変更監視対象のサービスの状態をチェックして、対象のサービスの状態変更が行われるように登録する。<p>
 *
 * @param targetMng ServiceManagerFactoryへの登録を監視したいServiceManagerの名前
 * @param targetService 状態変更を監視したいサービスの名前
 * @param waitService 状態変更を待機するサービス
 * @param completed 状態遷移されたサービス名の集合。依存関係により状態遷移されたサービスを含む。
 * @param isInit ロード中かどうかのフラグ
 */
private void waitRegistrationManagerProcess(final String targetMng, final String targetService, final String waitService, final Set completed, final boolean isInit) {
    final Logger logger = getLogger();
    final ServiceName cause = new ServiceName(targetMng, targetMng);
    addWaitingServiceCause(cause, waitService);
    ServiceManagerFactory.addRegistrationListener(new RegistrationListener() {

        private final int state = getState();

        public void registered(RegistrationEvent e) {
            final ServiceManager manager = (ServiceManager) e.getRegistration();
            if (!manager.getServiceName().equals(targetMng)) {
                return;
            }
            ServiceManagerFactory.removeRegistrationListener(this);
            removeWaitingServiceCause(cause, waitService);
            Service service = null;
            try {
                service = manager.getService(targetService);
            } catch (ServiceNotFoundException ex) {
                waitRegistrationServiceProcess(manager, targetService, waitService, state, completed, isInit);
                return;
            }
            if (!isMatchingState(service, state, isInit)) {
                waitServiceStateProcess(service, DefaultServiceManagerService.this, waitService, state, completed);
            } else if (!completed.contains(waitService)) {
                DefaultServiceManagerService.this.changeServiceState(waitService, state, completed);
            }
        }

        public void unregistered(RegistrationEvent e) {
        }
    });
    String messageId = null;
    switch(getState()) {
        case CREATING:
            messageId = SVCM_00031;
            break;
        case STARTING:
            messageId = SVCM_00032;
            break;
        default:
            break;
    }
    logger.write(messageId, new Object[] { targetMng, getServiceName(), waitService });
}
Also used : Logger(jp.ossc.nimbus.service.log.Logger)

Example 3 with Logger

use of jp.ossc.nimbus.service.log.Logger in project nimbus by nimbus-org.

the class DefaultServiceManagerService method processDepended.

private boolean processDepended(ServiceManager manager, String serviceName, int state, Set completed) {
    boolean isInit = false;
    try {
        final ServiceMetaData myData = manager.getServiceMetaData(serviceName);
        final ServiceLoader myLoader = myData.getServiceLoader();
        isInit = myLoader != null && myLoader.getState() != STARTED;
    } catch (ServiceNotFoundException e) {
    }
    final Logger logger = getLogger();
    boolean result = true;
    final Iterator loaders = ServiceManagerFactory.getLoaders().iterator();
    while (loaders.hasNext()) {
        final ServiceLoader loader = (ServiceLoader) loaders.next();
        if (loader.getState() != STARTING && loader.getState() != STARTED && loader.getState() != STOPPING) {
            loaders.remove();
            continue;
        }
        final List dependedList = loader.getDependedServices(manager.getServiceName(), serviceName);
        final Iterator services = dependedList.iterator();
        while (services.hasNext()) {
            final ServiceMetaData serviceData = (ServiceMetaData) services.next();
            final String dependsManagerName = serviceData.getManager().getName();
            final ServiceManager mng = ServiceManagerFactory.findManager(dependsManagerName);
            if (mng == null) {
                continue;
            }
            final String dependsServiceName = serviceData.getName();
            Service dependsService = null;
            try {
                dependsService = mng.getService(dependsServiceName);
            } catch (ServiceNotFoundException e) {
                if (state != CREATING) {
                    continue;
                }
                try {
                    serviceData.getServiceLoader().deployService(serviceData);
                } catch (DeploymentException ee) {
                    continue;
                }
                dependsService = mng.getService(dependsServiceName);
            }
            if (isDepends(manager, serviceName, mng, dependsServiceName)) {
                logger.write(SVCM_00036, new Object[] { manager.getServiceName(), serviceName, mng.getServiceName(), dependsServiceName });
                result = false;
                continue;
            }
            if (!isMatchingState(dependsService, state, isInit)) {
                if (!completed.contains(dependsServiceName)) {
                    switch(state) {
                        case STARTING:
                            if (mng.getState() == STARTED) {
                                try {
                                    mng.startService(dependsServiceName, completed);
                                } catch (Exception e) {
                                    continue;
                                }
                            }
                            break;
                        case STOPPING:
                            mng.stopService(dependsServiceName, completed);
                            break;
                        case DESTROYING:
                        case CREATING:
                        default:
                    }
                }
            }
        }
    }
    return result;
}
Also used : Logger(jp.ossc.nimbus.service.log.Logger)

Example 4 with Logger

use of jp.ossc.nimbus.service.log.Logger in project nimbus by nimbus-org.

the class DefaultServiceManagerService method setServiceRepository.

// ServiceManagerのJavaDoc
public boolean setServiceRepository(Repository newRep) {
    final Logger logger = getLogger();
    synchronized (repository) {
        if (newRep == null || repository.equals(newRep)) {
            return false;
        }
        boolean success = true;
        final Set registered = new HashSet();
        Iterator names = repository.nameSet().iterator();
        while (names.hasNext()) {
            final String name = (String) names.next();
            final Object service = repository.get(name);
            if (service != null) {
                if (!newRep.register(name, service)) {
                    success = false;
                } else {
                    registered.add(name);
                }
            }
        }
        if (!success) {
            names = registered.iterator();
            while (names.hasNext()) {
                final String name = (String) names.next();
                newRep.unregister(name);
            }
            logger.write(SVCM_00007, newRep);
            return false;
        }
        names = newRep.nameSet().iterator();
        while (names.hasNext()) {
            final String name = (String) names.next();
            repository.unregister(name);
        }
        repository = newRep;
        logger.write(SVCM_00008, newRep);
    }
    return true;
}
Also used : Logger(jp.ossc.nimbus.service.log.Logger)

Example 5 with Logger

use of jp.ossc.nimbus.service.log.Logger in project nimbus by nimbus-org.

the class DefaultServiceManagerService method startService.

/**
 * このサービスの開始処理を行う。<p>
 * このマネージャに登録されている全てのサービスの開始処理({@link Service#start()})を行う。<br>
 * サービスの開始時には、開始しようとしているサービスが依存しているサービスの開始が優先されて行われる。<br>
 * 依存関係のあるサービスのロードが完了していない場合には、そのサービスがロードされ開始されるまで、依存されているサービスの開始は待機される。<br>
 * <p>
 * また、このマネージャが定義されているサービス定義ファイルのserver要素の子要素に、manager-repository要素、log要素、message要素が定義されている場合、ServiceManagerFactoryにLogger、MessageRecordFactory、Repositoryの設定を行う。<br>
 * 同様に、このマネージャが定義されているmanager要素の子要素に、repository要素、log要素、message要素が定義されている場合、このマネージャにLogger、MessageRecordFactory、Repositoryの設定を行う。<br>
 *
 * @exception Exception 開始処理に失敗した場合
 */
public void startService() throws Exception {
    final Logger logger = getLogger();
    startAllService();
    if (existWaitingService()) {
        final Iterator waitingServices = getWaitingServices().iterator();
        while (waitingServices.hasNext()) {
            final String waitingServiceName = (String) waitingServices.next();
            final Set causes = getWaitingCauses(waitingServiceName);
            logger.write(SVCM_00024, new Object[] { getServiceName(), waitingServiceName, causes });
        }
    }
}
Also used : Logger(jp.ossc.nimbus.service.log.Logger)

Aggregations

Logger (jp.ossc.nimbus.service.log.Logger)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 NoSuchPropertyException (jp.ossc.nimbus.beans.NoSuchPropertyException)1