Search in sources :

Example 16 with DefaultCacheManager

use of org.infinispan.manager.DefaultCacheManager in project camel by apache.

the class InfinispanIdempotentRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    basicCacheContainer = new DefaultCacheManager(GLOBAL_CONFIGURATION);
    basicCacheContainer.start();
    idempotentRepository = InfinispanIdempotentRepository.infinispanIdempotentRepository(basicCacheContainer, cacheName);
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) Before(org.junit.Before)

Example 17 with DefaultCacheManager

use of org.infinispan.manager.DefaultCacheManager 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);
}
Also used : ValueDependency(org.wildfly.clustering.service.ValueDependency) Service(org.jboss.msc.service.Service) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) InfinispanBatcherFactory(org.jboss.as.clustering.infinispan.InfinispanBatcherFactory) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CacheStoppedEvent(org.infinispan.notifications.cachemanagerlistener.event.CacheStoppedEvent) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) ALIASES(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute.ALIASES) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) OperationContext(org.jboss.as.controller.OperationContext) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) InfinispanLogger(org.jboss.as.clustering.infinispan.InfinispanLogger) InfinispanRequirement(org.wildfly.clustering.infinispan.spi.InfinispanRequirement) CacheStopped(org.infinispan.notifications.cachemanagerlistener.annotation.CacheStopped) CacheStartedEvent(org.infinispan.notifications.cachemanagerlistener.event.CacheStartedEvent) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) ServiceTarget(org.jboss.msc.service.ServiceTarget) LinkedList(java.util.LinkedList) BatcherFactory(org.jboss.as.clustering.infinispan.BatcherFactory) BasicCacheContainer(org.infinispan.commons.api.BasicCacheContainer) Listener(org.infinispan.notifications.Listener) CONTAINER(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Capability.CONTAINER) PathAddress(org.jboss.as.controller.PathAddress) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ResourceServiceBuilder(org.jboss.as.clustering.controller.ResourceServiceBuilder) Consumer(java.util.function.Consumer) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) CacheStarted(org.infinispan.notifications.cachemanagerlistener.annotation.CacheStarted) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) DEFAULT_CACHE(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute.DEFAULT_CACHE) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) DefaultCacheContainer(org.jboss.as.clustering.infinispan.DefaultCacheContainer) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) BasicCacheContainer(org.infinispan.commons.api.BasicCacheContainer) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Example 18 with DefaultCacheManager

use of org.infinispan.manager.DefaultCacheManager in project indy by Commonjava.

the class CacheProducer method start.

@PostConstruct
public void start() {
    // FIXME This is just here to trigger shutdown hook init for embedded log4j in infinispan-embedded-query.
    // FIXES:
    //
    // Thread-15 ERROR Unable to register shutdown hook because JVM is shutting down.
    // java.lang.IllegalStateException: Cannot add new shutdown hook as this is not started. Current state: STOPPED
    //
    new MarshallableTypeHints().getBufferSizePredictor(CacheHandle.class);
    File confDir = indyConfiguration.getIndyConfDir();
    File ispnConf = new File(confDir, ISPN_XML);
    String configuration;
    if (ispnConf.exists()) {
        try {
            configuration = FileUtils.readFileToString(ispnConf);
        } catch (IOException e) {
            throw new RuntimeException("Cannot read infinispan configuration from file: " + ispnConf, e);
        }
    } else {
        try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(ISPN_XML)) {
            configuration = IOUtils.toString(stream);
        } catch (IOException e) {
            throw new RuntimeException("Cannot read infinispan configuration from classpath: " + ISPN_XML, e);
        }
    }
    StringSearchInterpolator interpolator = new StringSearchInterpolator();
    interpolator.addValueSource(new PropertiesBasedValueSource(System.getProperties()));
    try {
        configuration = interpolator.interpolate(configuration);
    } catch (InterpolationException e) {
        throw new RuntimeException("Cannot resolve expressions in infinispan configuration.", e);
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("Using Infinispan configuration:\n\n{}\n\n", configuration);
    try {
        cacheManager = new DefaultCacheManager(new ByteArrayInputStream(configuration.getBytes(StandardCharsets.UTF_8)));
    } catch (IOException e) {
        throw new RuntimeException("Cannot read infinispan configuration.", e);
    }
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) StringSearchInterpolator(org.codehaus.plexus.interpolation.StringSearchInterpolator) MarshallableTypeHints(org.infinispan.commons.marshall.MarshallableTypeHints) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) Logger(org.slf4j.Logger) File(java.io.File) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource) PostConstruct(javax.annotation.PostConstruct)

Aggregations

DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)18 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 BeforeClass (org.junit.BeforeClass)5 Before (org.junit.Before)4 File (java.io.File)3 InputStream (java.io.InputStream)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 WeakReference (java.lang.ref.WeakReference)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 PostConstruct (javax.annotation.PostConstruct)1