@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());
     }
   }
 }
Пример #2
0
 private void initializeListeners(Config config) {
   for (final ListenerConfig listenerCfg : config.getListenerConfigs()) {
     Object listener = listenerCfg.getImplementation();
     if (listener == null) {
       try {
         listener = ClassLoaderUtil.newInstance(configClassLoader, listenerCfg.getClassName());
       } catch (Exception e) {
         logger.severe(e);
       }
     }
     if (listener instanceof HazelcastInstanceAware) {
       ((HazelcastInstanceAware) listener).setHazelcastInstance(hazelcastInstance);
     }
     if (listener instanceof DistributedObjectListener) {
       final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
       proxyService.addProxyListener((DistributedObjectListener) listener);
     } else if (listener instanceof MembershipListener) {
       clusterService.addMembershipListener((MembershipListener) listener);
     } else if (listener instanceof MigrationListener) {
       partitionService.addMigrationListener((MigrationListener) listener);
     } else if (listener instanceof LifecycleListener) {
       hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener);
     } else if (listener != null) {
       final String error = "Unknown listener type: " + listener.getClass();
       Throwable t = new IllegalArgumentException(error);
       logger.warning(error, t);
     }
   }
 }
Пример #3
0
  private <T extends EventListener> T initializeListener(ListenerConfig listenerConfig) {
    T listener = getListenerImplOrNull(listenerConfig);

    if (listener instanceof HazelcastInstanceAware) {
      ((HazelcastInstanceAware) listener)
          .setHazelcastInstance(getNodeEngine().getHazelcastInstance());
    }

    return listener;
  }
Пример #4
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;
 }
Пример #5
0
 @Override
 public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
   if (mapListener instanceof HazelcastInstanceAware) {
     ((HazelcastInstanceAware) mapListener).setHazelcastInstance(hazelcastInstance);
   }
 }