Exemplo n.º 1
0
 private void sendMemberAttributeEvent(
     MemberImpl member, MemberAttributeOperationType operationType, String key, Object value) {
   final MemberAttributeServiceEvent event =
       new MemberAttributeServiceEvent(this, member, operationType, key, value);
   MemberAttributeEvent attributeEvent =
       new MemberAttributeEvent(this, member, operationType, key, value);
   Collection<MembershipAwareService> membershipAwareServices =
       nodeEngine.getServices(MembershipAwareService.class);
   if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) {
     for (final MembershipAwareService service : membershipAwareServices) {
       // service events should not block each other
       nodeEngine
           .getExecutionService()
           .execute(
               ExecutionService.SYSTEM_EXECUTOR,
               new Runnable() {
                 public void run() {
                   service.memberAttributeChanged(event);
                 }
               });
     }
   }
   EventService eventService = nodeEngine.getEventService();
   Collection<EventRegistration> registrations =
       eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
   for (EventRegistration reg : registrations) {
     eventService.publishEvent(SERVICE_NAME, reg, attributeEvent, reg.getId().hashCode());
   }
 }
Exemplo n.º 2
0
 void sendClientEvent(ClientEvent event) {
   final EventService eventService = nodeEngine.getEventService();
   final Collection<EventRegistration> regs =
       eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
   String uuid = event.getUuid();
   eventService.publishEvent(SERVICE_NAME, regs, event, uuid.hashCode());
 }
Exemplo n.º 3
0
 private void sendMembershipEventNotifications(
     MemberImpl member, Set<Member> members, final boolean added) {
   int eventType = added ? MembershipEvent.MEMBER_ADDED : MembershipEvent.MEMBER_REMOVED;
   MembershipEvent membershipEvent = new MembershipEvent(this, member, eventType, members);
   Collection<MembershipAwareService> membershipAwareServices =
       nodeEngine.getServices(MembershipAwareService.class);
   if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) {
     final MembershipServiceEvent event = new MembershipServiceEvent(membershipEvent);
     for (final MembershipAwareService service : membershipAwareServices) {
       nodeEngine
           .getExecutionService()
           .execute(
               MEMBERSHIP_EVENT_EXECUTOR_NAME,
               new Runnable() {
                 public void run() {
                   if (added) {
                     service.memberAdded(event);
                   } else {
                     service.memberRemoved(event);
                   }
                 }
               });
     }
   }
   EventService eventService = nodeEngine.getEventService();
   Collection<EventRegistration> registrations =
       eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
   for (EventRegistration reg : registrations) {
     eventService.publishEvent(SERVICE_NAME, reg, membershipEvent, reg.getId().hashCode());
   }
 }
Exemplo n.º 4
0
 private void flushInvalidationMessages(
     String cacheName, InvalidationEventQueue invalidationMessageQueue) {
   // If still in progress, no need to another attempt. So just ignore.
   if (invalidationMessageQueue.tryAcquire()) {
     try {
       CacheBatchInvalidationMessage batchInvalidationMessage =
           new CacheBatchInvalidationMessage(cacheName, invalidationMessageQueue.size());
       CacheSingleInvalidationMessage invalidationMessage;
       final int size = invalidationMessageQueue.size();
       // At most, poll from the invalidation queue as the current size of the queue before start
       // to polling.
       // So skip new invalidation queue items offered while the polling in progress in this round.
       for (int i = 0; i < size; i++) {
         invalidationMessage = invalidationMessageQueue.poll();
         if (invalidationMessage == null) {
           break;
         }
         batchInvalidationMessage.addInvalidationMessage(invalidationMessage);
       }
       EventService eventService = nodeEngine.getEventService();
       Collection<EventRegistration> registrations =
           eventService.getRegistrations(ICacheService.SERVICE_NAME, cacheName);
       if (!registrations.isEmpty()) {
         eventService.publishEvent(
             ICacheService.SERVICE_NAME,
             registrations,
             batchInvalidationMessage,
             cacheName.hashCode());
       }
     } finally {
       invalidationMessageQueue.release();
     }
   }
 }
Exemplo n.º 5
0
 private void sendClientEvent(ClientEndpoint endpoint) {
   if (endpoint.isFirstConnection()) {
     final EventService eventService = nodeEngine.getEventService();
     final Collection<EventRegistration> regs =
         eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
     eventService.publishEvent(SERVICE_NAME, regs, endpoint, endpoint.getUuid().hashCode());
   }
 }
  void publishEventInternal(
      Collection<EventRegistration> registrations, Object eventData, int orderKey) {
    final MapServiceContext mapServiceContext = this.mapServiceContext;
    final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    final EventService eventService = nodeEngine.getEventService();

    eventService.publishEvent(SERVICE_NAME, registrations, eventData, orderKey);
  }
