Ejemplo n.º 1
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);
     }
   }
 }
 @Test
 public void testTopicConfig() {
   TopicConfig testTopicConfig = config.getTopicConfig("testTopic");
   assertNotNull(testTopicConfig);
   assertEquals("testTopic", testTopicConfig.getName());
   assertEquals(1, testTopicConfig.getMessageListenerConfigs().size());
   ListenerConfig listenerConfig = testTopicConfig.getMessageListenerConfigs().get(0);
   assertEquals("com.hazelcast.spring.DummyMessageListener", listenerConfig.getClassName());
 }
 @Test
 public void testConfigListeners() {
   assertNotNull(membershipListener);
   List<ListenerConfig> list = config.getListenerConfigs();
   assertEquals(2, list.size());
   for (ListenerConfig lc : list) {
     if (lc.getClassName() != null) {
       assertNull(lc.getImplementation());
       assertEquals(DummyMembershipListener.class.getName(), lc.getClassName());
     } else {
       assertNotNull(lc.getImplementation());
       assertEquals(membershipListener, lc.getImplementation());
     }
   }
 }