Search in sources :

Example 1 with PersistenceConfigurationBuilder

use of org.infinispan.configuration.cache.PersistenceConfigurationBuilder in project infinispan by infinispan.

the class TargetStoreFactory method getInitializedStoreBuilder.

private static StoreConfigurationBuilder getInitializedStoreBuilder(StoreProperties props) {
    PersistenceConfigurationBuilder persistenceBuilder = new ConfigurationBuilder().persistence();
    StoreType storeType = StoreType.valueOf(props.get(TYPE).toUpperCase());
    switch(storeType) {
        case LEVELDB:
        case JDBC_BINARY:
        case JDBC_MIXED:
            throw new CacheConfigurationException(String.format("%s cannot be a target store as it no longer exists", storeType));
        case JDBC_STRING:
            return JdbcConfigurationUtil.configureStore(props, new JdbcStringBasedStoreConfigurationBuilder(persistenceBuilder));
        case ROCKSDB:
            props.required(LOCATION);
            String location = props.get(LOCATION);
            RocksDBStoreConfigurationBuilder builder = new RocksDBStoreConfigurationBuilder(persistenceBuilder);
            builder.location(location).expiredLocation(location + "-expired-");
            String compressionType = props.get(COMPRESSION);
            if (compressionType != null)
                builder.compressionType(CompressionType.valueOf(compressionType.toUpperCase()));
            return builder;
        case SINGLE_FILE_STORE:
            props.required(LOCATION);
            return new SingleFileStoreConfigurationBuilder(persistenceBuilder).location(props.get(LOCATION));
        case SOFT_INDEX_FILE_STORE:
            props.required(LOCATION);
            props.required(INDEX_LOCATION);
            return new SoftIndexFileStoreConfigurationBuilder(persistenceBuilder).dataLocation(props.get(LOCATION)).indexLocation(props.get(INDEX_LOCATION));
        default:
            throw new CacheConfigurationException(String.format("Unknown store type '%s'", storeType));
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) SoftIndexFileStoreConfigurationBuilder(org.infinispan.persistence.sifs.configuration.SoftIndexFileStoreConfigurationBuilder) StoreConfigurationBuilder(org.infinispan.configuration.cache.StoreConfigurationBuilder) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) RocksDBStoreConfigurationBuilder(org.infinispan.persistence.rocksdb.configuration.RocksDBStoreConfigurationBuilder) SingleFileStoreConfigurationBuilder(org.infinispan.configuration.cache.SingleFileStoreConfigurationBuilder) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) RocksDBStoreConfigurationBuilder(org.infinispan.persistence.rocksdb.configuration.RocksDBStoreConfigurationBuilder) SoftIndexFileStoreConfigurationBuilder(org.infinispan.persistence.sifs.configuration.SoftIndexFileStoreConfigurationBuilder) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) JdbcStringBasedStoreConfigurationBuilder(org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder) SingleFileStoreConfigurationBuilder(org.infinispan.configuration.cache.SingleFileStoreConfigurationBuilder)

Example 2 with PersistenceConfigurationBuilder

use of org.infinispan.configuration.cache.PersistenceConfigurationBuilder in project xwiki-commons by xwiki.

the class InfinispanConfigurationLoader method completeFilesystem.

/**
 * Add missing location for filesystem based cache.
 *
 * @param builder the configuration builder
 * @param configuration the configuration
 */
private void completeFilesystem(ConfigurationBuilder builder, Configuration configuration) {
    PersistenceConfigurationBuilder persistence = builder.persistence();
    if (containsIncompleteFileLoader(configuration)) {
        for (StoreConfigurationBuilder<?, ?> store : persistence.stores()) {
            if (store instanceof SingleFileStoreConfigurationBuilder) {
                SingleFileStoreConfigurationBuilder singleFileStore = (SingleFileStoreConfigurationBuilder) store;
                singleFileStore.location(createTempDir());
            }
        }
    }
}
Also used : PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) SingleFileStoreConfigurationBuilder(org.infinispan.configuration.cache.SingleFileStoreConfigurationBuilder)

Example 3 with PersistenceConfigurationBuilder

use of org.infinispan.configuration.cache.PersistenceConfigurationBuilder in project infinispan by infinispan.

