Skip to content

Commit

Permalink
Re-enable camel-core fraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmcwhirter committed Aug 5, 2016
1 parent ffffe8f commit d6c34a4
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 189 deletions.
2 changes: 2 additions & 0 deletions camel/core/main/module.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ org.wildfly.extension.camel.security
org.jboss.gravia
org.jboss.msc
org.slf4j

javax.enterprise.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -19,8 +19,17 @@
*/
package org.wildfly.swarm.camel.core;

import javax.inject.Singleton;

import org.wildfly.swarm.spi.api.DefaultFraction;
import org.wildfly.swarm.spi.api.Fraction;
import org.wildfly.swarm.spi.api.annotations.WildFlyExtension;
import org.wildfly.swarm.spi.api.annotations.WildFlySubsystem;

@Singleton
@DefaultFraction
@WildFlyExtension(module = "org.wildfly.extension.camel")
@WildFlySubsystem("camel")
public final class CamelCoreFraction extends AbstractCamelFraction<CamelCoreFraction> implements Fraction {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.wildfly.swarm.camel.core;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.enterprise.inject.Any;
import javax.inject.Inject;
import javax.inject.Singleton;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.ModelCamelContext;
import org.jboss.msc.service.AbstractService;
import org.jboss.msc.service.ServiceActivator;
import org.jboss.msc.service.ServiceActivatorContext;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistryException;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.wildfly.extension.camel.CamelConstants;
import org.wildfly.extension.camel.service.CamelContextRegistryService;

import static org.wildfly.swarm.camel.core.AbstractCamelFraction.LOGGER;

/**
* @author Bob McWhirter
*/
@Singleton
public class CamelServiceActivator implements ServiceActivator {

@Inject
@Any
private CamelCoreFraction fraction;

@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
BootstrapCamelContextService.addService(context.getServiceTarget(), this.fraction);
}

static class BootstrapCamelContextService extends AbstractService<Void> {

static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("wildfly", "swarm", "camel", "bootstrap");

InjectedValue<CamelContextRegistryService.MutableCamelContextRegistry> injectedContextRegistry = new InjectedValue<>();

List<CamelContext> systemContexts = new ArrayList<>();

CamelCoreFraction fraction;

static ServiceController<Void> addService(ServiceTarget serviceTarget, CamelCoreFraction fraction) {
BootstrapCamelContextService service = new BootstrapCamelContextService(fraction);
ServiceName serviceName = SERVICE_NAME;
ServiceBuilder<Void> builder = serviceTarget.addService(serviceName, service);
builder.addDependency(CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME, CamelContextRegistryService.MutableCamelContextRegistry.class, service.injectedContextRegistry);
return builder.install();
}

BootstrapCamelContextService(CamelCoreFraction fraction) {
this.fraction = fraction;
}

@Override
public void start(StartContext startContext) throws StartException {
CamelContextRegistryService.MutableCamelContextRegistry contextRegistry = injectedContextRegistry.getValue();
ClassLoader classLoader = CamelContextRegistryService.MutableCamelContextRegistry.class.getClassLoader();
try {
for (RouteBuilder builder : this.fraction.getRouteBuilders()) {
ModelCamelContext camelctx = builder.getContext();
camelctx.setApplicationContextClassLoader(classLoader);
builder.addRoutesToCamelContext(camelctx);
contextRegistry.addCamelContext(camelctx);
systemContexts.add(camelctx);
}
for (CamelContext camelctx : systemContexts) {
camelctx.start();
}
} catch (Exception ex) {
throw new StartException(ex);
}
}

@Override
public void stop(StopContext startContext) {
CamelContextRegistryService.MutableCamelContextRegistry contextRegistry = injectedContextRegistry.getValue();
Collections.reverse(systemContexts);
for (CamelContext camelctx : systemContexts) {
try {
camelctx.stop();
} catch (Exception ex) {
LOGGER.error("Cannot stop context: " + camelctx, ex);
}
}
for (CamelContext camelctx : systemContexts) {
contextRegistry.removeCamelContext(camelctx);
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -29,9 +29,9 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.swarm.ContainerFactory;
import org.wildfly.swarm.Swarm;
import org.wildfly.swarm.arquillian.CreateSwarm;
import org.wildfly.swarm.camel.core.subA.RouteBuilderA;
import org.wildfly.swarm.container.Container;
import org.wildfly.swarm.spi.api.JARArchive;


Expand All @@ -40,7 +40,7 @@
* @since 09-Feb-2016
*/
@RunWith(Arquillian.class)
public class SimpleCoreTransformTest implements ContainerFactory {
public class SimpleCoreTransformTest {

@Deployment
public static JARArchive deployment() {
Expand All @@ -50,9 +50,9 @@ public static JARArchive deployment() {
return archive;
}

@Override
public Container newContainer(String... args) throws Exception {
return new Container().fraction(new CamelCoreFraction());
@CreateSwarm
public static Swarm newContainer() throws Exception {
return new Swarm().fraction(new CamelCoreFraction());
}

@Test
Expand Down
Loading

0 comments on commit d6c34a4

Please sign in to comment.