Last active
December 25, 2015 07:39
-
-
Save rmjacobs/6941244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.day.cq.jcrclustersupport.ClusterAware; | |
import org.apache.felix.scr.annotations.Component; | |
import org.apache.felix.scr.annotations.Properties; | |
import org.apache.felix.scr.annotations.Property; | |
import org.apache.felix.scr.annotations.Service; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
@Component(immediate = true, metatype = true, label = "Periodic Job", description = "Does something on a schedule") | |
@Service | |
@Properties({ | |
@Property(name = "service.vendor", value = "CSG"), | |
@Property(name = "service.description", value = "Does stuff periodically"), | |
@Property(name = "scheduler.expression", value = "0 * * * * ?") | |
}) | |
public class MyClusterAwareService implements Runnable, ClusterAware { | |
private boolean isMaster; | |
Logger log = LoggerFactory.getLogger(this.getClass()); | |
@Override | |
public void bindRepository(String repositoryId, String clusterId, boolean isMaster) { | |
log.info("A new repository has been bound:" + repositoryId + "; clusterid:" + clusterId); | |
this.isMaster = isMaster; | |
} | |
@Override | |
public void unbindRepository() { | |
//do something useful here... | |
} | |
public void run() { | |
if (isMaster) { | |
log.info("I am the master and will do my task."); | |
//Do your task here. | |
} else { | |
log.info("I am the slave and will not do anything."); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment