Permalink
Browse files

Fix the way listeners are created

  • Loading branch information...
1 parent c918960 commit 1b11d6d03d061bc3b7a1ef9aa6cdd55974297fab @ctomc ctomc committed with kabir Apr 4, 2013
@@ -1,12 +1,9 @@
package org.jboss.as.undertow;
-import java.util.List;
-
import org.jboss.as.controller.OperationContext;
-import org.jboss.as.controller.ServiceVerificationHandler;
+import org.jboss.as.controller.OperationFailedException;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
-import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
/**
@@ -23,14 +20,12 @@ protected ServiceName constructServiceName(final String name) {
}
@Override
- void installService(OperationContext context, ModelNode operation, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) {
- final AJPListenerService service = new AJPListenerService(name);
- final ServiceBuilder<AJPListenerService> serviceBuilder = context.getServiceTarget().addService(constructServiceName(name), service);
- addDefaultDependencies(serviceBuilder, service);
+ AbstractListenerService<? extends AbstractListenerService> createService(String name, OperationContext context, ModelNode model) throws OperationFailedException {
+ return new AJPListenerService(name);
+ }
+
+ @Override
+ void configureAdditionalDependencies(OperationContext context, ServiceBuilder<? extends AbstractListenerService> serviceBuilder, ModelNode model, AbstractListenerService service) throws OperationFailedException {
- final ServiceController<AJPListenerService> serviceController = serviceBuilder.install();
- if (newControllers != null) {
- newControllers.add(serviceController);
- }
}
}
@@ -22,13 +22,7 @@
* @author <a href="mailto:tomaz.cerar@redhat.com">Tomaz Cerar</a> (c) 2012 Red Hat Inc.
*/
abstract class AbstractListenerAdd extends AbstractAddStepHandler {
- protected String name;
- protected String bindingRef;
- protected String workerName;
- protected String bufferPoolName;
- protected String serverName;
private final AbstractListenerResourceDefinition listenerDefinition;
- protected boolean enabled;
AbstractListenerAdd(AbstractListenerResourceDefinition definition) {
@@ -52,20 +46,28 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod
String bufferPoolName = AbstractListenerResourceDefinition.BUFFER_POOL.resolveModelAttribute(context, model).asString();
boolean enabled = AbstractListenerResourceDefinition.ENABLED.resolveModelAttribute(context, model).asBoolean();
String serverName = parent.getLastElement().getValue();
- if (enabled){
- installService(context, model, verificationHandler, newControllers);
- }
- }
+ if (enabled) {
+ final AbstractListenerService<? extends AbstractListenerService> service = createService(name, context, model);
+ final ServiceBuilder<? extends AbstractListenerService> serviceBuilder = context.getServiceTarget().addService(constructServiceName(name), service);
+ serviceBuilder.addDependency(UndertowService.WORKER.append(workerName), XnioWorker.class, service.getWorker())
+ .addDependency(SocketBinding.JBOSS_BINDING_NAME.append(bindingRef), SocketBinding.class, service.getBinding())
+ .addDependency(UndertowService.BUFFER_POOL.append(bufferPoolName), Pool.class, service.getBufferPool())
+ .addDependency(UndertowService.SERVER.append(serverName), Server.class, service.getServerService());
+
+ configureAdditionalDependencies(context, serviceBuilder, model, service);
- protected void addDefaultDependencies(ServiceBuilder<? extends AbstractListenerService<?>> serviceBuilder, AbstractListenerService<?> service) {
- serviceBuilder.addDependency(UndertowService.WORKER.append(workerName), XnioWorker.class, service.getWorker())
- .addDependency(SocketBinding.JBOSS_BINDING_NAME.append(bindingRef), SocketBinding.class, service.getBinding())
- .addDependency(UndertowService.BUFFER_POOL.append(bufferPoolName), Pool.class, service.getBufferPool())
- .addDependency(UndertowService.SERVER.append(serverName), Server.class, service.getServerService());
+ final ServiceController<? extends AbstractListenerService> serviceController = serviceBuilder.install();
+ if (newControllers != null) {
+ newControllers.add(serviceController);
+ }
+ }
}
abstract ServiceName constructServiceName(final String name);
- abstract void installService(OperationContext context, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException;
+ abstract AbstractListenerService<? extends AbstractListenerService> createService(final String name, final OperationContext context, ModelNode model) throws OperationFailedException;
+
+ abstract void configureAdditionalDependencies(OperationContext context, ServiceBuilder<? extends AbstractListenerService> serviceBuilder, ModelNode model, AbstractListenerService service) throws OperationFailedException;
+
}
@@ -1,13 +1,9 @@
package org.jboss.as.undertow;
-import java.util.List;
-
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
-import org.jboss.as.controller.ServiceVerificationHandler;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder;
-import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
/**
@@ -24,23 +20,12 @@ protected ServiceName constructServiceName(final String name) {
}
@Override
- void installService(OperationContext context, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException {
- final HttpListenerService service = createService(name);
- final ServiceBuilder<HttpListenerService> serviceBuilder = context.getServiceTarget().addService(constructServiceName(name), service);
- addDefaultDependencies(serviceBuilder, service);
-
- configureAdditionalDependencies(context, serviceBuilder, model, service);
-
- final ServiceController<HttpListenerService> serviceController = serviceBuilder.install();
- if (newControllers != null) {
- newControllers.add(serviceController);
- }
- }
-
- protected HttpListenerService createService(final String name) {
+ AbstractListenerService<? extends AbstractListenerService> createService(String name, OperationContext context, ModelNode model) throws OperationFailedException {
return new HttpListenerService(name);
}
- protected void configureAdditionalDependencies(OperationContext context, ServiceBuilder<HttpListenerService> serviceBuilder, ModelNode model, HttpListenerService service) throws OperationFailedException {
+ @Override
+ void configureAdditionalDependencies(OperationContext context, ServiceBuilder<? extends AbstractListenerService> serviceBuilder, ModelNode model, AbstractListenerService service) throws OperationFailedException {
+
}
}
@@ -34,7 +34,7 @@
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
-public class HttpsListenerAdd extends HttpListenerAdd {
+public class HttpsListenerAdd extends AbstractListenerAdd {
HttpsListenerAdd(HttpsListenerResourceDefinition def) {
super(def);
@@ -46,16 +46,14 @@ protected ServiceName constructServiceName(String name) {
}
@Override
- protected HttpListenerService createService(final String name) {
+ AbstractListenerService<? extends AbstractListenerService> createService(String name, OperationContext context, ModelNode model) throws OperationFailedException {
return new HttpsListenerService(name);
}
@Override
- protected void configureAdditionalDependencies(OperationContext context, ServiceBuilder<HttpListenerService> serviceBuilder, ModelNode model, HttpListenerService service) throws OperationFailedException {
+ void configureAdditionalDependencies(OperationContext context, ServiceBuilder<? extends AbstractListenerService> serviceBuilder, ModelNode model, AbstractListenerService service) throws OperationFailedException {
final String securityRealm = HttpsListenerResourceDefinition.SECURITY_REALM.resolveModelAttribute(context, model).asString();
serviceBuilder.addDependency(SecurityRealmService.BASE_SERVICE_NAME.append(securityRealm), SecurityRealm.class, ((HttpsListenerService) service).getSecurityRealm());
}
-
-
}

0 comments on commit 1b11d6d

Please sign in to comment.