• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CacheListenerAdapter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.gemstone.gemfire.cache.util.CacheListenerAdapter的典型用法代码示例。如果您正苦于以下问题:Java CacheListenerAdapter类的具体用法?Java CacheListenerAdapter怎么用?Java CacheListenerAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CacheListenerAdapter类属于com.gemstone.gemfire.cache.util包,在下文中一共展示了CacheListenerAdapter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getAsyncRegion

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * Returns the region used to keep track of asynchronous regions. 
 * The command client is allowed to supply an optional inbox region
 * with which it may receive results. The server removes these inbox
 * regions if they have idle for more that ASYNC_REGION_TIMEOUT. 
 * @return the region used to keep track of asynchronous regions
 */
private Region getAsyncRegion()
{
	Region asyncRegion = getCommandRegion().getSubregion(REGION_NAME_ASYNC);
	if (asyncRegion == null) {
		AttributesFactory factory = new AttributesFactory();
		factory.setStatisticsEnabled(true);
		factory.setScope(Scope.LOCAL);
		factory.setDataPolicy(DataPolicy.NORMAL);
		factory.setEntryIdleTimeout(new ExpirationAttributes(ASYNC_REGION_TIMEOUT, ExpirationAction.LOCAL_DESTROY));
		factory.addCacheListener(new CacheListenerAdapter() {
			public void afterDestroy(EntryEvent event)
			{
				String regionPath = (String)event.getKey();
				getCommandRegion().getSubregion(regionPath).destroyRegion();
			}
		});
		try {
			asyncRegion = getCommandRegion().createSubregion(REGION_NAME_ASYNC, factory.create());
		} catch (Exception ex) {
			// in case another thread created it
			asyncRegion = getCommandRegion().getSubregion(REGION_NAME_ASYNC);
		}
	}
	return asyncRegion;
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:33,代码来源:AbstractCommandTask.java


示例2: testEventIdSetForEvictDestroy

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * Test to verify event id exists when evict destroy happens.
 * 
 */
public void testEventIdSetForEvictDestroy()
{ 
  try{
    AttributesFactory factory = new AttributesFactory();    
    
    factory.setCacheListener(new CacheListenerAdapter(){        
      public void afterDestroy(EntryEvent event){          
        assertTrue("eventId has not been set for "+ event, ((EntryEventImpl)event).getEventId() != null);          
      }
     });
    
    EvictionAttributes evAttr = EvictionAttributes.createLRUEntryAttributes(1,EvictionAction.LOCAL_DESTROY);
    factory.setEvictionAttributes(evAttr);   
          
    RegionAttributes attrs = factory.createRegionAttributes();
    Region region = cache.createVMRegion("TEST_REGION", attrs);
    region.put("key1", "value1");
    region.put("key2", "value2");
  }
  catch (Exception e) {      
  }
  
  
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:29,代码来源:HARegionJUnitTest.java


示例3: addListenerAndKillPrimary

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static void addListenerAndKillPrimary(){
  Set<GatewaySender> senders = ((GemFireCacheImpl)cache).getAllGatewaySenders();
  assertEquals(senders.size(), 1);
  SerialGatewaySenderImpl sender = (SerialGatewaySenderImpl)senders.iterator().next();
  Region queue = cache.getRegion(Region.SEPARATOR+sender.getId()+"_SERIAL_GATEWAY_SENDER_QUEUE");
  assertNotNull(queue);
  CacheListenerAdapter cl = new CacheListenerAdapter() {
    @Override
    public void afterCreate(EntryEvent event) {
      if((Long)event.getKey() > 900){ 
        cache.getLogger().fine(" Gateway sender is killed by a test");
        cache.close();
        cache.getDistributedSystem().disconnect();
      }
    }
  };
  queue.getAttributesMutator().addCacheListener(cl);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:19,代码来源:WANTestBase.java


示例4: initQueue

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
private SingleWriteSingleReadRegionQueue initQueue(boolean conflate) {
    Cache cache = getCache();
    GatewayQueueAttributes queueAttrs = new GatewayQueueAttributes();
    queueAttrs.setBatchConflation(true);
    DiskStoreFactory dsf = cache.createDiskStoreFactory();
    File overflowDir = new File(getUniqueName() + InternalDistributedSystem.getAnyInstance().getId());
    if (!overflowDir.exists()) {
      overflowDir.mkdir();
    }
    assertTrue(overflowDir.isDirectory());
    File[] dirs1 = new File[] {overflowDir.getAbsoluteFile()};
    dsf.setDiskDirs(dirs1).create(getUniqueName());
    queueAttrs.setDiskStoreName(getUniqueName());
//    queueAttrs.setOverflowDirectory(getUniqueName() + InternalDistributedSystem.getAnyInstance().getId());
    CacheListener listener = new CacheListenerAdapter() {
      
    };
    GatewayStats stats = new GatewayStats(cache.getDistributedSystem(), "g1", "h1", null);
    SingleWriteSingleReadRegionQueue queue = new SingleWriteSingleReadRegionQueue(cache, "region", queueAttrs, listener, stats);
    return queue;
  }
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:22,代码来源:SingleWriteSingleReadRegionQueueDUnitTest.java


示例5: createHARegion

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * create the HARegion
 * 
 * @return @throws
 *         TimeoutException
 * @throws CacheWriterException
 * @throws CapacityControllerException
 * @throws GatewayException
 * @throws CacheExistsException
 * @throws RegionExistsException
 * @throws IOException
 * @throws ClassNotFoundException
 */
private Region createHARegion() throws TimeoutException,
    CacheWriterException,  GatewayException,
    CacheExistsException, RegionExistsException, IOException,
    ClassNotFoundException
{
  AttributesFactory factory = new AttributesFactory();
  factory.setDataPolicy(DataPolicy.REPLICATE);
  factory.setScope(Scope.DISTRIBUTED_ACK);
  ExpirationAttributes ea = new ExpirationAttributes(2000,
      ExpirationAction.LOCAL_INVALIDATE);
  factory.setStatisticsEnabled(true);
  ;
  factory.setCacheListener(new CacheListenerAdapter() {
    public void afterInvalidate(EntryEvent event)
    {
    }
  });
  RegionAttributes ra = factory.create();
  Region region = HARegion.getInstance("HARegionJUnitTest_region", (GemFireCacheImpl)cache,
      null, ra);
  region.getAttributesMutator().setEntryTimeToLive(ea);
  return region;

}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:38,代码来源:HARegionJUnitTest.java


示例6: prepareCacheListener

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * This method prepares a CacheListener, responsible for the cleanup of
 * reference of admin region, upon the cache closure.
 * 
 * @return CacheListener.
 */
private static CacheListener prepareCacheListener() {
  return new CacheListenerAdapter() {
    @Override
    public void close() {
      synchronized (ClientHealthMonitoringRegion.class) {
        ClientHealthMonitoringRegion.currentInstance = null;
      }
    }
  };
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:17,代码来源:ClientHealthMonitoringRegion.java


示例7: createCacheListenerForHARegion

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * 
 * @return CacheListener object having the desired functionility of expiry of
 *         Thread Identifier & Events for the HAregion. This method is
 *         appropriately over ridden in the test classes.
 */
CacheListener createCacheListenerForHARegion()
{
  return new CacheListenerAdapter() {
    @Override
    public void afterInvalidate(EntryEvent event)
    {
      try {
        // Fix 39175
        if (!HARegionQueue.this.isPrimary()) {
          HARegionQueue.this.expireTheEventOrThreadIdentifier(event);
        }
      }
      catch (CancelException e) {
        // ignore, we're done
      }
      catch (CacheException ce) {
        if (!destroyInProgress && logger.errorEnabled()) {
          logger
              .error(
                  LocalizedStrings.HARegionQueue_HAREGIONQUEUECREATECACHELISTNEREXCEPTION_IN_THE_EXPIRY_THREAD,
                  ce);
        }
      }
    }
  };
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:33,代码来源:HARegionQueue.java


示例8: main1

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static void main1(String[] args) throws Exception {
    DistributedSystem system =
      DistributedSystem.connect(new java.util.Properties());
    Cache cache = CacheFactory.create(system);
    AttributesFactory factory = new AttributesFactory();
    factory.setEvictionAttributes(EvictionAttributes
        .createLRUMemoryAttributes(2, (ObjectSizer) null, EvictionAction.OVERFLOW_TO_DISK));
    factory.setCacheListener(new CacheListenerAdapter() {
        public void afterUpdate(EntryEvent event) {
          System.out.println("UPDATE: " + event.getKey() + " -> (" +
                             event.getOldValue() + " -> " +
                             event.getNewValue() + ")");
        }
      });

    LocalRegion region = (LocalRegion)
      cache.createRegion("TestDiskRegion",
                           factory.create());
    DiskRegion dr = region.getDiskRegion();
    DiskRegionStats diskStats = dr.getStats();
    LRUStatistics lruStats = getLRUStats(region);

    BufferedReader br =
      new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Hit enter to perform action");
    for (int i = 0; true; i++) {
      br.readLine();
//       Thread.sleep(500);
      Object key = new Integer(i);
      Object value = new byte[200000];
      region.put(key, value);
      System.out.println(key + " -> " + value + " evictions = " +
                         lruStats.getEvictions() + ", writes = " +
                         diskStats.getWrites());
    }
  }
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:37,代码来源:TestDiskRegion.java


示例9: createClientCache

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * Creates the client cache
 *
 * @param hostName the name of the server's machine
 * @param port -
 *          bridgeserver port
 * @throws Exception -
 *           thrown if any problem occurs in setting up the client
 */
public static void createClientCache(String hostName, Integer port)
  throws Exception {
  Properties props = new Properties();
  props.setProperty("mcast-port", "0");
  props.setProperty("locators", "");
  new Bug36853EventsExpiryDUnitTest("temp").createCache(props);
  AttributesFactory factory = new AttributesFactory();
  factory.setScope(Scope.DISTRIBUTED_ACK);
  BridgeTestCase.configureConnectionPool(factory, hostName, port.intValue(),-1, true, -1, 2, null);

  factory.addCacheListener(new CacheListenerAdapter() {
    public void afterCreate(EntryEvent event)
    {
      String key = (String)event.getKey();
      Log.getLogWriter().info("client2 : afterCreate : key =" + key);
      if (key.equals(LAST_KEY)) {

        synchronized (Bug36853EventsExpiryDUnitTest.class) {
          Log.getLogWriter().info(
              "Notifying client2 to proceed for validation");
          proceedForValidation = true;
          Bug36853EventsExpiryDUnitTest.class.notify();
        }
      }
      else {
        putsRecievedByClient++;
      }
    }
  });
  RegionAttributes attrs = factory.create();
  Region region = cache.createRegion(REGION_NAME, attrs);

  region.registerInterest("ALL_KEYS");
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:44,代码来源:Bug36853EventsExpiryDUnitTest.java


示例10: createClientCache

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static void createClientCache(String hostName, Integer port1 , Integer port2) throws Exception
  {
    PORT1 = port1.intValue();
    PORT2 = port2.intValue();
    Properties props = new Properties();
    props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
    props.setProperty(DistributionConfig.LOCATORS_NAME, "");
    new FailoverDUnitTest("temp").createCache(props);

    /*props.setProperty("retryAttempts", "5");
    props.setProperty("endpoints", "ep1=" + hostName + ":"+PORT1+",ep2="
        + hostName + ":"+PORT2);
    props.setProperty("redundancyLevel", "-1");
    props.setProperty("establishCallbackConnection", "true");
    props.setProperty("LBPolicy", "RoundRobin");
    props.setProperty("readTimeout", "250");
    props.setProperty("socketBufferSize", "32768");
    props.setProperty("retryInterval", "1000");
    props.setProperty("connectionsPerServer", "2");
*/
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    BridgeTestCase.configureConnectionPoolWithName(factory, hostName, new int[] {PORT1,PORT2}, true, -1, 2, null, "FailoverPool");
    factory.setCacheListener(new CacheListenerAdapter() {
      public void afterUpdate(EntryEvent event)
      {
        synchronized (this) {
          cache.getLogger().info("Event Received : key..."+ event.getKey());
          cache.getLogger().info("Event Received : value..."+ event.getNewValue());
        }
      }
     });
    cache.createRegion(regionName, factory.create());
  }
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:35,代码来源:FailoverDUnitTest.java


示例11: createServerCache

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static void createServerCache() throws Exception
{
  new VerifyEventIDGenerationInP2PDUnitTest("temp")
      .createCache(new Properties());
  AttributesFactory factory = new AttributesFactory();
  factory.setScope(Scope.DISTRIBUTED_ACK);
  factory.setMirrorType(MirrorType.NONE);
  factory.setCacheListener(new CacheListenerAdapter() {

    public void afterCreate(EntryEvent event)
    {
      if (!receiver) {
        vm0.invoke(EventIDVerificationInP2PDUnitTest.class, "setEventIDData",
            new Object[] { ((EntryEventImpl)event).getEventId() });
      }
      else {
        testEventIDResult = ((EntryEventImpl)event).getEventId().equals(
            eventId);
      }
    }

  });

  RegionAttributes attrs = factory.create();
  cache.createRegion(REGION_NAME, attrs);

}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:28,代码来源:VerifyEventIDGenerationInP2PDUnitTest.java


示例12: testClearInteractionWithLRUList_Bug37605

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * If an entry which has just been written on the disk, sees clear just before
 * updating the LRULiist, then that deleted entry should not go into the
 * LRUList
 * 
 * @author Asif
 */
public void testClearInteractionWithLRUList_Bug37605()
{
  DiskRegionProperties props = new DiskRegionProperties();
  props.setOverflow(true);
  props.setOverFlowCapacity(1);
  props.setDiskDirs(dirs);
  props.setRegionName("IGNORE_EXCEPTION_testClearInteractionWithLRUList_Bug37605");
  final Region region = DiskRegionHelperFactory
      .getSyncOverFlowAndPersistRegion(cache, props);

  region.getAttributesMutator().setCacheListener(new CacheListenerAdapter() {
    public void afterCreate(EntryEvent event)
    {
      Thread th = new Thread(new Runnable() {
        public void run()
        {
          region.clear();
        }
      });
      th.start();
      try {
        DistributedTestCase.join(th, 30 * 1000, null);
      }
      catch (Exception ie) {
        DiskRegionJUnitTest.this.exceptionOccured = true;
        DiskRegionJUnitTest.this.failureCause = ie.toString();
      }
    }
  });
  region.create("key1", "value1");
  assertFalse(this.failureCause, this.exceptionOccured);
  NewLRUClockHand lruList = ((VMLRURegionMap)((LocalRegion)region).entries)
      ._getLruList();
  assertEquals(region.size(), 0);
  lruList.audit();
  assertNull(
      "The LRU List should have been empty instead it contained a cleared entry",
      lruList.getLRUEntry());
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:47,代码来源:DiskRegionJUnitTest.java


示例13: addCacheListenerAndDestroyRegion

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static void addCacheListenerAndDestroyRegion(String regionName){
  final Region region = cache.getRegion(Region.SEPARATOR + regionName);
  assertNotNull(region);
  CacheListenerAdapter cl = new CacheListenerAdapter() {
    @Override
    public void afterCreate(EntryEvent event) {
      if((Long)event.getKey() == 99){ 
        region.destroyRegion();
      }
    }
  };
  region.getAttributesMutator().addCacheListener(cl);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:14,代码来源:WANTestBase.java


示例14: addCacheListenerAndCloseCache

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static void addCacheListenerAndCloseCache(String regionName){
  final Region region = cache.getRegion(Region.SEPARATOR + regionName);
  assertNotNull(region);
  CacheListenerAdapter cl = new CacheListenerAdapter() {
    @Override
    public void afterCreate(EntryEvent event) {
      if((Long)event.getKey() == 900){ 
        cache.getLogger().fine(" Gateway sender is killed by a test");
        cache.close();
        cache.getDistributedSystem().disconnect();
      }
    }
  };
  region.getAttributesMutator().addCacheListener(cl);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:16,代码来源:WANTestBase.java


示例15: createClientCache

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static void createClientCache(Integer port1, Integer port2) throws Exception {
  PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest("temp");
  Properties props = new Properties();
  props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
  props.setProperty(DistributionConfig.LOCATORS_NAME, "");
  test.createCache(props);

  lastKeyReceived = false;
  
  PoolImpl p = (PoolImpl)PoolManager.createFactory().addServer("localhost",
      port1).addServer("localhost", port2).setSubscriptionEnabled(true)
      .setSubscriptionRedundancy(1).setThreadLocalConnections(true)
      .setMinConnections(6).setReadTimeout(20000).setPingInterval(10000)
      .setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");

  AttributesFactory factory = new AttributesFactory();
  factory.setScope(Scope.LOCAL);
  factory.setPoolName(p.getName());
  factory.setCloningEnabled(false);
  factory.setConcurrencyChecksEnabled(true);
  factory.addCacheListener(new CacheListenerAdapter(){
  public void afterCreate(EntryEvent event) {
      if (LAST_KEY.equals(event.getKey())) {
      lastKeyReceived = true;
    }}});

  RegionAttributes attrs = factory.create();
  deltaPR = cache.createRegion(REGION_NAME, attrs);
  //deltaPR.create(DELTA_KEY, new PRDeltaTestImpl());
  deltaPR.registerInterest("ALL_KEYS");
  pool = p;

}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:34,代码来源:PRDeltaPropagationDUnitTest.java


示例16: testBasicMapAfterClearCalback

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public void testBasicMapAfterClearCalback() {
  Region rgn = CacheUtils.getRegion("Portfolios");
  AttributesMutator atm = rgn.getAttributesMutator();
  atm.setCacheListener(new CacheListenerAdapter() {

    @Override
    public void afterRegionClear(RegionEvent event) {
      synchronized (MapInterfaceTest.this) {
        event.getRegion().getCache().getLogger().info("afterRegionClear call back " + event);
        afterClearCallbackOccured = true;
        MapInterfaceTest.this.notify();
      }
    }
  });
  int size = rgn.size();
  assertTrue(
      "MapInterfaceTest::basicMapClearNonTranxn: The init size of region is zero",
      size > 0);
  rgn.clear();
  if (rgn.size() != 0) {
    fail("The region size is non zero even after issuing clear");
  }
  if (rgn.size() != 0) {
    fail("The region size is non zero even after issuing clear");
  }
  try {
    synchronized (this) {
      if (!this.afterClearCallbackOccured) {
        this.wait(10000);
      }
    }
  }
  catch (InterruptedException ie) {
    fail(ie.toString());
  }
  if (!this.afterClearCallbackOccured) {
    fail("afterClear Callback not issued");
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:40,代码来源:MapInterfaceTest.java


示例17: createClientCache

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static void createClientCache(String host, Integer port)
    throws Exception {
  Properties props = new Properties();
  props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
  props.setProperty(DistributionConfig.LOCATORS_NAME, "");
  cache = new DeltaPropagationStatsDUnitTest("temp").createCache(props);
  pool = PoolManager.createFactory().addServer(host, port)
      .setThreadLocalConnections(true).setMinConnections(1)
      .setSubscriptionEnabled(true).setSubscriptionRedundancy(0)
      .setReadTimeout(10000).setSocketBufferSize(32768).create(
          "DeltaPropagationStatsDunitTestPool");
  AttributesFactory factory = new AttributesFactory();
  factory.setScope(Scope.DISTRIBUTED_ACK);
  factory.setDataPolicy(DataPolicy.NORMAL);
  factory.setPoolName(pool.getName());
  factory.setCloningEnabled(false);

  factory.addCacheListener(new CacheListenerAdapter() {
    public void afterCreate(EntryEvent event) {
      if (LAST_KEY.equals(event.getKey())) {
        lastKeyReceived = true;
      }
    }
  });

  RegionAttributes attrs = factory.create();
  cache.createRegion(REGION_NAME, attrs).registerInterest("ALL_KEYS");
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:29,代码来源:DeltaPropagationStatsDUnitTest.java


示例18: createServerCache

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
public static Integer createServerCache(Boolean flag, DataPolicy policy,
    Scope scope, Boolean listener) throws Exception {
  ConnectionTable.threadWantsSharedResources();
  DeltaPropagationStatsDUnitTest test = new DeltaPropagationStatsDUnitTest(
      "temp");
  Properties props = new Properties();
  if (!flag) {
    props
        .setProperty(DistributionConfig.DELTA_PROPAGATION_PROP_NAME, "false");
  }
  cache = test.createCache(props);
  AttributesFactory factory = new AttributesFactory();
  factory.setScope(scope);
  factory.setDataPolicy(policy);

  if (listener) {
    factory.addCacheListener(new CacheListenerAdapter() {
      public void afterCreate(EntryEvent event) {
        if (event.getKey().equals(LAST_KEY)) {
          lastKeyReceived = true;
        }
      }
    });
  }

  Region region = cache.createRegion(REGION_NAME, factory.create());
  if (!policy.isReplicate()) {
    region.create("KEY", "KEY");
  }
  region.getAttributesMutator().setCloningEnabled(false);
  CacheServer server = cache.addCacheServer();
  int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
  server.setPort(port);
  server.setNotifyBySubscription(true);
  server.start();
  return server.getPort();
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:38,代码来源:DeltaPropagationStatsDUnitTest.java


示例19: testBug31592

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * Tests that a Region with an LRU capacity controller can be
 * accessed from inside a cache listener.
 */
public void testBug31592() throws Exception {
  final String name = this.getUniqueName();
  final Object key = "KEY";
  final Object value = "VALUE";
  final Object key2 = "KEY2";
  final Object value2 = "VALUE2";

  AttributesFactory factory = new AttributesFactory();
  factory.setScope(Scope.LOCAL);
  factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(10));
  final Region region =
    createRegion(name, factory.create());

  region.put(key, value);

  final Throwable[] errors = new Throwable[1];
  region.getAttributesMutator().addCacheListener(new
    CacheListenerAdapter() {
      public void afterCreate(EntryEvent event) {
        try {
          getLogWriter().info("AFTER CREATE");
          region.put(key, value2);

        } 
        catch (VirtualMachineError e) {
          SystemFailure.initiateFailure(e);
          throw e;
        }
        catch (Throwable ex) {
          region.getCache().getLogger().severe(
              "failed to access cache from listener", ex);
          errors[0] = ex;
        }
      }
    });
  region.put(key2, value2);

  assertNull(errors[0]);
  assertEquals(value2, region.get(key));
  assertEquals(value2, region.get(key2));
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:46,代码来源:LRUEvictionControllerTest.java


示例20: testBug31592

import com.gemstone.gemfire.cache.util.CacheListenerAdapter; //导入依赖的package包/类
/**
 * Tests that a Region with an LRU capacity controller can be
 * accessed from inside a cache listener.
 */
public void testBug31592() throws Exception {
  final String name = this.getUniqueName();
  final Object key = "KEY";
  final Object value = "VALUE";
  final Object key2 = "KEY2";
  final Object value2 = "VALUE2";

  AttributesFactory factory = new AttributesFactory();
  factory.setEnableOffHeapMemory(isOffHeapEnabled());
  factory.setScope(Scope.LOCAL);
  factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(10));
  final Region region =
    createRegion(name, factory.create());

  region.put(key, value);

  final Throwable[] errors = new Throwable[1];
  region.getAttributesMutator().addCacheListener(new
    CacheListenerAdapter() {
      public void afterCreate(EntryEvent event) {
        try {
          getLogWriter().info("AFTER CREATE");
          region.put(key, value2);

        } 
        catch (VirtualMachineError e) {
          SystemFailure.initiateFailure(e);
          throw e;
        }
        catch (Throwable ex) {
          region.getCache().getLogger().severe(
              "failed to access cache from listener", ex);
          errors[0] = ex;
        }
      }
    });
  region.put(key2, value2);

  assertNull(errors[0]);
  assertEquals(value2, region.get(key));
  assertEquals(value2, region.get(key2));
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:47,代码来源:LRUEvictionControllerDUnitTest.java



注:本文中的com.gemstone.gemfire.cache.util.CacheListenerAdapter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LinkService类代码示例发布时间:2022-05-22
下一篇:
Java SpanBytesEncoder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap