Search in sources :

Example 1 with CamelContextRegistryService

use of org.wildfly.extension.camel.service.CamelContextRegistryService in project wildfly-camel by wildfly-extras.

the class CamelContextAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    String propName = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CONTEXT).asString();
    String propValue = CamelContextResource.VALUE.resolveModelAttribute(context, model).asString();
    subsystemState.putContextDefinition(propName, propValue.trim());
    ServiceController<?> container = context.getServiceRegistry(false).getService(CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME);
    if (container != null) {
        CamelContextRegistryService serviceRegistry = CamelContextRegistryService.class.cast(container.getService());
        CamelContextRegistry camelContextRegistry = serviceRegistry.getValue();
        if (camelContextRegistry != null) {
            if (camelContextRegistry.getCamelContext(propName) == null) {
                serviceRegistry.createCamelContext(propName, propValue);
            }
        }
    }
}
Also used : CamelContextRegistryService(org.wildfly.extension.camel.service.CamelContextRegistryService) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry)

Example 2 with CamelContextRegistryService

use of org.wildfly.extension.camel.service.CamelContextRegistryService in project wildfly-camel by wildfly-extras.

the class CamelContextRemove method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String propName = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CONTEXT).asString();
    final String oldContextDefinition = subsystemState.removeContextDefinition(propName);
    context.completeStep(new OperationContext.RollbackHandler() {

        @Override
        public void handleRollback(OperationContext context, ModelNode operation) {
            subsystemState.putContextDefinition(propName, oldContextDefinition);
        }
    });
    ServiceController<?> container = context.getServiceRegistry(false).getService(CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME);
    if (container != null) {
        CamelContextRegistryService serviceRegistry = CamelContextRegistryService.class.cast(container.getService());
        CamelContextRegistry camelContextRegistry = serviceRegistry.getValue();
        if (camelContextRegistry != null) {
            CamelContext camelctx = camelContextRegistry.getCamelContext(propName);
            try {
                if (camelctx != null) {
                    camelctx.stop();
                }
            } catch (Exception e) {
                LOGGER.warn("Cannot stop camel context: " + camelctx.getName(), e);
                throw new OperationFailedException(e);
            }
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) CamelContext(org.apache.camel.CamelContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) CamelContextRegistryService(org.wildfly.extension.camel.service.CamelContextRegistryService) ModelNode(org.jboss.dmr.ModelNode) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

CamelContextRegistry (org.wildfly.extension.camel.CamelContextRegistry)2 CamelContextRegistryService (org.wildfly.extension.camel.service.CamelContextRegistryService)2 CamelContext (org.apache.camel.CamelContext)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 ModelNode (org.jboss.dmr.ModelNode)1