Package org.jboss.cache

Examples of org.jboss.cache.Cache


        JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
       
        CacheInstanceManager mgr = regionFactory.getCacheInstanceManager();
        assertTrue("Correct default CacheInstanceManager type", mgr instanceof SharedCacheInstanceManager);
       
        Cache cache = mgr.getEntityCacheInstance();
        assertTrue("entity cache exists", cache != null);
        assertEquals("Used correct config", "TestSharedCache", cache.getConfiguration().getClusterName());
        assertEquals("Cache started", CacheStatus.STARTED, cache.getCacheStatus());       
       
        CacheTestUtil.stopRegionFactory(regionFactory, getCacheTestSupport());
       
        assertEquals("Cache destroyed", CacheStatus.DESTROYED, cache.getCacheStatus());
    }
View Full Code Here


      System.out.println("*** testAll()");
     
      // Bind a listener to the "local" cache
      // Our region factory makes its CacheManager available to us
      CacheManager localManager = TestCacheInstanceManager.getTestCacheManager(DualNodeTestUtil.LOCAL);
      Cache localCache = localManager.getCache(getEntityCacheConfigName(), true);
      MyListener localListener = new MyListener();
      localCache.addCacheListener(localListener);
     
      TransactionManager localTM = localCache.getConfiguration().getRuntimeConfig().getTransactionManager();
     
      // Bind a listener to the "remote" cache
      CacheManager remoteManager = TestCacheInstanceManager.getTestCacheManager(DualNodeTestUtil.REMOTE);
      Cache remoteCache = remoteManager.getCache(getEntityCacheConfigName(), true);
      MyListener remoteListener = new MyListener();
      remoteCache.addCacheListener(remoteListener);     
     
      TransactionManager remoteTM = remoteCache.getConfiguration().getRuntimeConfig().getTransactionManager();
     
      SessionFactory localFactory = getEnvironment().getSessionFactory();
      SessionFactory remoteFactory = getSecondNodeEnvironment().getSessionFactory();
     
      try
View Full Code Here

        super.setUp();
       
        if (getCollectionAccessStrategy() == null) {
            Configuration cfg = createConfiguration();
            JBossCacheRegionFactory rf  = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
            Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance();
            optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
           
            // Sleep a bit to avoid concurrent FLUSH problem
            avoidConcurrentFlush();
           
            CollectionRegion localCollectionRegion = rf.buildCollectionRegion(REGION_NAME, cfg.getProperties(), null);
View Full Code Here

        super.setUp();
       
        if (getEntityAccessStrategy() == null) {
            Configuration cfg = createConfiguration();
            JBossCacheRegionFactory rf  = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
            Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance();
            optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
           
            // Sleep a bit to avoid concurrent FLUSH problem
            avoidConcurrentFlush();
           
            EntityRegion localEntityRegion = rf.buildEntityRegion(REGION_NAME, cfg.getProperties(), null);
View Full Code Here

       
        region.put(KEY, VALUE1);
        assertEquals(VALUE1, region.get(KEY));
       
        final Fqn rootFqn = getRegionFqn(getStandardRegionName(REGION_PREFIX), REGION_PREFIX);
        final Cache jbc = getJBossCache(regionFactory);

        final CountDownLatch blockerLatch = new CountDownLatch(1);
        final CountDownLatch writerLatch = new CountDownLatch(1);
        final CountDownLatch completionLatch = new CountDownLatch(1);
        final ExceptionHolder holder = new ExceptionHolder();
       
        Thread blocker = new Thread() {
         
            public void run() {
                Fqn toBlock = new Fqn(rootFqn, KEY);
                GetBlocker blocker = new GetBlocker(blockerLatch,toBlock);
                try {
                    jbc.addCacheListener(blocker);
                   
                    BatchModeTransactionManager.getInstance().begin();
                    region.get(KEY);
                    BatchModeTransactionManager.getInstance().commit();
                }
                catch (Exception e) {
                    holder.e1 = e;
                    rollback();
                }
                finally {
                    jbc.removeCacheListener(blocker);
                }
            }
        };
       
        Thread writer = new Thread() {
         
            public void run() {
                try {
                    writerLatch.await();
                   
                    BatchModeTransactionManager.getInstance().begin();
                    region.put(KEY, VALUE2);
                    BatchModeTransactionManager.getInstance().commit();
                }
                catch (Exception e) {
                    holder.e2 = e;
                    rollback();
                }
                finally {
                    completionLatch.countDown();
                }
            }
        };
       
        blocker.setDaemon(true);
        writer.setDaemon(true);
       
        boolean unblocked = false;
        try {
            blocker.start();
            writer.start();
           
            assertFalse("Blocker is blocking", completionLatch.await(100, TimeUnit.MILLISECONDS));
            // Start the writer
            writerLatch.countDown();
            assertTrue("Writer finished promptly", completionLatch.await(100, TimeUnit.MILLISECONDS));
           
            blockerLatch.countDown();
            unblocked = true;
           
            if ("PESSIMISTIC".equals(jbc.getConfiguration().getNodeLockingSchemeString())
                  && "REPEATABLE_READ".equals(jbc.getConfiguration().getIsolationLevelString())) {
                assertEquals(VALUE1, region.get(KEY));
            }
            else {
                assertEquals(VALUE2, region.get(KEY));
            }           
View Full Code Here

  private void batchTest() {
   
    Configuration config = new Configuration();
    config.setInvocationBatchingEnabled(true);
    CacheFactory factory = new DefaultCacheFactory();
    Cache cache = factory.createCache(config);
   
    cache.put("/a", "a", new Content("a"));
   
    cache.startBatch();
    cache.put("/b", "b", new Content("b"));
    cache.put("/c", "c", new Content("c"));
    cache.put("/d", "d", new Content("d"));
    cache.endBatch(true);
   
    System.out.println(cache.getRoot().getChildren());
  }
View Full Code Here

    config.setIsolationLevel(IsolationLevel.READ_COMMITTED);
    config.setCacheMode(CacheMode.LOCAL);
    config.setLockAcquisitionTimeout(15000);
   
    CacheFactory factory = new DefaultCacheFactory();
    Cache cache = factory.createCache(config);
  }
View Full Code Here

    Cache cache = factory.createCache(config);
  }

  private void destroy() {

    Cache cache = createCacheUseDefault();
    cache.stop();
    cache.destroy();
  }
View Full Code Here

    cache.stop();
    cache.destroy();
  }
 
  private void getNode() {
    Cache cache = createCacheUseDefault();
    Node root = cache.getRoot();
    root.addChild(Fqn.fromString("/a/b/c"));
    Node b = root.getChild(Fqn.fromString("/a/b"));
   
    b.put("k1", "v1");
    b.put("k2", "v2");
View Full Code Here

    b.put("k3", "v3");
  }

  private void cachingRetrievingWithFqn() {

    Cache cache = createCacheUseDefault();
    Node rootNode = cache.getRoot();
    Fqn helloWorldFqn = Fqn.fromString("/root/helloWorld");
    Node helloWorld = rootNode.addChild(helloWorldFqn);
   
    cache.put(helloWorldFqn, "isJBossCache", Boolean.TRUE);
    cache.put(helloWorldFqn, "content", new Content("HelloWorld"));
   
    System.out.println(helloWorld.get("isJBossCache"));
    System.out.println(helloWorld.get("content"));
    System.out.println(cache.getRoot().hasChild(helloWorldFqn));
   
    cache.removeNode(helloWorldFqn);
  }
View Full Code Here

TOP

Related Classes of org.jboss.cache.Cache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.