Skip to content

Commit

Permalink
The HA Singleton TimerService provider should be made vendor-neutral …
Browse files Browse the repository at this point in the history
…eventually, so renamed as such.
  • Loading branch information
peteroyle committed May 12, 2015
1 parent 3aa0600 commit 3126487
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.seam.cron</groupId>
<artifactId>seam-cron-scheduling-timerservice-jboss-ha-singleton</artifactId>
<artifactId>seam-cron-scheduling-timerservice-ha-singleton</artifactId>
<packaging>jar</packaging>
<version>3.1.1-SNAPSHOT</version>
<name>Seam Cron Scheduling Provider: Java EE Timer Service - JBoss HA Singleton</name>
<description>The Java EE Timer Service provider of scheduling for Seam Cron.</description>
<name>Seam Cron Scheduling Provider: Java EE Timer Service - HA Singleton</name>
<description>The Java EE Timer Service scheduling provider for Seam Cron, HA Singleton version.</description>
<url>http://seamframework.org/Seam3/CronModule</url>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,56 @@
package org.jboss.as.quickstarts.cluster.hasingleton.service.ejb;

import org.jboss.as.clustering.singleton.SingletonService;
import org.jboss.as.clustering.singleton.election.NamePreference;
import org.jboss.as.clustering.singleton.election.PreferredSingletonElectionPolicy;
import org.jboss.as.clustering.singleton.election.SimpleSingletonElectionPolicy;
import org.jboss.logging.Logger;
import org.jboss.msc.service.DelegatingServiceContainer;
import org.jboss.msc.service.ServiceActivator;
import org.jboss.msc.service.ServiceActivatorContext;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;

/**
* Service activator that installs the HATimerService as a clustered singleton service
* during deployment.
* Service activator that installs the HATimerService as a clustered singleton service during deployment.
*
* @author Paul Ferraro
* @author Wolf-Dieter Fink
*/
public class HATimerServiceActivator implements ServiceActivator {

private final Logger log = Logger.getLogger(this.getClass());

@Override
public void activate(ServiceActivatorContext context) {
log.info("HATimerService will be installed!");
log.info("JBoss HATimerServiceActivator activating. HATimerService will be installed as JBoss HA Singleton.");

log.info("Locating JBoss HA Singleton Service");
final ServiceController<?> haSingletonService = context.getServiceRegistry().getService(ServiceName.JBOSS.append("cluster",
"singleton"));
if (haSingletonService != null) {
log.info("Found JBoss HA Singleton Service");
HATimerService service = new HATimerService();
SingletonService<String> singleton = new SingletonService<String>(service, HATimerService.SINGLETON_SERVICE_NAME);
/*
* The NamePreference is a combination of the node name (-Djboss.node.name) and the name of
* the configured cache "singleton". If there is more than 1 node, it is possible to add more than
* one name and the election will use the first available node in that list.
* - To pass a chain of election policies to the singleton and tell JGroups to run the
* singleton on a node with a particular name, uncomment the first line and
* comment the second line below.
* - To pass a list of more than one node, comment the first line and uncomment the
* second line below.
*/
// singleton.setElectionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference(
// "node1/singleton")));
// singleton.setElectionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference("node1/singleton"), new NamePreference("node2/singleton")));

HATimerService service = new HATimerService();
SingletonService<String> singleton = new SingletonService<String>(service, HATimerService.SINGLETON_SERVICE_NAME);
/*
* The NamePreference is a combination of the node name (-Djboss.node.name) and the name of
* the configured cache "singleton". If there is more than 1 node, it is possible to add more than
* one name and the election will use the first available node in that list.
* - To pass a chain of election policies to the singleton and tell JGroups to run the
* singleton on a node with a particular name, uncomment the first line and
* comment the second line below.
* - To pass a list of more than one node, comment the first line and uncomment the
* second line below.
*/
singleton.setElectionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference("node1/singleton")));
//singleton.setElectionPolicy(new PreferredSingletonElectionPolicy(new SimpleSingletonElectionPolicy(), new NamePreference("node1/singleton"), new NamePreference("node2/singleton")));
log.info("Installing HATimerService using JBoss HA Singleton Service");
singleton.build(new DelegatingServiceContainer(context.getServiceTarget(), context.getServiceRegistry()))
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
} else {
log.warn("JBoss ServiceActivator was activated, but the JBoss HA Singleton Service could not be located. "
+ "Cron TimerService will be deployed in NON-HA-SINGLETON mode.");
}

singleton.build(new DelegatingServiceContainer(context.getServiceTarget(), context.getServiceRegistry()))
.setInitialMode(ServiceController.Mode.ACTIVE)
.install()
;
}
}

0 comments on commit 3126487

Please sign in to comment.