Getting Cache Manager Using Default Configuration

Access to Cacheonix API begins with obtaining an instance of CacheManager. When CacheManager is requested for the first time, Cacheonix initializes internal data structures and starts up network services if one or more clustered caches are configured.

The following example demonstrates how to get an instance of CacheManager using the default Cacheonix configuration. Cacheonix receives the default configuration from a file named cacheonix-config.xml found in the classpath or using a file that name is defined by system parameter cacheonix.config.xml:

package com.cacheonix.examples.cache;

import java.io.IOException;
import junit.framework.TestCase;

import cacheonix.cache.CacheManager;

/**
 * Tester for CacheManager.
 */
public final class CacheManagerTest extends TestCase {

   private CacheManager cacheManager;


   /**
    * Tests getting an instance of CacheManager using a default Cacheonix configuration.
    */
   public void testGetInstance() {
      assertNotNull("CacheManager created in setUp() method should not be null", cacheManager);
   }


   /**
    * Sets up the fixture. This method is called before a test is executed.
    *
    * Cacheonix receives the default configuration from a file named cacheonix-config.xml
    * found in the classpath or using a file that name is defined by system parameter
    * cacheonix.config.xml.
    */
   protected void setUp() throws Exception {
      super.setUp();
      // Get CacheManager using a default Cacheonix configuration
      cacheManager = CacheManager.getInstance();
   }


   /**
    * Tears down the fixture. This method is called after a test is executed.
    */
   protected void tearDown() throws Exception {
      // Cache manager has to be shutdown upon application exit
      cacheManager.shutdown();
      super.tearDown();
   }
}

Labels

 
(None)