Skip to content

Commit

Permalink
Represent status interval as a Duration to remove time unit ambiguity…
Browse files Browse the repository at this point in the history
… in mod_cluster container event handler adapter SPI.
  • Loading branch information
pferraro committed Apr 5, 2017
1 parent 8956f0c commit a8da8eb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
@@ -1,9 +1,11 @@
package org.wildfly.extension.mod_cluster;

import java.time.Duration;

import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceTarget;

public interface ContainerEventHandlerAdapterBuilder {
ServiceBuilder<?> build(ServiceTarget target, CapabilityServiceSupport serviceSupport, String connector, int statusInterval);
ServiceBuilder<?> build(ServiceTarget target, CapabilityServiceSupport serviceSupport, String connector, Duration statusInterval);
}
Expand Up @@ -30,6 +30,7 @@
import static org.wildfly.extension.mod_cluster.ModClusterConfigResourceDefinition.STATUS_INTERVAL;
import static org.wildfly.extension.mod_cluster.ModClusterLogger.ROOT_LOGGER;

import java.time.Duration;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void performBoottime(OperationContext context, ModelNode operation, Model

// Install services for web container integration
for (ContainerEventHandlerAdapterBuilder adapterBuilder : ServiceLoader.load(ContainerEventHandlerAdapterBuilder.class, ContainerEventHandlerAdapterBuilder.class.getClassLoader())) {
adapterBuilder.build(target, context.getCapabilityServiceSupport(), connector, statusInterval).setInitialMode(Mode.PASSIVE).install();
adapterBuilder.build(target, context.getCapabilityServiceSupport(), connector, Duration.ofSeconds(statusInterval)).setInitialMode(Mode.PASSIVE).install();
}
}

Expand Down
Expand Up @@ -27,6 +27,7 @@
import io.undertow.servlet.api.Deployment;

import java.security.PrivilegedAction;
import java.time.Duration;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -62,7 +63,6 @@ public class UndertowEventHandlerAdapter implements UndertowEventListener, Servi
// No logger interface for this module and no reason to create one for this class only
private static final Logger log = Logger.getLogger("org.jboss.mod_cluster.undertow");

@SuppressWarnings("rawtypes")
private final Value<UndertowListener> listener;
private final Value<UndertowService> service;
private final Value<ContainerEventHandler> eventHandler;
Expand All @@ -71,9 +71,9 @@ public class UndertowEventHandlerAdapter implements UndertowEventListener, Servi
private volatile ScheduledExecutorService executor;
private volatile Server server;
private volatile Connector connector;
private int statusInterval;
private final Duration statusInterval;

public UndertowEventHandlerAdapter(Value<ContainerEventHandler> eventHandler, Value<UndertowService> service, @SuppressWarnings("rawtypes") Value<UndertowListener> listener, Value<SuspendController> suspendController, int statusInterval) {
public UndertowEventHandlerAdapter(Value<ContainerEventHandler> eventHandler, Value<UndertowService> service, @SuppressWarnings("rawtypes") Value<UndertowListener> listener, Value<SuspendController> suspendController, Duration statusInterval) {
this.eventHandler = eventHandler;
this.service = service;
this.listener = listener;
Expand Down Expand Up @@ -108,7 +108,7 @@ public ThreadFactory run() {
}
});
this.executor = Executors.newScheduledThreadPool(1, factory);
this.executor.scheduleWithFixedDelay(this, 0, statusInterval, TimeUnit.SECONDS);
this.executor.scheduleWithFixedDelay(this, 0, this.statusInterval.toMillis(), TimeUnit.MILLISECONDS);
suspendController.getValue().registerActivity(this);
}

Expand All @@ -119,7 +119,7 @@ public void stop(StopContext context) {

this.executor.shutdownNow();
try {
this.executor.awaitTermination(statusInterval, TimeUnit.SECONDS);
this.executor.awaitTermination(this.statusInterval.toMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException ignore) {
// Move on.
}
Expand Down
Expand Up @@ -22,6 +22,8 @@

package org.wildfly.mod_cluster.undertow;

import java.time.Duration;

import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.modcluster.container.ContainerEventHandler;
Expand All @@ -42,7 +44,7 @@ public class UndertowEventHandlerAdapterBuilder implements ContainerEventHandler
public static final ServiceName SERVICE_NAME = ContainerEventHandlerService.SERVICE_NAME.append("undertow");

@Override
public ServiceBuilder<?> build(ServiceTarget target, CapabilityServiceSupport serviceSupport, String connector, int statusInterval) {
public ServiceBuilder<?> build(ServiceTarget target, CapabilityServiceSupport serviceSupport, String connector, Duration statusInterval) {
InjectedValue<ContainerEventHandler> eventHandler = new InjectedValue<>();
InjectedValue<UndertowService> undertowService = new InjectedValue<>();
InjectedValue<SuspendController> suspendController = new InjectedValue<>();
Expand Down

0 comments on commit a8da8eb

Please sign in to comment.