Search in sources :

Example 6 with CamelContextRegistry

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

the class CamelContextRegistryProvider method lookup.

@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    if (serviceInstance.get() == null) {
        CamelContextRegistry service = ServiceLocator.getRequiredService(CamelContextRegistry.class);
        serviceProducer.set(service);
    }
    return serviceInstance.get();
}
Also used : CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry)

Example 7 with CamelContextRegistry

use of org.wildfly.extension.camel.CamelContextRegistry 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 8 with CamelContextRegistry

use of org.wildfly.extension.camel.CamelContextRegistry 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)8 CamelContext (org.apache.camel.CamelContext)5 Test (org.junit.Test)4 ProducerTemplate (org.apache.camel.ProducerTemplate)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 CamelContextRegistryService (org.wildfly.extension.camel.service.CamelContextRegistryService)2 PrintWriter (java.io.PrintWriter)1 Socket (java.net.Socket)1 MonitorNotification (javax.management.monitor.MonitorNotification)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 ConsumerTemplate (org.apache.camel.ConsumerTemplate)1 PollingConsumer (org.apache.camel.PollingConsumer)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 BinderService (org.jboss.as.naming.service.BinderService)1 ModelNode (org.jboss.dmr.ModelNode)1