@Test
 public void testIssue321() throws Exception {
   HazelcastClient hClient = getHazelcastClient();
   final IMap<Integer, Integer> imap = hClient.getMap("testIssue321_1");
   final BlockingQueue<EntryEvent<Integer, Integer>> events1 =
       new LinkedBlockingQueue<EntryEvent<Integer, Integer>>();
   final BlockingQueue<EntryEvent<Integer, Integer>> events2 =
       new LinkedBlockingQueue<EntryEvent<Integer, Integer>>();
   imap.addEntryListener(
       new EntryAdapter<Integer, Integer>() {
         @Override
         public void entryAdded(EntryEvent event) {
           events2.add(event);
         }
       },
       false);
   imap.addEntryListener(
       new EntryAdapter<Integer, Integer>() {
         @Override
         public void entryAdded(EntryEvent event) {
           events1.add(event);
         }
       },
       true);
   imap.put(1, 1);
   final EntryEvent<Integer, Integer> event1 = events1.poll(10, TimeUnit.MILLISECONDS);
   final EntryEvent<Integer, Integer> event2 = events2.poll(10, TimeUnit.MILLISECONDS);
   assertNotNull(event1);
   assertNotNull(event2);
   assertNotNull(event1.getValue());
   assertNull(event2.getValue());
 }
Exemple #2
0
 @SuppressWarnings("unchecked")
 public void dispatchEvent(EventData eventData, EntryListener listener) {
   Member member = nodeEngine.getClusterService().getMember(eventData.getCaller());
   EntryEvent event =
       new DataAwareEntryEvent(
           member,
           eventData.getEventType(),
           eventData.getMapName(),
           eventData.getDataKey(),
           eventData.getDataNewValue(),
           eventData.getDataOldValue(),
           getSerializationService());
   switch (event.getEventType()) {
     case ADDED:
       listener.entryAdded(event);
       break;
     case EVICTED:
       listener.entryEvicted(event);
       break;
     case UPDATED:
       listener.entryUpdated(event);
       break;
     case REMOVED:
       listener.entryRemoved(event);
       break;
     default:
       throw new IllegalArgumentException("Invalid event type: " + event.getEventType());
   }
   MapContainer mapContainer = getMapContainer(eventData.getMapName());
   if (mapContainer.getMapConfig().isStatisticsEnabled()) {
     getLocalMapStatsImpl(eventData.getMapName()).incrementReceivedEvents();
   }
 }
 @Override
 public void entryUpdated(EntryEvent<K, V> entry) {
   K k = entry.getKey();
   ChoosableSet<V> entries = cache.get(k);
   if (entries != null) {
     entries.add(entry.getValue());
   }
 }
 @Override
 public void entryAdded(EntryEvent<String, BpmEvent> event) {
   BpmEvent bpmEvent = event.getValue();
   logger.log(
       Level.INFO,
       "BpmEventListener.entryAdded executor {0}",
       new Object[] {bpmEvent.getExecutor()});
   try {
     BpmEvent.EXECUTOR executor = bpmEvent.getExecutor();
     switch (executor) {
       case ACTOR_RESOLVER:
         InternalAPI.get().executeActorResolver(bpmEvent.getCaseId(), bpmEvent.getTaskId());
         break;
       case CONNECTOR:
         InternalAPI.get().executeConnectorOut(bpmEvent.getCaseId(), bpmEvent.getTaskId());
         break;
       case JOIN:
         InternalAPI.get()
             .executeJoin(bpmEvent.getCaseId(), bpmEvent.getTaskId(), bpmEvent.getJoinId());
         break;
       case TRANSITION:
         InternalAPI.get().executeTransition(bpmEvent.getCaseId(), bpmEvent.getTaskId());
         break;
     }
     HazelcastServer.removeBpmEvent(bpmEvent);
   } catch (Exception ex) {
     logger.log(Level.SEVERE, ex.getMessage(), ex);
   }
 }
  @Override
  public void dispatchEvent(Object event, Object listener) {
    if ((event instanceof EntryEventData)) {
      EntryEventData entryEventData = (EntryEventData) event;
      Member member = getMember(entryEventData);
      EntryEvent entryEvent = createDataAwareEntryEvent(entryEventData, member);
      EntryListener entryListener = (EntryListener) listener;
      switch (entryEvent.getEventType()) {
        case ADDED:
          entryListener.entryAdded(entryEvent);
          break;
        case EVICTED:
          entryListener.entryEvicted(entryEvent);
          break;
        case UPDATED:
          entryListener.entryUpdated(entryEvent);
          break;
        case REMOVED:
          entryListener.entryRemoved(entryEvent);
          break;
        default:
          throw new IllegalArgumentException(
              "event type " + entryEvent.getEventType() + " not supported");
      }

      String mapName = ((EntryEventData) event).getMapName();
      Boolean statisticsEnabled = statisticsMap.get(mapName);
      if (statisticsEnabled == null) {
        ReplicatedMapConfig mapConfig = config.findReplicatedMapConfig(mapName);
        statisticsEnabled = mapConfig.isStatisticsEnabled();
        statisticsMap.put(mapName, statisticsEnabled);
      }
      if (statisticsEnabled) {
        int partitionId =
            nodeEngine.getPartitionService().getPartitionId(entryEventData.getDataKey());
        ReplicatedRecordStore recordStore =
            replicatedMapService.getPartitionContainer(partitionId).getRecordStore(mapName);
        if (recordStore instanceof AbstractReplicatedRecordStore) {
          LocalReplicatedMapStatsImpl stats =
              ((AbstractReplicatedRecordStore) recordStore).getStats();
          stats.incrementReceivedEvents();
        }
      }
    } else if (event instanceof MapEventData) {
      MapEventData mapEventData = (MapEventData) event;
      Member member = getMember(mapEventData);
      MapEvent mapEvent =
          new MapEvent(
              mapEventData.getMapName(),
              member,
              mapEventData.getEventType(),
              mapEventData.getNumberOfEntries());
      EntryListener entryListener = (EntryListener) listener;
      EntryEventType type = EntryEventType.getByType(mapEventData.getEventType());
      switch (type) {
        case CLEAR_ALL:
          entryListener.mapCleared(mapEvent);
          break;
        default:
          throw new IllegalArgumentException("event type " + type + " not supported");
      }
    }
  }
 public void entryRemoved(EntryEvent<String, ExpiringSession> event) {
   if (logger.isDebugEnabled()) {
     logger.debug("Session deleted with id: " + event.getOldValue().getId());
   }
   this.eventPublisher.publishEvent(new SessionDeletedEvent(this, event.getOldValue()));
 }
 public void entryAdded(EntryEvent<String, ExpiringSession> event) {
   if (logger.isDebugEnabled()) {
     logger.debug("Session created with id: " + event.getValue().getId());
   }
   this.eventPublisher.publishEvent(new SessionCreatedEvent(this, event.getValue()));
 }
 @Override
 public void entryRemoved(EntryEvent<K, V> entry) {
   removeEntry(entry.getKey(), entry.getValue());
 }
 @Override
 public void entryAdded(EntryEvent<K, V> entry) {
   addEntry(entry.getKey(), entry.getValue());
 }