@Override public Object call() throws Exception { final ClientEndpoint endpoint = getEndpoint(); final ClientEngine clientEngine = getClientEngine(); ItemListener listener = new ItemListener() { @Override public void itemAdded(ItemEvent item) { send(item); } @Override public void itemRemoved(ItemEvent item) { send(item); } private void send(ItemEvent event) { if (endpoint.live()) { Data item = serializationService.toData(event.getItem()); final ItemEventType eventType = event.getEventType(); final String uuid = event.getMember().getUuid(); PortableItemEvent portableItemEvent = new PortableItemEvent(item, eventType, uuid); endpoint.sendEvent(portableItemEvent, getCallId()); } } }; final EventService eventService = clientEngine.getEventService(); final CollectionEventFilter filter = new CollectionEventFilter(includeValue); final EventRegistration registration = eventService.registerListener(getServiceName(), name, filter, listener); final String registrationId = registration.getId(); endpoint.setListenerRegistration(getServiceName(), name, registrationId); return registrationId; }
@Override public Object call() { final ClientEndpoint endpoint = getEndpoint(); final MapService mapService = getService(); EntryListener<Object, Object> listener = new EntryAdapter<Object, Object>() { @Override public void onEntryEvent(EntryEvent<Object, Object> event) { if (endpoint.isAlive()) { if (!(event instanceof DataAwareEntryEvent)) { throw new IllegalArgumentException( "Expecting: DataAwareEntryEvent, Found: " + event.getClass().getSimpleName()); } DataAwareEntryEvent dataAwareEntryEvent = (DataAwareEntryEvent) event; Data key = dataAwareEntryEvent.getKeyData(); Data value = dataAwareEntryEvent.getNewValueData(); Data oldValue = dataAwareEntryEvent.getOldValueData(); PortableEntryEvent portableEntryEvent = new PortableEntryEvent( key, value, oldValue, event.getEventType(), event.getMember().getUuid()); endpoint.sendEvent(key, portableEntryEvent, getCallId()); } } @Override public void onMapEvent(MapEvent event) { if (endpoint.isAlive()) { final EntryEventType type = event.getEventType(); final String uuid = event.getMember().getUuid(); PortableEntryEvent portableEntryEvent = new PortableEntryEvent(type, uuid, event.getNumberOfEntriesAffected()); endpoint.sendEvent(null, portableEntryEvent, getCallId()); } } }; final EventFilter eventFilter = getEventFilter(); final String registrationId = mapService.getMapServiceContext().addEventListener(listener, eventFilter, name); endpoint.setListenerRegistration(MapService.SERVICE_NAME, name, registrationId); return registrationId; }
public Object call() throws Exception { final TopicService service = getService(); final ClientEngine clientEngine = getClientEngine(); final ClientEndpoint endpoint = getEndpoint(); MessageListener listener = new MessageListener() { public void onMessage(Message message) { if (endpoint.live()) { Data messageData = clientEngine.toData(message.getMessageObject()); PortableMessage portableMessage = new PortableMessage( messageData, message.getPublishTime(), message.getPublishingMember().getUuid()); clientEngine.sendResponse(endpoint, portableMessage); } } }; String registrationId = service.addMessageListener(name, listener); endpoint.setListenerRegistration(TopicService.SERVICE_NAME, name, registrationId); return null; }