Search in sources :

Example 11 with ConfigurableCacheFactory

use of com.tangosol.net.ConfigurableCacheFactory in project coherence-hibernate by coherence-community.

the class CoherenceRegionFactory method start.

// ---- interface org.hibernate.cache.spi.RegionFactory
/**
 * {@inheritDoc}
 */
@Override
public void start(SessionFactoryOptions options, Properties properties) throws CacheException {
    this.sessionFactoryOptions = options;
    if (this.sessionFactoryOptions != null) {
        StrategySelector selector = this.sessionFactoryOptions.getServiceRegistry().getService(StrategySelector.class);
        this.cacheKeysFactory = selector.resolveDefaultableStrategy(CacheKeysFactory.class, properties.get(Environment.CACHE_KEYS_FACTORY), new DefaultCacheKeysFactory());
    } else {
        this.cacheKeysFactory = new DefaultCacheKeysFactory();
    }
    CacheFactory.ensureCluster();
    String cacheConfigFilePath = (properties == null) ? null : properties.getProperty(CACHE_CONFIG_FILE_PATH_PROPERTY_NAME);
    if (cacheConfigFilePath == null) {
        cacheConfigFilePath = System.getProperty(CACHE_CONFIG_FILE_PATH_PROPERTY_NAME, DEFAULT_CACHE_CONFIG_FILE_PATH);
    }
    ConfigurableCacheFactory factory = CacheFactory.getCacheFactoryBuilder().getConfigurableCacheFactory(cacheConfigFilePath, getClass().getClassLoader());
    setConfigurableCacheFactory(factory);
    debugMessageSeverityLevel = Integer.getInteger(DEBUG_MESSAGE_SEVERITY_LEVEL_PROPERTY_NAME, DEFAULT_DEBUG_MESSAGE_SEVERITY_LEVEL);
    dumpStackOnDebugMessage = Boolean.getBoolean(DUMP_STACK_ON_DEBUG_MESSAGE_PROPERTY_NAME);
    debugf("%s.start(%s, %s)", this, options, properties);
}
Also used : CacheKeysFactory(org.hibernate.cache.spi.CacheKeysFactory) DefaultCacheKeysFactory(org.hibernate.cache.internal.DefaultCacheKeysFactory) DefaultCacheKeysFactory(org.hibernate.cache.internal.DefaultCacheKeysFactory) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector) ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory)

Example 12 with ConfigurableCacheFactory

use of com.tangosol.net.ConfigurableCacheFactory in project oracle-bedrock by coherence-community.

the class StorageDisabledMember method build.

@Override
public ConfigurableCacheFactory build(LocalPlatform platform, CoherenceCluster cluster, OptionsByType optionsByType) {
    // ----- establish the diagnostics output table -----
    Table diagnosticsTable = new Table();
    diagnosticsTable.getOptions().add(Table.orderByColumn(0));
    // establish a new set of options based on those provided
    optionsByType = OptionsByType.of(optionsByType);
    // ----- establish the options for launching a local storage-disabled member -----
    optionsByType.add(RoleName.of("client"));
    optionsByType.add(LocalStorage.disabled());
    optionsByType.addIfAbsent(CacheConfig.of("coherence-cache-config.xml"));
    // ----- notify the Profiles that we're about to launch an application -----
    MetaClass<CoherenceClusterMember> metaClass = new CoherenceClusterMember.MetaClass();
    for (Profile profile : optionsByType.getInstancesOf(Profile.class)) {
        profile.onLaunching(platform, metaClass, optionsByType);
    }
    // ----- create local system properties based on those defined by the launch options -----
    // modify the current system properties to include/override those in the schema
    com.oracle.bedrock.runtime.java.options.SystemProperties systemProperties = optionsByType.get(com.oracle.bedrock.runtime.java.options.SystemProperties.class);
    Properties properties = systemProperties.resolve(platform, optionsByType);
    Table systemPropertiesTable = new Table();
    systemPropertiesTable.getOptions().add(Table.orderByColumn(0));
    systemPropertiesTable.getOptions().add(Cell.Separator.of(""));
    systemPropertiesTable.getOptions().add(Cell.DisplayNull.asEmptyString());
    for (String propertyName : properties.stringPropertyNames()) {
        String propertyValue = properties.getProperty(propertyName);
        systemPropertiesTable.addRow(propertyName + (System.getProperties().containsKey(propertyName) ? "*" : ""), propertyValue);
        System.setProperty(propertyName, propertyValue.isEmpty() ? "" : propertyValue);
    }
    diagnosticsTable.addRow("System Properties", systemPropertiesTable.toString());
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.log(Level.INFO, "Oracle Bedrock " + Bedrock.getVersion() + ": Starting Storage Disabled Member...\n" + "------------------------------------------------------------------------\n" + diagnosticsTable.toString() + "\n" + "------------------------------------------------------------------------\n");
    }
    // ----- establish the session -----
    // create the session
    ConfigurableCacheFactory session = new ScopedCacheFactoryBuilder().getConfigurableCacheFactory(optionsByType.get(CacheConfig.class).getUri(), getClass().getClassLoader());
    // as this is a cluster member we have to join the cluster
    CacheFactory.ensureCluster();
    return session;
}
Also used : Table(com.oracle.bedrock.table.Table) Properties(java.util.Properties) ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) Profile(com.oracle.bedrock.runtime.Profile) ScopedCacheFactoryBuilder(com.tangosol.net.ScopedCacheFactoryBuilder) CoherenceClusterMember(com.oracle.bedrock.runtime.coherence.CoherenceClusterMember) MetaClass(com.oracle.bedrock.runtime.MetaClass)

Example 13 with ConfigurableCacheFactory

use of com.tangosol.net.ConfigurableCacheFactory in project oracle-bedrock by coherence-community.

the class CoherenceClusterResourceTest method shouldCreateExtendClientSession.

/**
 * Ensure that a {@link ExtendClient} session can be created against the {@link CoherenceClusterResource}.
 */
@Test
public void shouldCreateExtendClientSession() {
    ConfigurableCacheFactory session = coherenceResource.createSession(SessionBuilders.extendClient("proxy-cache-config.xml"));
    NamedCache cache = session.ensureCache("dist-example", null);
    Assert.assertThat(coherenceResource.getCluster().getClusterSize(), is(3));
    cache.put("message", "hello world");
    Eventually.assertThat(invoking(coherenceResource.getCluster().getCache("dist-example")).get("message"), is((Object) "hello world"));
}
Also used : ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) NamedCache(com.tangosol.net.NamedCache) Test(org.junit.Test)

Example 14 with ConfigurableCacheFactory

use of com.tangosol.net.ConfigurableCacheFactory in project oracle-bedrock by coherence-community.

the class CoherenceClusterResource method createSession.

/**
 * Obtains a session, represented as a {@link ConfigurableCacheFactory}, against the {@link CoherenceCluster}.
 * <p>
 * Only a single session may be created by a {@link CoherenceClusterResource} against the {@link CoherenceCluster}.
 * <p>
 * Attempts to request a session multiple times with the same {@link SessionBuilder} will return the same session.
 *
 * @param builder the builder for the specific type of session
 *
 * @return a {@link ConfigurableCacheFactory} representing the Coherence Session.
 *
 * @throws IllegalStateException when an attempt to request sessions for
 *                               different {@link SessionBuilder}s is made
 */
public synchronized ConfigurableCacheFactory createSession(SessionBuilder builder) {
    // restore the system properties (as the session needs to start cleanly)
    com.oracle.bedrock.util.SystemProperties.replaceWith(systemProperties);
    ConfigurableCacheFactory session = sessions.get(builder);
    if (session == null) {
        OptionsByType optionsByType = OptionsByType.of(commonOptionsByType);
        optionsByType.add(RoleName.of("client"));
        optionsByType.add(LocalStorage.disabled());
        session = builder.build(LocalPlatform.get(), getCluster(), optionsByType);
        sessions.put(builder, session);
    }
    return session;
}
Also used : ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) OptionsByType(com.oracle.bedrock.OptionsByType)

