Skip to content

Instantly share code, notes, and snippets.

@Ladicek
Created November 29, 2018 11:22
Show Gist options
  • Save Ladicek/3278f7af048c83a8620d84f87525bca6 to your computer and use it in GitHub Desktop.
Save Ladicek/3278f7af048c83a8620d84f87525bca6 to your computer and use it in GitHub Desktop.
package org.wildfly.swarm.infinispan.runtime;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceActivator;
import org.jboss.msc.service.ServiceActivatorContext;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistryException;
/**
* Activator to force a cache to start prior to deployment.
* Created by bob on 8/15/17.
*/
public class CacheActivator implements ServiceActivator {
// for WildFly 11, it was enough to add an artificial dependency
// on org.wildfly.clustering.infinispan.cache-container-configuration.<cache container>,
// because the Infinispan services were actually always started (albeit in a passive mode)
//
// since WildFly 14, we need to add an artificial dependency
// on org.wildfly.clustering.infinispan.default-cache.<cache container>,
// because the Infinispan services are now only started on demand
private ServiceName BASE = ServiceName.parse("org.wildfly.clustering.infinispan.default-cache");
public CacheActivator(String cacheContainerName) {
this.cacheContainerName = cacheContainerName;
}
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
ServiceBuilder<?> builder = context.getServiceTarget()
.addService(BASE.append(this.cacheContainerName).append("activator"));
builder.requires(BASE.append(this.cacheContainerName));
builder
.setInstance(Service.NULL)
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
}
private final String cacheContainerName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment