This discussion is archived
9 Replies Latest reply: Aug 4, 2011 3:39 PM by e.gherardini RSS

Include in cache configuration?

MagnusE Explorer
Currently Being Moderated
I would like to define a "corporate" cache configuration file that later can be included and extended by project cache configuration files. I have seen some hints that this is supported by the Common package in the incubator but I have not seen any examples or documentation about how to do it. I know that I must specify the ExtensibleEnvironment as initialisation handler but what does the XML required look like? Can (should) both the included and the including cache configuration files be complete cache configuration files (verifyable against the XML schema) or should the included file just be a fragment that is legal to include at the point where it is inserted?

Any links or examples are very much appreciated!

Note I am not an XML guru so try to keep the explanation simple and try to provide complete examples not just "snippets" - to get all the new schema XML stuff to just validate without the added complexity of commons name spaces is a challenge to me :-)

/Magnus

Edited by: MagnusE on Jul 13, 2011 6:04 PM
  • 1. Re: Include in cache configuration?
    user738616 Pro
    Currently Being Moderated
    It is used in the Push Replication Example and the XML files are:

    ***** session-cache-config (including the extend-cache-config.xml) ***********

    <?xml version="1.0"?>
    <!DOCTYPE cache-config SYSTEM "cache-config.dtd">
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <!-- -->
    <!-- Cache configuration descriptor for Coherence*Web -->
    <!-- -->
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
    <cache-config
    xmlns:sync="class:com.oracle.coherence.patterns.pushreplication.configuration.PushReplicationNamespaceContentHandler">
    <introduce:config file="extend-cache-config.xml" />
    <caching-scheme-mapping>

    <!--
    The clustered cache used to store Session attributes.
    -->
    <cache-mapping>
    <cache-name>session-storage</cache-name>
    <scheme-name>session-near</scheme-name>
    <sync:publisher>
    <sync:publisher-name>SessionStoragePublisher</sync:publisher-name>
    <sync:publisher-scheme>
    <sync:remote-cluster-publisher-scheme>
    <sync:remote-invocation-service-name>publisher-invocation</sync:remote-invocation-service-name>
    <sync:remote-publisher-scheme>
    <sync:local-cache-publisher-scheme>
    <sync:target-cache-name>session-storage</sync:target-cache-name>
    </sync:local-cache-publisher-scheme>
    </sync:remote-publisher-scheme>
    <sync:autostart>true</sync:autostart>
    </sync:remote-cluster-publisher-scheme>
    </sync:publisher-scheme>
    </sync:publisher>
    </cache-mapping>


    **** extend-cache-config.xml **********
    <?xml version="1.0"?>

    <!DOCTYPE cache-config SYSTEM "cache-config.dtd">
    <cache-config>
    <caching-schemes>

    <remote-invocation-scheme>
    <service-name>publisher-invocation</service-name>
    <initiator-config>
    <tcp-initiator>
    <remote-addresses>
    <socket-address>
    <address>localhost</address>
    <port system-property="client.port">7101</port>
    </socket-address>
    </remote-addresses>
    <connect-timeout>2s</connect-timeout>
    </tcp-initiator>
    <outgoing-message-handler>
    <request-timeout>5s</request-timeout>
    </outgoing-message-handler>
    </initiator-config>
    </remote-invocation-scheme>

    <proxy-scheme>
    <service-name>PublisherProxyService</service-name>
    <acceptor-config>
    <tcp-acceptor>
    <reuse-address>true</reuse-address>
    <local-address>
    <address>localhost</address>
    <port system-property="bind.port">7102</port>
    </local-address>
    </tcp-acceptor>
    </acceptor-config>
    <autostart system-property="proxy.enabled">true</autostart>
    </proxy-scheme>
    </caching-schemes>
    </cache-config>

    Cheers,
    NJ
  • 2. Re: Include in cache configuration?
    MagnusE Explorer
    Currently Being Moderated
    Double post - removed!
  • 3. Re: Include in cache configuration?
    MagnusE Explorer
    Currently Being Moderated
    Thanks for the reply. Have been working on other things for a while but is now back looking at it again. Sadly I cant get my example to work when using your proposal:

    <cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
    xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
    <introduce:config file="scania-cache-config.xml" />

    <caching-scheme-mapping>
    ...
    </caching-scheme-mapping>
    <caching-schemes>
    ...
    </caching-schemes>
    </cache-config>

    Results in:
    2011-08-02 09:24:42.883/1.136 Oracle Coherence GE 3.7.0.0 <Error> (thread=main, member=n/a): Fatal Error org.xml.sax.SAXParseException: The prefix "introduce" for element "introduce:config" is not bound. - line 7
    Exception in thread "main" (Wrapped: Failed to load the factory) (Wrapped: Missing or inaccessible constructor "com.oracle.coherence.environment.extensible.ExtensibleEnvironment(String)"
    <configurable-cache-factory-config>
    <class-name>com.oracle.coherence.environment.extensible.ExtensibleEnvironment</class-name>
    <init-params>
    <init-param>
    <param-type>java.lang.String</param-type>
    <param-value>./lib/project-cache-config.xml</param-value>
    </init-param>
    </init-params>
    </configurable-cache-factory-config>) java.lang.reflect.InvocationTargetException
         at com.tangosol.util.Base.ensureRuntimeException(Base.java:288)
         at com.tangosol.net.ScopedCacheFactoryBuilder.getDefaultFactory(ScopedCacheFactoryBuilder.java:308)
         at com.tangosol.net.DefaultCacheFactoryBuilder.getSingletonFactory(DefaultCacheFactoryBuilder.java:48)
         at com.tangosol.net.DefaultCacheFactoryBuilder.getFactory(DefaultCacheFactoryBuilder.java:121)
         at com.tangosol.net.ScopedCacheFactoryBuilder.getConfigurableCacheFactory(ScopedCacheFactoryBuilder.java:109)
         at com.tangosol.net.CacheFactory.getConfigurableCacheFactory(CacheFactory.java:126)
         at com.tangosol.net.DefaultCacheServer.getDefaultConfigurableCacheFactory(DefaultCacheServer.java:364)
         at com.tangosol.net.DefaultCacheServer.main(DefaultCacheServer.java:197)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
    Caused by: (Wrapped: Missing or inaccessible constructor "com.oracle.coherence.environment.extensible.ExtensibleEnvironment(String)"

    When I instead tried:

    <cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
    xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
    <introduce-cache-config file="scania-cache-config.xml"/>
    <caching-scheme-mapping>
    ...
    </caching-scheme-mapping>
    <caching-schemes>
    ...
    </caching-schemes>
    </cache-config>

    It seems to work (i.e. Coherence reports that the extensible environment is used and that the cache config file has been read) - I have not verified that the cache definitions are correct yet though (i.e. that the include REALLY work as expected):

    2011-08-02 09:31:50.730/1.177 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "file:/C:/Javaproj/CoherenceCommon/lib/project-cache-config.xml"

    Using the Incubator Extensible Environment for Coherence Cache Configuration

    What is the difference between the two ways of including and what am I doing wrong in the first case?

    /Magnus

    Edited by: MagnusE on Aug 2, 2011 12:44 PM

    I have now verified that my proposed solution above DOES NOT WORK properly - i.e. the included cache configuration does not take effect properly- it just does not produce any error messages while loading... :-(

    I can also add that my XML-editor (IntelliJ IDEA) does NOT recognize the "introduce:" namespace - what would I need to do in order fix this (once again I am a real XML-newb ...). I assume there is some schema I am supposed to register with the editor but what schema is that?
  • 4. Re: Include in cache configuration?
    user738616 Pro
    Currently Being Moderated
    Hi Magnus,

    I guess the problem is one of the following:

    1. Missing coherence-common jar from the Incubator projects in your cache node classpath
    2. xmlns:introduce="class://com.oracle.coherence.environment.extensible.namespaces.IntroduceNamespaceContentHandler" namespace not configured.

    Here are the steps:

    1. Include coherence-common jar in your cache node classpath
    2. You parent configuration should look like,

    <?xml version="1.0"?>
    <!DOCTYPE cache-config SYSTEM "cache-config.dtd">
    <cache-config xmlns:introduce="class://com.oracle.coherence.environment.extensible.namespaces.IntroduceNamespaceContentHandler">
    <introduce:config file="C:\Oracle\Coherence\Files\IncludeExample\IncludeConfiguration\include-config.xml"/>
    <caching-scheme-mapping>
         <cache-mapping>
              <cache-name>*</cache-name>
              <scheme-name>example-distributed</scheme-name>
         </cache-mapping>
    </caching-scheme-mapping>
    <caching-schemes>
         <!--
    Distributed caching scheme.
    -->
         <distributed-scheme>
              <scheme-name>example-distributed</scheme-name>
              <service-name>DistributedCache</service-name>
              <backing-map-scheme>
                   <local-scheme>
                        <scheme-ref>example-binary-backing-map</scheme-ref>
                   </local-scheme>
              </backing-map-scheme>
              <autostart>true</autostart>                              
         </distributed-scheme>
    </caching-schemes>
    </cache-config>

    If you carefully in the above configuration, there is a reference to "example-binary-backing-map" scheme and now in the child configuration provide this schema reference as below:

    File name: include-config.xml

    <?xml version="1.0"?>

    <!DOCTYPE cache-config SYSTEM "cache-config.dtd">
    <cache-config>
    <caching-schemes>
         <local-scheme>
              <scheme-name>example-binary-backing-map</scheme-name>
              <eviction-policy>HYBRID</eviction-policy>
              <high-units>{back-size-limit 0}</high-units>
              <unit-calculator>BINARY</unit-calculator>
              <expiry-delay>{back-expiry 1h}</expiry-delay>
              <cachestore-scheme></cachestore-scheme>          
         </local-scheme>
    </caching-schemes>
    </cache-config>

    Hope this helps!

    Cheers,
    NJ
  • 5. Re: Include in cache configuration?
    e.gherardini Newbie
    Currently Being Moderated
    Hi user738616,
    I have the same MagnusE problem,
    but in my case I have both the coherence-common jar inside my classpath and both the introduce namespace correctly defined inside my configuration file:

    Here is my cache config file, named "poc-coherence-cache-config.xml":
    <cache-config 
         xmlns:introduce="class://com.oracle.coherence.environment.extensible.namespaces.IntroduceNamespaceContentHandler"
         >
    
         <introduce:config file="coherence-messagingpattern-cache-config.xml"/>
         
         <caching-scheme-mapping>
                ...
         </caching-scheme-mapping>
    
         <caching-schemes>
              ...
         </caching-schemes>
              
      
    </cache-config>
    Which I load using defining the system property to load this override file:"poc-tangosol-coherence-override.xml", which is as follows:
    <?xml version='1.0'?>
    <coherence>
    
         <configurable-cache-factory-config>
              <class-name>com.oracle.coherence.environment.extensible.ExtensibleEnvironment
              </class-name>
              <init-params>
                   <init-param>
                        <param-type>java.lang.String</param-type>
                        <param-value system-property="tangosol.coherence.cacheconfig">
                        poc-coherence-cache-config.xml</param-value>
                   </init-param>
              </init-params>
         </configurable-cache-factory-config>
    
         <cluster-config>
              <member-identity>
                   <cluster-name system-property="tangosol.coherence.cluster">
                        Coherence_PoC_Cluster
                   </cluster-name>
              </member-identity>
              <multicast-listener>
                   <time-to-live system-property="tangosol.coherence.ttl">1</time-to-live>
                   <join-timeout-milliseconds>5000</join-timeout-milliseconds>
                   <address system-property="tangosol.coherence.clusteraddress">239.1.5.0</address> <!-- 224.13.16.10 -->
                   <port system-property="tangosol.coherence.clusterport">3030</port>
              </multicast-listener>
         </cluster-config>
    
         <logging-config>
              <destination system-property="tangosol.coherence.log">log4j</destination>
              <severity-level system-property="tangosol.coherence.log.level">10</severity-level>
              <character-limit system-property="tangosol.coherence.log.limit">0</character-limit>
         </logging-config>
    </coherence>
    But I still get the same exception:
    2011-08-03 11:48:54,416 INFO [Logger@8079107 3.7.0.0] Coherence [Log4j.CDB:3] 2011-08-03 11:48:54.320/2.246 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:/Users/.../.m2/repository/com/oracle/oracle-coherence/3.7.0/oracle-coherence-3.7.0.jar!/tangosol-coherence.xml"
    2011-08-03 11:48:54,417 INFO [Logger@8079107 3.7.0.0] Coherence [Log4j.CDB:3] 2011-08-03 11:48:54.322/2.248 Oracle Coherence 3.7.0.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "file:/C:/.../coherence-config/target/classes/poc-tangosol-coherence-override.xml"
    2011-08-03 11:48:54,498 INFO [Logger@8079107 3.7.0.0] Coherence [Log4j.CDB:3] 2011-08-03 11:48:54.494/2.420 Oracle Coherence GE 3.7.0.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "file:/C:/.../coherence-config/target/classes/poc-coherence-cache-config.xml"
    Exception in thread "main" (Wrapped: Failed to load the factory) (Wrapped: Missing or inaccessible constructor "com.oracle.coherence.environment.extensible.ExtensibleEnvironment(String)"
    <configurable-cache-factory-config>
      <class-name>com.oracle.coherence.environment.extensible.ExtensibleEnvironment</class-name>
      <init-params>
        <init-param>
          <param-type>java.lang.String</param-type>
          <param-value>poc-coherence-cache-config.xml</param-value>
        </init-param>
      </init-params>
    </configurable-cache-factory-config>) java.lang.reflect.InvocationTargetException
         at com.tangosol.util.Base.ensureRuntimeException(Base.java:288)
         at com.tangosol.net.ScopedCacheFactoryBuilder.getDefaultFactory(ScopedCacheFactoryBuilder.java:308)
         at com.tangosol.net.DefaultCacheFactoryBuilder.getSingletonFactory(DefaultCacheFactoryBuilder.java:48)
         at com.tangosol.net.DefaultCacheFactoryBuilder.getFactory(DefaultCacheFactoryBuilder.java:121)
         at com.tangosol.net.ScopedCacheFactoryBuilder.getConfigurableCacheFactory(ScopedCacheFactoryBuilder.java:109)
         at com.tangosol.net.CacheFactory.getConfigurableCacheFactory(CacheFactory.java:126)
         at com.tangosol.net.CacheFactory.getCache(CacheFactory.java:204)
         at com.tangosol.net.CacheFactory.getCache(CacheFactory.java:181)
         at poc.datagrid.coherence.impl.PartitionCoherence.<init>(PartitionCoherence.java:26)
         at poc.datagrid.coherence.impl.GridCoherence.get(GridCoherence.java:14)
         at poc.eventcollector.jmx.TournamentBean.<init>(TournamentBean.java:19)
         at poc.eventcollector.main.EventCollectorMain.main(EventCollectorMain.java:52)
    Caused by: (Wrapped: Missing or inaccessible constructor "com.oracle.coherence.environment.extensible.ExtensibleEnvironment(String)"
    <configurable-cache-factory-config>
      <class-name>com.oracle.coherence.environment.extensible.ExtensibleEnvironment</class-name>
      <init-params>
        <init-param>
          <param-type>java.lang.String</param-type>
          <param-value>poc-coherence-cache-config.xml</param-value>
        </init-param>
      </init-params>
    </configurable-cache-factory-config>) java.lang.reflect.InvocationTargetException
         at com.tangosol.util.Base.ensureRuntimeException(Base.java:288)
         at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2608)
         at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2492)
         at com.tangosol.net.ScopedCacheFactoryBuilder.getDefaultFactory(ScopedCacheFactoryBuilder.java:270)
         ... 10 more
    Caused by: java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
         at com.tangosol.util.ClassHelper.newInstance(ClassHelper.java:694)
         at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2567)
         ... 12 more
    Caused by: java.lang.RuntimeException: Can't instantiate the NamespaceContentHandler [com.oracle.coherence.environment.extensible.namespaces.IntroduceNamespaceContentHandler] as the class is not found
    
         at com.oracle.coherence.environment.extensible.DefaultConfigurationContext$Scope.establishNamespaceContentHandlerFor(DefaultConfigurationContext.java:1145)
         at com.oracle.coherence.environment.extensible.DefaultConfigurationContext.ensureNamespaceContentHandler(DefaultConfigurationContext.java:119)
         at com.oracle.coherence.environment.extensible.DefaultConfigurationContext.processElement(DefaultConfigurationContext.java:282)
         at com.oracle.coherence.environment.extensible.DefaultConfigurationContext.processDocument(DefaultConfigurationContext.java:230)
         at com.oracle.coherence.environment.extensible.ExtensibleEnvironment.setConfig(ExtensibleEnvironment.java:469)
         at com.tangosol.net.DefaultConfigurableCacheFactory.<init>(DefaultConfigurableCacheFactory.java:190)
         at com.tangosol.net.DefaultConfigurableCacheFactory.<init>(DefaultConfigurableCacheFactory.java:176)
         at com.tangosol.net.DefaultConfigurableCacheFactory.<init>(DefaultConfigurableCacheFactory.java:152)
         at com.oracle.coherence.environment.extensible.ExtensibleEnvironment.<init>(ExtensibleEnvironment.java:155)
         ... 18 more
    Caused by: java.lang.ClassNotFoundException: com.oracle.coherence.environment.extensible.namespaces.IntroduceNamespaceContentHandler
         at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:169)
         at com.tangosol.util.ExternalizableHelper.loadClass(ExternalizableHelper.java:3056)
         at com.oracle.coherence.environment.extensible.DefaultConfigurationContext$Scope.establishNamespaceContentHandlerFor(DefaultConfigurationContext.java:1109)
         ... 26 more
    Do you have any ideas ?
  • 6. Re: Include in cache configuration?
    e.gherardini Newbie
    Currently Being Moderated
    I opened the coherence common jar (lastest version from coherence incubator 10)

    and I found that the class:
    class://com.oracle.coherence.environment.extensible.namespaces.IntroduceNamespaceContentHandler
    Is not present in the jar, which in fact it is stated inside the change list on the coherence common page:
    http://coherence.oracle.com/display/INC10/coherence-common

    We need to use Xml Element pre-processing namespace.

    Edited by: GheParDo on Aug 3, 2011 1:59 PM
  • 7. Re: Include in cache configuration?
    e.gherardini Newbie
    Currently Being Moderated
    Hi,
    I solved sobstituting this line:
    <cache-config 
         xmlns:introduce="class://com.oracle.coherence.environment.extensible.namespaces.IntroduceNamespaceContentHandler"
         >
    with this line:
    <cache-config 
    xmlns:element="class://com.oracle.coherence.environment.extensible.namespaces.XmlElementProcessingNamespaceContentHandler"
    element:introduce-cache-config="coherence-messagingpattern-cache-config.xml">
    Hope this helps.
  • 8. Re: Include in cache configuration?
    MagnusE Explorer
    Currently Being Moderated
    I got it working with the following configuration (this is the project specific file that includes the shared one):

    <cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
                  xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd"
                  xmlns:element="class://com.oracle.coherence.environment.extensible.namespaces.XmlElementProcessingNamespaceContentHandler"
                  element:introduce-cache-config=".\lib\shared-cache-config.xml">
    
        <caching-scheme-mapping>
            <cache-mapping>
                <cache-name>ExampleCache</cache-name>
                <scheme-name>ExampleScheme</scheme-name>
            </cache-mapping>
        </caching-scheme-mapping>
        <caching-schemes>
            <distributed-scheme>
                <scheme-name>ExampleScheme</scheme-name>
                <autostart>true</autostart>
            </distributed-scheme>
        </caching-schemes>
    </cache-config>
    Thanks a lot for the help!
  • 9. Re: Include in cache configuration?
    e.gherardini Newbie
    Currently Being Moderated
    You are welcome ;)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points