use of org.jboss.msc.service.Service in project wildfly by wildfly.
the class KeyAffinityServiceFactoryBuilder method build.
@Override
public ServiceBuilder<KeyAffinityServiceFactory> build(ServiceTarget target) {
int bufferSize = this.bufferSize;
Function<ExecutorService, KeyAffinityServiceFactory> mapper = executor -> new KeyAffinityServiceFactory() {
@Override
public <K> KeyAffinityService<K> createService(Cache<K, ?> cache, KeyGenerator<K> generator) {
CacheMode mode = cache.getCacheConfiguration().clustering().cacheMode();
return mode.isDistributed() || mode.isReplicated() ? new KeyAffinityServiceImpl<>(executor, cache, generator, bufferSize, Collections.singleton(cache.getCacheManager().getAddress()), false) : new SimpleKeyAffinityService<>(generator);
}
};
Supplier<ExecutorService> supplier = () -> {
ThreadGroup threadGroup = new ThreadGroup("KeyAffinityService ThreadGroup");
String namePattern = "KeyAffinityService Thread Pool -- %t";
PrivilegedAction<ThreadFactory> action = () -> new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null);
return Executors.newCachedThreadPool(doPrivileged(action));
};
Service<KeyAffinityServiceFactory> service = new SuppliedValueService<>(mapper, supplier, ExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.getServiceName(), service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of org.jboss.msc.service.Service in project wildfly by wildfly.
the class RemoveOnCancelScheduledExecutorServiceBuilder method build.
@Override
public ServiceBuilder<ScheduledExecutorService> build(ServiceTarget target) {
Function<ScheduledExecutorService, ScheduledExecutorService> mapper = executor -> JBossExecutors.protectedScheduledExecutorService(executor);
Supplier<ScheduledExecutorService> supplier = () -> {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.size, this.factory);
executor.setRemoveOnCancelPolicy(true);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
return executor;
};
Service<ScheduledExecutorService> service = new SuppliedValueService<>(mapper, supplier, ScheduledExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.name, service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of org.jboss.msc.service.Service in project wildfly by wildfly.
the class JaxrsSpringProcessor method getResteasySpringVirtualFile.
/**
* Lookup Seam integration resource loader.
*
* @return the Seam integration resource loader
* @throws DeploymentUnitProcessingException
* for any error
*/
protected synchronized VirtualFile getResteasySpringVirtualFile() throws DeploymentUnitProcessingException {
if (resourceRoot != null) {
return resourceRoot;
}
try {
Module module = Module.getBootModuleLoader().loadModule(MODULE);
URL fileUrl = module.getClassLoader().getResource(JAR_LOCATION);
if (fileUrl == null) {
throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
}
File dir = new File(fileUrl.toURI());
File file = null;
for (String jar : dir.list()) {
if (jar.endsWith(".jar")) {
file = new File(dir, jar);
break;
}
}
if (file == null) {
throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
}
VirtualFile vf = VFS.getChild(file.toURI());
final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
Service<Closeable> mountHandleService = new Service<Closeable>() {
public void start(StartContext startContext) throws StartException {
}
public void stop(StopContext stopContext) {
VFSUtils.safeClose(mountHandle);
}
public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
return mountHandle;
}
};
ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SERVICE_NAME), mountHandleService);
builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
resourceRoot = vf;
return resourceRoot;
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
}
use of org.jboss.msc.service.Service in project wildfly by wildfly.
the class ServiceBasedNamingStoreTestCase method bindObject.
private void bindObject(final ServiceName serviceName, final Object value) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
container.addService(serviceName, new Service<ManagedReferenceFactory>() {
public void start(StartContext context) throws StartException {
store.add(serviceName);
latch.countDown();
}
public void stop(StopContext context) {
}
public ManagedReferenceFactory getValue() throws IllegalStateException, IllegalArgumentException {
return new ValueManagedReferenceFactory(Values.immediateValue(value));
}
}).install();
latch.await();
}
use of org.jboss.msc.service.Service in project wildfly by wildfly.
the class CacheContainerBuilder method build.
@Override
public ServiceBuilder<CacheContainer> build(ServiceTarget target) {
Function<EmbeddedCacheManager, CacheContainer> mapper = manager -> new DefaultCacheContainer(this.name, manager, this.defaultCache, this.batcherFactory);
Supplier<EmbeddedCacheManager> supplier = () -> {
GlobalConfiguration config = this.configuration.getValue();
EmbeddedCacheManager manager = new DefaultCacheManager(config, null, false);
manager.addListener(this);
manager.start();
InfinispanLogger.ROOT_LOGGER.debugf("%s cache container started", this.name);
return manager;
};
Consumer<EmbeddedCacheManager> destroyer = manager -> {
manager.stop();
manager.removeListener(this);
InfinispanLogger.ROOT_LOGGER.debugf("%s cache container stopped", this.name);
};
Service<CacheContainer> service = new SuppliedValueService<>(mapper, supplier, destroyer);
ServiceBuilder<CacheContainer> builder = target.addService(this.getServiceName(), service).addAliases(this.aliases.stream().toArray(ServiceName[]::new)).setInitialMode(ServiceController.Mode.PASSIVE);
return this.configuration.register(builder);
}
Aggregations