com.tangosol.coherence.jcache.JCacheExtendNamespace Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of coherence-jcache Show documentation
Show all versions of coherence-jcache Show documentation
Oracle Coherence Community Edition
The newest version!
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
package com.tangosol.coherence.jcache;
import com.oracle.coherence.common.base.Logger;
import com.tangosol.coherence.config.CacheConfig;
import com.tangosol.coherence.config.CacheMapping;
import com.tangosol.coherence.config.Config;
import com.tangosol.coherence.config.ResourceMappingRegistry;
import com.tangosol.coherence.config.ServiceSchemeRegistry;
import com.tangosol.coherence.config.builder.ListBasedAddressProviderBuilder;
import com.tangosol.coherence.config.scheme.LocalScheme;
import com.tangosol.coherence.config.scheme.RemoteCacheScheme;
import com.tangosol.coherence.config.scheme.ServiceScheme;
import com.tangosol.coherence.jcache.common.ContainerHelper;
import com.tangosol.config.ConfigurationException;
import com.tangosol.config.injection.Injector;
import com.tangosol.config.injection.SimpleInjector;
import com.tangosol.config.xml.AbstractNamespaceHandler;
import com.tangosol.config.xml.ProcessingContext;
import com.tangosol.internal.net.service.extend.remote.DefaultRemoteCacheServiceDependencies;
import com.tangosol.internal.net.service.peer.initiator.DefaultTcpInitiatorDependencies;
import com.tangosol.net.events.InterceptorRegistry;
import com.tangosol.run.xml.XmlElement;
import com.tangosol.util.RegistrationBehavior;
import com.tangosol.util.ResourceRegistry;
import java.net.URI;
/**
* A {@link com.tangosol.config.xml.NamespaceHandler} to enable and enhance Coherence-based
* configurations to be used with the Coherence-based JCache Extend implementation
*
* @author bo 2013.11.06
* @author jf 2014.06.12
* @since Coherence 12.2.1
*/
public class JCacheExtendNamespace
extends AbstractNamespaceHandler
{
// ----- NamespaceHandler interface -------------------------------------
/**
*
* {@code
*
*
*
* jcache-partitioned-*
* jcache-extend-tcp
*
*
* jcache-configurations
* jcache-extend-tcp
*
*
*
*
* jcache-extend-tcp
*
*
* JCacheTCPProxyService
* TCPProxyService
*
*
*
*
* 127.0.0.1
* 7574
*
*
*
*
*
*
* }
*
*/
@Override
public void onEndNamespace(ProcessingContext processingContext, XmlElement xmlElement, String s, URI uri)
{
CacheConfig cacheConfig = processingContext.getCookie(CacheConfig.class);
if (cacheConfig == null)
{
throw new ConfigurationException("Can't locate the Coherence Configuration. This only occurs when the "
+ uri + " namespace is used outside of a Coherence Cache Configuration", "Please ensure that the "
+ uri + " is defined with in the scope of a Coherence Cache Configuration");
}
else
{
ResourceRegistry registryResources = processingContext.getResourceRegistry();
ServiceSchemeRegistry registryServices = cacheConfig.getServiceSchemeRegistry();
ResourceMappingRegistry registryCacheMappings = cacheConfig.getMappingRegistry();
// register a jcache-lifecycle-interceptor to enable container activation
// for coherence based jcache implementation. The registration name is used for lookup in junit test
// that validates that interceptor was called.
registryResources.getResource(InterceptorRegistry.class)
.registerEventInterceptor("jcache-lifecycle-interceptor",
new ContainerHelper.JCacheLifecycleInterceptor(),
RegistrationBehavior.ALWAYS);
// we may need to inject some values into our services
Injector injector = new SimpleInjector();
// ---- ensure the cache mapping for the jcache configuration is defined ----
CacheMapping mapping = registryCacheMappings.findCacheMapping(CoherenceBasedCache.JCACHE_CONFIG_CACHE_NAME);
// register a specific non-wildcard mapping for CoherenceBasedCache.JCACHE_CONFIG_CACHE_NAME
if (mapping == null || mapping.usesWildcard())
{
mapping = new CacheMapping(CoherenceBasedCache.JCACHE_CONFIG_CACHE_NAME,
CoherenceBasedCache.JCACHE_EXTEND_SCHEME_NAME);
registryCacheMappings.register(mapping);
}
// ---- ensure the for the jcache local caches is defined ----
schemeService = registryServices.findSchemeBySchemeName(CoherenceBasedCache.JCACHE_LOCAL_SCHEME_NAME);
if (schemeService == null)
{
// construct the LocalScheme
LocalScheme schemeLocal = new LocalScheme();
schemeLocal.setSchemeName(CoherenceBasedCache.JCACHE_LOCAL_SCHEME_NAME);
schemeLocal.setServiceName(CoherenceBasedCache.JCACHE_LOCAL_SERVICE_NAME);
injector.inject(schemeLocal, registryResources);
// register the LocalScheme
registryServices.register(schemeLocal);
}
// ---- ensure the cache mapping for the jcache local caches is defined ----
mapping = registryCacheMappings.findCacheMapping(CoherenceBasedCache.JCACHE_LOCAL_CACHE_NAME_PATTERN);
if (mapping == null)
{
mapping = new CacheMapping(CoherenceBasedCache.JCACHE_LOCAL_CACHE_NAME_PATTERN,
CoherenceBasedCache.JCACHE_LOCAL_SCHEME_NAME);
registryCacheMappings.register(mapping);
}
}
}
}