Search in sources :

Example 1 with MessageRecordFactory

use of jp.ossc.nimbus.service.message.MessageRecordFactory in project nimbus by nimbus-org.

the class DefaultServiceLoaderService method checkDepends.

private void checkDepends(Map refServices, ServiceMetaData serviceData, ServiceMetaData.DependsMetaData dependsData) throws DeploymentException {
    final ManagerMetaData managerData = serviceData.getManager();
    final String managerName = managerData.getName();
    final String serviceName = serviceData.getName();
    final String depManagerName = dependsData.getManagerName();
    final String depServiceName = dependsData.getServiceName();
    final Map ref = (Map) refServices.get(depManagerName);
    if (ref == null || !ref.containsKey(depServiceName)) {
        final MessageRecordFactory message = getMessageRecordFactory();
        throw new DeploymentException(message.findEmbedMessage(SVCL_00036, new Object[] { depManagerName, depServiceName }));
    } else {
        final ServiceMetaData depServiceData = (ServiceMetaData) ref.get(depServiceName);
        final Iterator deps = depServiceData.getDepends().iterator();
        while (deps.hasNext()) {
            final ServiceMetaData.DependsMetaData depdepServiceData = (ServiceMetaData.DependsMetaData) deps.next();
            final String depdepManagerName = depdepServiceData.getManagerName();
            final String depdepServiceName = depdepServiceData.getServiceName();
            if (depdepManagerName.equals(managerName) && depdepServiceName.equals(serviceName)) {
                final MessageRecordFactory message = getMessageRecordFactory();
                throw new DeploymentException(message.findEmbedMessage(SVCL_00037, new Object[] { managerName, serviceName, depdepManagerName, depdepServiceName }));
            }
            checkDepends(refServices, serviceData, depdepServiceData);
        }
    }
}
Also used : MessageRecordFactory(jp.ossc.nimbus.service.message.MessageRecordFactory)

Example 2 with MessageRecordFactory

use of jp.ossc.nimbus.service.message.MessageRecordFactory in project nimbus by nimbus-org.

the class DefaultServiceManagerService method instanciateObject.

private Object instanciateObject(ObjectMetaData objData) throws Exception {
    Object value = null;
    final Class clazz = Utility.convertStringToClass(objData.getCode());
    if ((objData instanceof ServiceMetaData) && ((ServiceMetaData) objData).isFactory()) {
        final ServiceMetaData serviceData = (ServiceMetaData) objData;
        final GenericsFactoryServiceProxy proxy = new GenericsFactoryServiceProxy(clazz, serviceData.isManagement());
        if (ServiceMetaData.INSTANCE_TYPE_THREADLOCAL.equals(serviceData.getInstance())) {
            proxy.setThreadLocal(true);
        }
        proxy.setCreateTemplateOnStart(serviceData.isCreateTemplate());
        value = proxy;
    } else {
        final ConstructorMetaData constData = objData.getConstructor();
        if (constData == null) {
            if (clazz.isArray()) {
                final Class elementType = clazz.getComponentType();
                value = Array.newInstance(elementType, 0);
            } else {
                value = clazz.newInstance();
            }
        } else {
            if (constData.getInvoke() != null) {
                InvokeMetaData invoke = constData.getInvoke();
                Object target = getValueOfTarget(invoke);
                value = callInvoke(target, null, invoke);
                if (value == null) {
                    final MessageRecordFactory message = getMessageRecordFactory();
                    throw new InstantiationException(message.findEmbedMessage(SVCM_00015, new Object[] { target == null ? null : target.getClass().getName(), invoke.getName() }));
                }
            } else if (constData.getStaticInvoke() != null) {
                StaticInvokeMetaData invoke = constData.getStaticInvoke();
                value = callInvoke(null, null, invoke);
                if (value == null) {
                    final MessageRecordFactory message = getMessageRecordFactory();
                    throw new InstantiationException(message.findEmbedMessage(SVCM_00015, new Object[] { invoke.getCode(), invoke.getName() }));
                }
            } else if (constData.getStaticFieldRef() != null) {
                StaticFieldRefMetaData field = constData.getStaticFieldRef();
                value = getStaticFieldValue(field);
                if (value == null) {
                    final MessageRecordFactory message = getMessageRecordFactory();
                    throw new InstantiationException(message.findEmbedMessage(SVCM_00016, new Object[] { field.getCode(), field.getName() }));
                }
            } else if (clazz.isArray()) {
                final Class elementType = clazz.getComponentType();
                final Collection argCollection = constData.getArguments();
                Object argVals = Array.newInstance(elementType, argCollection.size());
                final Iterator args = argCollection.iterator();
                int i = 0;
                while (args.hasNext()) {
                    final ArgumentMetaData argData = (ArgumentMetaData) args.next();
                    Array.set(argVals, i, getValueOfArgument(argData));
                    i++;
                }
                value = argVals;
            } else {
                final Collection argCollection = constData.getArguments();
                final Class[] argTypes = new Class[argCollection.size()];
                final Object[] argVals = new Object[argCollection.size()];
                final Iterator args = argCollection.iterator();
                int i = 0;
                while (args.hasNext()) {
                    final ArgumentMetaData argData = (ArgumentMetaData) args.next();
                    argVals[i] = getValueOfArgument(argData);
                    if (argData.getType() != null) {
                        argTypes[i] = Utility.convertStringToClass(argData.getType());
                    } else if (argVals[i] != null) {
                        argTypes[i] = argVals[i].getClass();
                    } else {
                        argTypes[i] = String.class;
                    }
                    i++;
                }
                final Constructor constructor = clazz.getConstructor(argTypes);
                value = constructor.newInstance(argVals);
            }
        }
    }
    return value;
}
Also used : MessageRecordFactory(jp.ossc.nimbus.service.message.MessageRecordFactory)

Example 3 with MessageRecordFactory

use of jp.ossc.nimbus.service.message.MessageRecordFactory in project nimbus by nimbus-org.

the class DefaultServiceManagerService method changeServiceState.

private boolean changeServiceState(Object obj, ServiceMetaData serviceData, int state) throws Exception {
    synchronized (obj) {
        String managerName = null;
        String serviceName = null;
        Service service = null;
        Object serviceObj = obj;
        if (obj instanceof Service) {
            service = (Service) obj;
            managerName = service.getServiceManagerName();
            serviceName = service.getServiceName();
            if (getServiceName().equals(serviceName)) {
                return true;
            }
            serviceObj = convertServiceToObject(service);
        }
        switch(state) {
            case CREATING:
                if (service instanceof ServiceBase && !((ServiceBase) service).isNecessaryToCreate()) {
                    return false;
                }
                if (serviceData != null && !serviceData.isFactory()) {
                    callInvokes(serviceObj, serviceData, CREATING);
                }
                if (service != null) {
                    service.create();
                }
                if (serviceData != null && !serviceData.isFactory()) {
                    setFields(serviceObj, serviceData, CREATED);
                    setAttributes(serviceObj, serviceData, CREATED);
                    callInvokes(serviceObj, serviceData, CREATED);
                }
                removeFailedServiceCause(serviceName);
                break;
            case STARTING:
                if (service instanceof ServiceBase && !((ServiceBase) service).isNecessaryToStart()) {
                    return false;
                }
                if (serviceData != null && !serviceData.isFactory()) {
                    setFields(serviceObj, serviceData, STARTING);
                    setAttributes(serviceObj, serviceData, STARTING);
                    callInvokes(serviceObj, serviceData, STARTING);
                }
                if (service != null) {
                    service.start();
                }
                if (serviceData != null && !serviceData.isFactory()) {
                    callInvokes(serviceObj, serviceData, STARTED);
                }
                break;
            case STOPPING:
                if (service instanceof ServiceBase && !((ServiceBase) service).isNecessaryToStop()) {
                    return false;
                }
                if (serviceData != null && !serviceData.isFactory()) {
                    callInvokes(serviceObj, serviceData, STOPPING);
                }
                if (service != null) {
                    service.stop();
                }
                if (serviceData != null && !serviceData.isFactory()) {
                    callInvokes(serviceObj, serviceData, STOPPED);
                }
                break;
            case DESTROYING:
                if (service instanceof ServiceBase && !((ServiceBase) service).isNecessaryToDestroy()) {
                    return false;
                }
                if (serviceData != null && !serviceData.isFactory()) {
                    callInvokes(serviceObj, serviceData, DESTROYING);
                }
                if (service != null) {
                    service.destroy();
                }
                if (serviceData != null && !serviceData.isFactory()) {
                    callInvokes(serviceObj, serviceData, DESTROYED);
                }
                break;
            default:
                final MessageRecordFactory message = getMessageRecordFactory();
                throw new IllegalStateException(message.findEmbedMessage(SVCM_00012, new Object[] { managerName, serviceName, STATES[state] }));
        }
    }
    return true;
}
Also used : MessageRecordFactory(jp.ossc.nimbus.service.message.MessageRecordFactory)

Example 4 with MessageRecordFactory

use of jp.ossc.nimbus.service.message.MessageRecordFactory in project nimbus by nimbus-org.

the class DefaultCommonsLogFactoryService method getInstance.

// CommonsLogFactory恮JavaDoc
public Log getInstance(Class clazz) throws LogConfigurationException {
    if (logInstances == null) {
        final MessageRecordFactory message = getMessageRecordFactory();
        throw new LogConfigurationException(message.findMessage(DCLF_00001));
    }
    if (logInstances.containsKey(clazz)) {
        return (Log) logInstances.get(clazz);
    }
    final CommonsLog log = new CommonsLog(clazz);
    logInstances.put(clazz, log);
    if (!enabledClientSet.isEmpty()) {
        log.setEnabled(containsEnabledClient(log));
    }
    return log;
}
Also used : Log(org.apache.commons.logging.Log) MessageRecordFactory(jp.ossc.nimbus.service.message.MessageRecordFactory) LogConfigurationException(org.apache.commons.logging.LogConfigurationException)

Example 5 with MessageRecordFactory

use of jp.ossc.nimbus.service.message.MessageRecordFactory in project nimbus by nimbus-org.

the class GroupCategoryService method parseRange.

private Range parseRange(String range) throws IllegalArgumentException {
    final MessageRecordFactory message = getMessageRecordFactory();
    final StringTokenizer tokens = new StringTokenizer(range, PRIORITY_RANGE_DELIMITER);
    if (tokens.countTokens() != 2) {
        throw new IllegalArgumentException(message.findMessage(SCGRY00001));
    }
    final String minStr = tokens.nextToken();
    final String maxStr = tokens.nextToken();
    int min = 0;
    int max = 0;
    try {
        min = Integer.parseInt(minStr);
        max = Integer.parseInt(maxStr);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException(message.findMessage(SCGRY00001));
    }
    if (min > max) {
        throw new IllegalArgumentException(message.findMessage(SCGRY00002));
    }
    return new Range(min, max);
}
Also used : MessageRecordFactory(jp.ossc.nimbus.service.message.MessageRecordFactory)

Aggregations

MessageRecordFactory (jp.ossc.nimbus.service.message.MessageRecordFactory)16 Log (org.apache.commons.logging.Log)2 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)2