Commit 32344958 authored by michael.simon's avatar michael.simon
Browse files

Remove singleton scheduler classes

Remove singleton scheduler classes for JBoss/Wildfly specific API.
parent 5a8c787f
......@@ -106,23 +106,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.msc</groupId>
<artifactId>jboss-msc</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-clustering-common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-clustering-singleton</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
......@@ -159,9 +142,7 @@
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Dependencies>org.jboss.msc,
${bwreg.jboss-singleton},
org.jboss.as.server</Dependencies>
<Dependencies></Dependencies>
</manifestEntries>
</archive>
</configuration>
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.timer;
public interface ClusterSchedulerStatusService {
String getActiveNode();
ClusterScheduler getClusterScheduler();
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.timer;
import java.io.Serializable;
import javax.ejb.Stateless;
import org.jboss.as.server.CurrentServiceContainer;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceController;
@Stateless
public class ClusterSchedulerStatusServiceImpl implements
ClusterSchedulerStatusService, Serializable {
private static final long serialVersionUID = 1L;
@Override
public String getActiveNode() {
return getClusterScheduler().getNodeName();
}
@Override
public ClusterScheduler getClusterScheduler() {
ServiceController<?> serviceController =
CurrentServiceContainer.getServiceContainer().getService(
ClusterSingletonTimerService.SINGLETON_SERVICE_NAME);
Service<?> service = serviceController.getService();
return (ClusterScheduler) service.getValue();
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.timer;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ClusterSingletonTimerService implements Service<ClusterScheduler> {
private static final Logger logger = LoggerFactory.getLogger(ClusterSingletonTimerService.class);
public static final ServiceName SINGLETON_SERVICE_NAME = ServiceName.JBOSS.append("bwidm", "cluster", "singleton", "timer");
private final AtomicBoolean started = new AtomicBoolean(false);
private ClusterScheduler clusterScheduler;
final InjectedValue<ServerEnvironment> env = new InjectedValue<ServerEnvironment>();
public ClusterScheduler getValue() throws IllegalStateException, IllegalArgumentException {
if (! started.get()) {
throw new IllegalStateException("Service " + this.getClass().getName() + " not yet started!");
}
return clusterScheduler;
}
public void start(StartContext arg0) throws StartException {
if (! started.compareAndSet(false, true)) {
throw new StartException("The service is already running");
}
logger.info("Start Cluster Singleton timer service '" + this.getClass().getName() + "'");
String nodeName = env.getValue().getNodeName();
try {
clusterScheduler = lookupClusterScheduler();
clusterScheduler.startTimers(nodeName);
} catch (NamingException e) {
throw new StartException("Could not initialize timer", e);
}
}
public void stop(StopContext arg0) {
if (!started.compareAndSet(true, false)) {
logger.warn("The service '" + this.getClass().getName() + "' is not active!");
}
else {
logger.info("Stop Cluster Singleton timer service '" + this.getClass().getName() + "'");
try {
clusterScheduler = lookupClusterScheduler();
clusterScheduler.stopTimers();
} catch (NamingException e) {
logger.error("Could not stop timer", e);
}
}
}
private ClusterScheduler lookupClusterScheduler() throws NamingException {
InitialContext ic = new InitialContext();
return (ClusterScheduler) ic.lookup("global/bwreg/bwreg-service/ClusterSchedulerImpl!edu.kit.scc.webreg.service.timer.ClusterScheduler");
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.timer;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.ServerEnvironmentService;
import org.jboss.msc.service.ServiceActivator;
import org.jboss.msc.service.ServiceActivatorContext;
import org.jboss.msc.service.ServiceController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wildfly.clustering.singleton.SingletonServiceBuilderFactory;
public class WildflyClusterSingletonServiceActivator implements ServiceActivator {
private final Logger logger = LoggerFactory.getLogger(WildflyClusterSingletonServiceActivator.class);
@Override
public void activate(ServiceActivatorContext context) {
logger.info("ClusterSingletonService will be installed!");
ClusterSingletonTimerService service = new ClusterSingletonTimerService();
ServiceController<?> factoryService = context.getServiceRegistry().getRequiredService(SingletonServiceBuilderFactory.SERVICE_NAME.append("server", "default"));
SingletonServiceBuilderFactory factory = (SingletonServiceBuilderFactory) factoryService.getValue();
factory.createSingletonServiceBuilder(ClusterSingletonTimerService.SINGLETON_SERVICE_NAME, service)
.build(context.getServiceTarget())
.addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, service.env)
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
}
}
......@@ -17,7 +17,6 @@ import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.bootstrap.NodeConfiguration;
import edu.kit.scc.webreg.service.timer.ClusterSchedulerStatusService;
import edu.kit.scc.webreg.service.timer.StandardScheduler;
@Named("schedulerStatusBean")
......@@ -26,19 +25,12 @@ public class SchedulerStatusBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private ClusterSchedulerStatusService clusterSchedulerStatusService;
@Inject
private StandardScheduler standardScheduler;
@Inject
private NodeConfiguration nodeConfiguration;
public ClusterSchedulerStatusService getClusterSchedulerStatusService() {
return clusterSchedulerStatusService;
}
public NodeConfiguration getNodeConfiguration() {
return nodeConfiguration;
}
......
......@@ -139,27 +139,6 @@
<artifactId>ganymed-ssh2</artifactId>
<version>262</version>
</dependency>
<dependency>
<groupId>org.jboss.msc</groupId>
<artifactId>jboss-msc</artifactId>
<version>1.0.4.GA</version>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-clustering-common</artifactId>
<version>8.2.0.Final</version>
<exclusions>
<exclusion>
<artifactId>jconsole</artifactId>
<groupId>sun.jdk</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-clustering-singleton</artifactId>
<version>8.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.api</groupId>
<artifactId>openstack-keystone</artifactId>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment