public String addItemListener(ItemListener<E> listener, boolean includeValue) { final EventService eventService = getNodeEngine().getEventService(); final EventRegistration registration = eventService.registerListener( getServiceName(), name, new CollectionEventFilter(includeValue), listener); return registration.getId(); }
String addClientListener(ClientListener clientListener) { final EventRegistration registration = nodeEngine .getEventService() .registerLocalListener(SERVICE_NAME, SERVICE_NAME, clientListener); return registration.getId(); }
public String addEventListener( EntryListener entryListener, EventFilter eventFilter, String mapName) { EventRegistration registration = nodeEngine .getEventService() .registerListener(SERVICE_NAME, mapName, eventFilter, entryListener); return registration.getId(); }
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()); } }
public static void main(String[] args) { // 콜백 수신 CallbackEvent callbackEvent = new CallbackEvent() { @Override public void callbackMethod() { System.out.println("returned callback message"); } }; // 시작. EventRegistration eventRegistration = new EventRegistration(callbackEvent); eventRegistration.doWork(); }
public void publishEvent( Address caller, String mapName, EntryEventType eventType, Data dataKey, Data dataOldValue, Data dataValue) { Collection<EventRegistration> candidates = nodeEngine.getEventService().getRegistrations(SERVICE_NAME, mapName); Set<EventRegistration> registrationsWithValue = new HashSet<EventRegistration>(); Set<EventRegistration> registrationsWithoutValue = new HashSet<EventRegistration>(); if (candidates.isEmpty()) return; Object key = null; Object value = null; Object oldValue = null; for (EventRegistration candidate : candidates) { EventFilter filter = candidate.getFilter(); if (filter instanceof EventServiceImpl.EmptyFilter) { registrationsWithValue.add(candidate); } else if (filter instanceof QueryEventFilter) { Object testValue; if (eventType == EntryEventType.REMOVED || eventType == EntryEventType.EVICTED) { oldValue = oldValue != null ? oldValue : toObject(dataOldValue); testValue = oldValue; } else { value = value != null ? value : toObject(dataValue); testValue = value; } key = key != null ? key : toObject(dataKey); QueryEventFilter queryEventFilter = (QueryEventFilter) filter; QueryEntry entry = new QueryEntry(getSerializationService(), dataKey, key, testValue); if (queryEventFilter.eval(entry)) { if (queryEventFilter.isIncludeValue()) { registrationsWithValue.add(candidate); } else { registrationsWithoutValue.add(candidate); } } } else if (filter.eval(dataKey)) { EntryEventFilter eventFilter = (EntryEventFilter) filter; if (eventFilter.isIncludeValue()) { registrationsWithValue.add(candidate); } else { registrationsWithoutValue.add(candidate); } } } if (registrationsWithValue.isEmpty() && registrationsWithoutValue.isEmpty()) return; String source = nodeEngine.getThisAddress().toString(); if (eventType == EntryEventType.REMOVED || eventType == EntryEventType.EVICTED) { dataValue = dataValue != null ? dataValue : dataOldValue; } EventData event = new EventData( source, mapName, caller, dataKey, dataValue, dataOldValue, eventType.getType()); int orderKey = dataKey.hashCode(); nodeEngine .getEventService() .publishEvent(SERVICE_NAME, registrationsWithValue, event, orderKey); nodeEngine .getEventService() .publishEvent( SERVICE_NAME, registrationsWithoutValue, event.cloneWithoutValues(), orderKey); }