Exemplo n.º 7
0
 void publishEvent(String cacheName, CacheEventSet eventSet, int orderKey) {
   final EventService eventService = nodeEngine.getEventService();
   final Collection<EventRegistration> candidates =
       eventService.getRegistrations(ICacheService.SERVICE_NAME, cacheName);
   if (candidates.isEmpty()) {
     return;
   }
   eventService.publishEvent(ICacheService.SERVICE_NAME, candidates, eventSet, orderKey);
 }
Exemplo n.º 8
0
  void publishEvent(CacheEventContext cacheEventContext) {
    final EventService eventService = nodeEngine.getEventService();
    final String cacheName = cacheEventContext.getCacheName();
    final Collection<EventRegistration> candidates =
        eventService.getRegistrations(ICacheService.SERVICE_NAME, cacheName);

    if (candidates.isEmpty()) {
      return;
    }
    final Object eventData;
    final CacheEventType eventType = cacheEventContext.getEventType();
    switch (eventType) {
      case CREATED:
      case UPDATED:
      case REMOVED:
      case EXPIRED:
        final CacheEventData cacheEventData =
            new CacheEventDataImpl(
                cacheName,
                eventType,
                cacheEventContext.getDataKey(),
                cacheEventContext.getDataValue(),
                cacheEventContext.getDataOldValue(),
                cacheEventContext.isOldValueAvailable());
        CacheEventSet eventSet = new CacheEventSet(eventType, cacheEventContext.getCompletionId());
        eventSet.addEventData(cacheEventData);
        eventData = eventSet;
        break;
      case EVICTED:
      case INVALIDATED:
        eventData =
            new CacheEventDataImpl(
                cacheName, eventType, cacheEventContext.getDataKey(), null, null, false);
        break;
      case COMPLETED:
        CacheEventData completedEventData =
            new CacheEventDataImpl(
                cacheName,
                eventType,
                cacheEventContext.getDataKey(),
                cacheEventContext.getDataValue(),
                null,
                false);
        eventSet = new CacheEventSet(eventType, cacheEventContext.getCompletionId());
        eventSet.addEventData(completedEventData);
        eventData = eventSet;
        break;
      default:
        throw new IllegalArgumentException(
            "Event Type not defined to create an eventData during publish : " + eventType.name());
    }
    eventService.publishEvent(
        ICacheService.SERVICE_NAME, candidates, eventData, cacheEventContext.getOrderKey());
  }
Exemplo n.º 9
0
 private void sendSingleInvalidationEvent(String name, Data key, String sourceUuid) {
   EventService eventService = nodeEngine.getEventService();
   Collection<EventRegistration> registrations =
       eventService.getRegistrations(ICacheService.SERVICE_NAME, name);
   if (!registrations.isEmpty()) {
     eventService.publishEvent(
         ICacheService.SERVICE_NAME,
         registrations,
         new CacheSingleInvalidationMessage(name, key, sourceUuid),
         name.hashCode());
   }
 }
 public void fireEntryListenerEvent(
     Data key, Data oldValue, Data value, EntryEventType eventType, String name, Address caller) {
   Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
   if (registrations.isEmpty()) {
     return;
   }
   EntryEventData eventData =
       new EntryEventData(name, name, caller, key, value, oldValue, eventType.getType());
   for (EventRegistration registration : registrations) {
     if (!shouldPublish(key, oldValue, value, eventType, registration.getFilter())) {
       continue;
     }
     eventService.publishEvent(SERVICE_NAME, registration, eventData, key.hashCode());
   }
 }
 public void fireMapClearedEvent(int deletedEntrySize, String name) {
   EventService eventService = nodeEngine.getEventService();
   Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
   if (registrations.isEmpty()) {
     return;
   }
   MapEventData mapEventData =
       new MapEventData(
           name,
           name,
           nodeEngine.getThisAddress(),
           EntryEventType.CLEAR_ALL.getType(),
           deletedEntrySize);
   eventService.publishEvent(SERVICE_NAME, registrations, mapEventData, name.hashCode());
 }
Exemplo n.º 12
0
 public void publishEvent(ItemEventType eventType, Data data) {
   EventService eventService = getNodeEngine().getEventService();
   Collection<EventRegistration> registrations =
       eventService.getRegistrations(getServiceName(), name);
   for (EventRegistration registration : registrations) {
     QueueEventFilter filter = (QueueEventFilter) registration.getFilter();
     QueueEvent event =
         new QueueEvent(
             name,
             filter.isIncludeValue() ? data : null,
             eventType,
             getNodeEngine().getThisAddress());
     eventService.publishEvent(getServiceName(), registration, event, name.hashCode());
   }
 }