PRODUCTS AND SERVICES INDUSTRIES SUPPORT PARTNERS COMMUNITIES ABOUT
  Coherence 3.4 User Guide
  Parameter Macros
Added by Rob Misek, last edited by Tom Pfaeffle on Aug 06, 2008  (view change)

Labels

 

Cache Configuration Deployment Descriptor supports parameter macros to minimize custom coding and enable specification of commonly used attributes when configuring class constructor parameters. The macros should be entered enclosed in curly braces as shown below, without any quotes or spaces.

The following parameter macros may be specified:

<param-type> <param-value> Description
java.lang.String {cache-name} Used to pass the current cache name as a constructor parameter

For example:

<class-name>com.mycompany.cache.CustomCacheLoader</class-name>
<init-params>
    <init-param>
        <param-type>java.lang.String</param-type>
        <param-value>{cache-name}</param-value>
    </init-param>
</init-params>

java.lang.ClassLoader {class-loader} Used to pass the current classloader as a constructor parameter.

For example:

<class-name>com.mycompany.cache.CustomCacheLoader</class-name>
<init-params>
    <init-param>
        <param-type>java.lang.ClassLoader</param-type>
        <param-value>{class-loader}</param-value>
    </init-param>
</init-params>

com.tangosol.net.BackingMapManagerContext {manager-context} Used to pass the current BackingMapManagerContext object as a constructor parameter.

For example:

<class-name>com.mycompany.cache.CustomCacheLoader</class-name>
<init-params>
    <init-param>
        <param-type>com.tangosol.net.BackingMapManagerContext</param-type>
        <param-value>{manager-context}</param-value>
    </init-param>
</init-params>

{scheme-ref} scheme name Instantiates an object defined by the <class-scheme>, <local-scheme> or <file-scheme> with the specified <scheme-name> value and uses it as a constructor parameter.

For example:

<class-scheme>
    <scheme-name>dbconnection</scheme-name>
    <class-name>com.mycompany.dbConnection</class-name>
    <init-params>
        <init-param>
            <param-name>driver</param-name>
            <param-type>String</param-type>
            <param-value>org.gjt.mm.mysql.Driver</param-value>
        </init-param>
        <init-param>
            <param-name>url</param-name>
            <param-type>String</param-type>
            <param-value>jdbc:mysql://dbserver:3306/companydb</param-value>
        </init-param>
        <init-param>
            <param-name>user</param-name>
            <param-type>String</param-type>
            <param-value>default</param-value>
        </init-param>
        <init-param>
            <param-name>password</param-name>
            <param-type>String</param-type>
            <param-value>default</param-value>
        </init-param>
    </init-params>
</class-scheme>
...
<class-name>com.mycompany.cache.CustomCacheLoader</class-name>
<init-params>
    <init-param>
        <param-type>{scheme-ref}</param-type>
        <param-value>dbconnection</param-value>
    </init-param>
</init-params>

{cache-ref} cache name Used to obtain a NamedCache reference for the specified cache name.

Consider the following configuration example:

<cache-config>
  <caching-scheme-mapping>
    <cache-mapping>
      <cache-name>boston-*</cache-name>
      <scheme-name>wrapper</scheme-name>
      <init-params>
        <init-param>
          <param-name>delegate-cache-name</param-name>
          <param-value>london-*</param-value>
        </init-param>
      </init-params>
    </cache-mapping>

    <cache-mapping>
      <cache-name>london-*</cache-name>
      <scheme-name>partitioned</scheme-name>
    </cache-mapping>
  </caching-scheme-mapping>

  <caching-schemes>
    <class-scheme>
      <scheme-name>wrapper</scheme-name>
      <class-name>com.tangosol.net.cache.WrapperNamedCache</class-name>
      <init-params>
        <init-param>
          <param-type>cache-ref</param-type>
          <param-value>delegate-cache-name</param-value>
        </init-param>
        <init-param>
          <param-type>string</param-type>
          <param-value>cache-name</param-value>
        </init-param>
      </init-params>
    </class-scheme>

    <distributed-scheme>
      <scheme-name>partitioned</scheme-name>
      <service-name>partitioned</service-name>
      <backing-map-scheme>
        <local-scheme>
          <unit-calculator>BINARY</unit-calculator>
        </local-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
  </caching-schemes>
</cache-config>


The CacheFactory.getCache("london-test") call would result in a standard partitioned cache reference. On the other hand, the CacheFactory.getCache("boston-test") call would resolve the value of the "delegate-cache-name" parameter to "london-test" and would construct an instance of the WrapperNamedCache delegating to the NamedCache returned by the CacheFactory.getCache("london-test") call.

Unknown macro: {rate-table}