コード例 #1
0
  @Override
  public V get(Object key) {
    checkNotNull(key, NULL_KEY_IS_NOT_ALLOWED);
    initNearCache();
    if (nearCache != null) {
      Object cached = nearCache.get(key);
      if (cached != null) {
        if (cached.equals(NULL_OBJECT)) {
          return null;
        }
        return (V) cached;
      }
    }

    Data keyData = toData(key);
    ClientMessage request = ReplicatedMapGetCodec.encodeRequest(name, keyData);
    ClientMessage response = invoke(request, keyData);

    ReplicatedMapGetCodec.ResponseParameters result =
        ReplicatedMapGetCodec.decodeResponse(response);

    V value = (V) toObject(result.response);
    if (nearCache != null) {
      nearCache.put(key, value);
    }
    return value;
  }
コード例 #2
0
  /** Adds near cache stats. */
  protected void addNearCacheStats(
      LocalMapStatsImpl stats,
      LocalMapOnDemandCalculatedStats onDemandStats,
      MapContainer mapContainer) {
    if (!mapContainer.getMapConfig().isNearCacheEnabled()) {
      return;
    }
    NearCache nearCache = nearCacheProvider.getOrCreateNearCache(mapContainer.getName());
    NearCacheStats nearCacheStats = nearCache.getNearCacheStats();
    long nearCacheHeapCost = mapContainer.getNearCacheSizeEstimator().getSize();

    stats.setNearCacheStats(nearCacheStats);
    onDemandStats.incrementHeapCost(nearCacheHeapCost);
  }
コード例 #3
0
 @Override
 protected void onDestroy() {
   if (nearCache != null) {
     removeNearCacheInvalidationListener();
     nearCache.destroy();
   }
 }
コード例 #4
0
 private void removeInvalidationListener() {
   if (nearCache != null && nearCache.isInvalidateOnChange()) {
     String registrationId = nearCacheMembershipRegistrationId;
     if (registrationId != null) {
       clientContext.getListenerService().deregisterListener(registrationId);
     }
   }
 }
コード例 #5
0
 private void registerInvalidationListener() {
   if (nearCache != null && nearCache.isInvalidateOnChange()) {
     Client client = clientContext.getClusterService().getLocalClient();
     EventHandler handler = new NearCacheInvalidationHandler(client);
     ListenerMessageCodec listenerCodec = createInvalidationListenerCodec();
     nearCacheMembershipRegistrationId =
         clientContext.getListenerService().registerListener(listenerCodec, handler);
   }
 }
コード例 #6
0
 @Override
 public void destroy() {
   if (nearCache != null) {
     removeInvalidationListener();
     nearCacheManager.destroyNearCache(nearCache.getName());
   }
   if (statisticsEnabled) {
     statistics.clear();
   }
   super.destroy();
 }
コード例 #7
0
  protected void doListNearCaches() {
    NearCacheManager nearCacheManager = createNearCacheManager();

    Set<String> nearCacheNames = new HashSet<String>();

    Collection<NearCache> nearCaches1 = nearCacheManager.listAllNearCaches();
    assertEquals(0, nearCaches1.size());

    for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
      String nearCacheName = DEFAULT_NEAR_CACHE_NAME + "-" + i;
      createNearCache(nearCacheManager, nearCacheName);
      nearCacheNames.add(nearCacheName);
    }

    Collection<NearCache> nearCaches2 = nearCacheManager.listAllNearCaches();
    assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches2.size());

    for (NearCache nearCache : nearCaches2) {
      assertTrue(nearCacheNames.contains(nearCache.getName()));
    }
  }
コード例 #8
0
  protected AbstractClientInternalCacheProxy(
      CacheConfig cacheConfig,
      ClientContext clientContext,
      HazelcastClientCacheManager cacheManager) {
    super(cacheConfig, clientContext);
    this.cacheManager = cacheManager;
    this.nearCacheManager = clientContext.getNearCacheManager();
    this.asyncListenerRegistrations =
        new ConcurrentHashMap<CacheEntryListenerConfiguration, String>();
    this.syncListenerRegistrations =
        new ConcurrentHashMap<CacheEntryListenerConfiguration, String>();
    this.syncLocks = new ConcurrentHashMap<Integer, CountDownLatch>();

    initNearCache();

    if (nearCache != null) {
      this.statistics =
          new ClientCacheStatisticsImpl(System.currentTimeMillis(), nearCache.getNearCacheStats());
    } else {
      this.statistics = new ClientCacheStatisticsImpl(System.currentTimeMillis());
    }
    this.statisticsEnabled = cacheConfig.isStatisticsEnabled();
  }
コード例 #9
0
 protected void invalidateNearCache(Data key) {
   if (nearCache != null) {
     nearCache.remove(key);
   }
 }
コード例 #10
0
 protected void storeInNearCache(Data key, Data valueData, V value) {
   if (nearCache != null && valueData != null) {
     Object valueToStore = nearCache.selectToSave(value, valueData);
     nearCache.put(key, valueToStore);
   }
 }