the class ClassLoaderManagerDisablingTest method testDisableWithMultipleStores.

public void testDisableWithMultipleStores() {
    ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(false);
    PersistenceConfigurationBuilder p = builder.persistence();
    p.addStore(DummyInMemoryStoreConfigurationBuilder.class).fetchPersistentState(true);
    // Just add this one as it is simple and we need different types
    p.addStore(UnnecessaryLoadingTest.CountingStoreConfigurationBuilder.class);
    EmbeddedCacheManager cacheManager = null;
    try {
        cacheManager = TestCacheManagerFactory.createCacheManager(builder);
        Cache<Object, Object> cache = cacheManager.getCache();
        PersistenceManager pm = TestingUtil.extractComponent(cache, PersistenceManager.class);
        // Get all types of stores
        Set<Object> stores = pm.getStores(Object.class);
        // Should have 2 before we disable
        assertEquals(2, stores.size());
        pm.disableStore(UnnecessaryLoadingTest.CountingStore.class.getName());
        stores = pm.getStores(Object.class);
        assertEquals(1, stores.size());
        DummyInMemoryStore store = (DummyInMemoryStore) stores.iterator().next();
        assertTrue(store.getConfiguration().fetchPersistentState());
    } finally {
        TestingUtil.killCacheManagers(cacheManager);
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) DummyInMemoryStoreConfigurationBuilder(org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 4 with PersistenceConfigurationBuilder

use of org.infinispan.configuration.cache.PersistenceConfigurationBuilder in project infinispan by infinispan.

the class CacheParser method parseFileStore.

protected void parseFileStore(ConfigurationReader reader, ConfigurationBuilderHolder holder) {
    SoftIndexFileStoreConfigurationBuilder fileStoreBuilder = null;
    PersistenceConfigurationBuilder persistence = holder.getCurrentConfigurationBuilder().persistence();
    AbstractStoreConfigurationBuilder<?, ?> actualStoreConfig;
    int majorSchema = reader.getSchema().getMajor();
    boolean legacyFileStore = false;
    if (majorSchema < 13) {
        parseSingleFileStore(reader, holder);
        return;
    } else if (majorSchema == 13) {
        fileStoreBuilder = persistence.addStore(SFSToSIFSConfigurationBuilder.class);
        actualStoreConfig = fileStoreBuilder;
        legacyFileStore = true;
    } else {
        fileStoreBuilder = persistence.addSoftIndexFileStore();
        actualStoreConfig = fileStoreBuilder;
    }
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String value = reader.getAttributeValue(i);
        Attribute attribute = Attribute.forName(reader.getAttributeName(i));
        switch(attribute) {
            case RELATIVE_TO:
                {
                    if (reader.getSchema().since(11, 0))
                        throw ParseUtils.attributeRemoved(reader, i);
                    ignoreAttribute(reader, i);
                    break;
                }
            case PATH:
                {
                    fileStoreBuilder.dataLocation(value);
                    fileStoreBuilder.indexLocation(value);
                    break;
                }
            case FRAGMENTATION_FACTOR:
            case MAX_ENTRIES:
                {
                    if (legacyFileStore) {
                        ignoreAttribute(reader, i);
                    } else {
                        throw ParseUtils.attributeRemoved(reader, i);
                    }
                    break;
                }
            case OPEN_FILES_LIMIT:
                if (fileStoreBuilder != null) {
                    fileStoreBuilder.openFilesLimit(Integer.parseInt(value));
                } else {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                }
                break;
            case COMPACTION_THRESHOLD:
                if (fileStoreBuilder != null) {
                    fileStoreBuilder.compactionThreshold(Double.parseDouble(value));
                } else {
                    throw ParseUtils.unexpectedAttribute(reader, i);
                }
                break;
            case PURGE:
                {
                    actualStoreConfig.purgeOnStartup(Boolean.parseBoolean(value));
                    break;
                }
            default:
                {
                    parseStoreAttribute(reader, i, actualStoreConfig);
                }
        }
    }
    while (reader.inTag()) {
        Element element = Element.forName(reader.getLocalName());
        switch(element) {
            case DATA:
                if (fileStoreBuilder != null) {
                    parseData(reader, fileStoreBuilder);
                } else {
                    throw ParseUtils.unexpectedElement(reader);
                }
                break;
            case INDEX:
                if (fileStoreBuilder != null) {
                    parseIndex(reader, fileStoreBuilder);
                } else {
                    throw ParseUtils.unexpectedElement(reader);
                }
                break;
            default:
                parseStoreElement(reader, actualStoreConfig);
        }
    }
}
Also used : SoftIndexFileStoreConfigurationBuilder(org.infinispan.persistence.sifs.configuration.SoftIndexFileStoreConfigurationBuilder) ParseUtils.ignoreAttribute(org.infinispan.configuration.parsing.ParseUtils.ignoreAttribute) ParseUtils.ignoreElement(org.infinispan.configuration.parsing.ParseUtils.ignoreElement) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder)

Example 5 with PersistenceConfigurationBuilder

use of org.infinispan.configuration.cache.PersistenceConfigurationBuilder in project meveo by meveo-org.

the class CachesInitializer method init.

@PostConstruct
protected void init() {
    try {
        InitialContext initialContext = new InitialContext();
        cacheContainer = (EmbeddedCacheManager) initialContext.lookup("java:jboss/infinispan/container/meveo");
    } catch (Exception e) {
        log.error("Cannot instantiate cache container", e);
    }
    log.info("Initializing ontology caches");
    PersistenceConfigurationBuilder confBuilder = new ConfigurationBuilder().persistence().passivation(false);
    Configuration configuration = confBuilder.build();
    if (!cacheContainer.cacheExists(CustomFieldsCacheContainerProvider.MEVEO_CFT_CACHE)) {
        cacheContainer.defineConfiguration(CustomFieldsCacheContainerProvider.MEVEO_CFT_CACHE, configuration);
    }
    if (!cacheContainer.cacheExists(CustomFieldsCacheContainerProvider.MEVEO_CET_CACHE)) {
        cacheContainer.defineConfiguration(CustomFieldsCacheContainerProvider.MEVEO_CET_CACHE, configuration);
    }
    if (!cacheContainer.cacheExists(CustomFieldsCacheContainerProvider.MEVEO_CRT_CACHE)) {
        cacheContainer.defineConfiguration(CustomFieldsCacheContainerProvider.MEVEO_CRT_CACHE, configuration);
    }
    log.info("Finished initializing ontology caches");
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) SingleFileStoreConfigurationBuilder(org.infinispan.configuration.cache.SingleFileStoreConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration) PersistenceConfigurationBuilder(org.infinispan.configuration.cache.PersistenceConfigurationBuilder) InitialContext(javax.naming.InitialContext) PostConstruct(javax.annotation.PostConstruct)

Aggregations

PersistenceConfigurationBuilder (org.infinispan.configuration.cache.PersistenceConfigurationBuilder)5 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 SingleFileStoreConfigurationBuilder (org.infinispan.configuration.cache.SingleFileStoreConfigurationBuilder)3 SoftIndexFileStoreConfigurationBuilder (org.infinispan.persistence.sifs.configuration.SoftIndexFileStoreConfigurationBuilder)2 PostConstruct (javax.annotation.PostConstruct)1 InitialContext (javax.naming.InitialContext)1 CacheConfigurationException (org.infinispan.commons.CacheConfigurationException)1 Configuration (org.infinispan.configuration.cache.Configuration)1 StoreConfigurationBuilder (org.infinispan.configuration.cache.StoreConfigurationBuilder)1 ParseUtils.ignoreAttribute (org.infinispan.configuration.parsing.ParseUtils.ignoreAttribute)1 ParseUtils.ignoreElement (org.infinispan.configuration.parsing.ParseUtils.ignoreElement)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 DummyInMemoryStore (org.infinispan.persistence.dummy.DummyInMemoryStore)1 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)1 JdbcStringBasedStoreConfigurationBuilder (org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder)1 PersistenceManager (org.infinispan.persistence.manager.PersistenceManager)1 RocksDBStoreConfigurationBuilder (org.infinispan.persistence.rocksdb.configuration.RocksDBStoreConfigurationBuilder)1