Example 15 with ConfigurableCacheFactory

use of com.tangosol.net.ConfigurableCacheFactory in project oracle-bedrock by coherence-community.

the class CoherenceClusterExtensionTest method shouldPerformRollingRestartWithStorageDisabledSession.

/**
 * Ensure that a {@link CoherenceClusterResource} can be used to perform a rolling restart
 * when there's a storage disabled session.
 */
@Test
public void shouldPerformRollingRestartWithStorageDisabledSession() throws Exception {
    CoherenceCluster cluster = coherenceResource.getCluster();
    ConfigurableCacheFactory cacheFactory = coherenceResource.createSession(new StorageDisabledMember());
    // only restart storage enabled members
    cluster.filter(member -> member.getName().startsWith("storage")).relaunch();
    CoherenceClusterMember member1 = cluster.get("storage-1");
    CoherenceClusterMember member2 = cluster.get("storage-2");
    assertThat(member1, is(notNullValue()));
    assertThat(member2, is(notNullValue()));
}
Also used : LocalPlatform(com.oracle.bedrock.runtime.LocalPlatform) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) CoherenceClusterMember(com.oracle.bedrock.runtime.coherence.CoherenceClusterMember) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Set(java.util.Set) com.oracle.bedrock.runtime.coherence.options(com.oracle.bedrock.runtime.coherence.options) SystemProperty(com.oracle.bedrock.runtime.java.options.SystemProperty) CoherenceCluster(com.oracle.bedrock.runtime.coherence.CoherenceCluster) Capture(com.oracle.bedrock.util.Capture) TreeSet(java.util.TreeSet) DeferredHelper.invoking(com.oracle.bedrock.deferred.DeferredHelper.invoking) Test(org.junit.jupiter.api.Test) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Is.is(org.hamcrest.core.Is.is) DisplayName(com.oracle.bedrock.runtime.options.DisplayName) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) Eventually(com.oracle.bedrock.testsupport.deferred.Eventually) NamedCache(com.tangosol.net.NamedCache) CoherenceClusterMember(com.oracle.bedrock.runtime.coherence.CoherenceClusterMember) CoherenceCluster(com.oracle.bedrock.runtime.coherence.CoherenceCluster) ConfigurableCacheFactory(com.tangosol.net.ConfigurableCacheFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurableCacheFactory (com.tangosol.net.ConfigurableCacheFactory)19 NamedCache (com.tangosol.net.NamedCache)7 CoherenceClusterMember (com.oracle.bedrock.runtime.coherence.CoherenceClusterMember)4 Test (org.junit.jupiter.api.Test)4 OptionsByType (com.oracle.bedrock.OptionsByType)3 Test (org.junit.Test)3 DeferredHelper.invoking (com.oracle.bedrock.deferred.DeferredHelper.invoking)2 LocalPlatform (com.oracle.bedrock.runtime.LocalPlatform)2 MetaClass (com.oracle.bedrock.runtime.MetaClass)2 Profile (com.oracle.bedrock.runtime.Profile)2 CoherenceCluster (com.oracle.bedrock.runtime.coherence.CoherenceCluster)2 SystemProperty (com.oracle.bedrock.runtime.java.options.SystemProperty)2 DisplayName (com.oracle.bedrock.runtime.options.DisplayName)2 Table (com.oracle.bedrock.table.Table)2 Eventually (com.oracle.bedrock.testsupport.deferred.Eventually)2 Capture (com.oracle.bedrock.util.Capture)2 ScopedCacheFactoryBuilder (com.tangosol.net.ScopedCacheFactoryBuilder)2 Properties (java.util.Properties)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2