예제 #1
0
 CacheEventHandler(NodeEngine nodeEngine) {
   this.nodeEngine = nodeEngine;
   GroupProperties groupProperties = nodeEngine.getGroupProperties();
   invalidationMessageBatchEnabled =
       groupProperties.getBoolean(CACHE_INVALIDATION_MESSAGE_BATCH_ENABLED);
   if (invalidationMessageBatchEnabled) {
     invalidationMessageBatchSize =
         groupProperties.getInteger(CACHE_INVALIDATION_MESSAGE_BATCH_SIZE);
     int invalidationMessageBatchFreq =
         groupProperties.getInteger(CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS);
     ExecutionService executionService = nodeEngine.getExecutionService();
     CacheBatchInvalidationMessageSender batchInvalidationMessageSender =
         new CacheBatchInvalidationMessageSender();
     cacheBatchInvalidationMessageSenderScheduler =
         executionService.scheduleWithRepetition(
             ICacheService.SERVICE_NAME + ":cacheBatchInvalidationMessageSender",
             batchInvalidationMessageSender,
             invalidationMessageBatchFreq,
             invalidationMessageBatchFreq,
             TimeUnit.SECONDS);
   }
   LifecycleService lifecycleService = nodeEngine.getHazelcastInstance().getLifecycleService();
   lifecycleService.addLifecycleListener(
       new LifecycleListener() {
         @Override
         public void stateChanged(LifecycleEvent event) {
           if (event.getState() == LifecycleEvent.LifecycleState.SHUTTING_DOWN) {
             invalidateAllCaches();
           }
         }
       });
 }
 @Override
 public void initialize() {
   final NodeEngine nodeEngine = getNodeEngine();
   CollectionConfig config = getConfig(nodeEngine);
   final List<ItemListenerConfig> itemListenerConfigs = config.getItemListenerConfigs();
   for (ItemListenerConfig itemListenerConfig : itemListenerConfigs) {
     ItemListener listener = itemListenerConfig.getImplementation();
     if (listener == null && itemListenerConfig.getClassName() != null) {
       try {
         listener =
             ClassLoaderUtil.newInstance(
                 nodeEngine.getConfigClassLoader(), itemListenerConfig.getClassName());
       } catch (Exception e) {
         throw ExceptionUtil.rethrow(e);
       }
     }
     if (listener != null) {
       if (listener instanceof HazelcastInstanceAware) {
         ((HazelcastInstanceAware) listener)
             .setHazelcastInstance(nodeEngine.getHazelcastInstance());
       }
       addItemListener(listener, itemListenerConfig.isIncludeValue());
     }
   }
 }
예제 #3
0
 public String addMapInterceptorInternal(MapInterceptor interceptor) {
   NodeEngine nodeEngine = getNodeEngine();
   if (interceptor instanceof HazelcastInstanceAware) {
     ((HazelcastInstanceAware) interceptor)
         .setHazelcastInstance(nodeEngine.getHazelcastInstance());
   }
   String id = mapServiceContext.generateInterceptorId(name, interceptor);
   Collection<Member> members = nodeEngine.getClusterService().getMembers();
   for (Member member : members) {
     try {
       AddInterceptorOperation op = new AddInterceptorOperation(id, interceptor, name);
       Future future = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
       future.get();
     } catch (Throwable t) {
       throw rethrow(t);
     }
   }
   return id;
 }