public String addDistributedObjectListener(final DistributedObjectListener listener) { final DistributedObjectListenerRequest request = new DistributedObjectListenerRequest(); final EventHandler<PortableDistributedObjectEvent> eventHandler = new EventHandler<PortableDistributedObjectEvent>() { public void handle(PortableDistributedObjectEvent e) { final ObjectNamespace ns = new DefaultObjectNamespace(e.getServiceName(), e.getName()); ClientProxyFuture future = proxies.get(ns); ClientProxy proxy = future == null ? null : future.get(); if (proxy == null) { proxy = getOrCreateProxy(e.getServiceName(), e.getName()); } DistributedObjectEvent event = new DistributedObjectEvent(e.getEventType(), e.getServiceName(), proxy); if (DistributedObjectEvent.EventType.CREATED.equals(e.getEventType())) { listener.distributedObjectCreated(event); } else if (DistributedObjectEvent.EventType.DESTROYED.equals(e.getEventType())) { listener.distributedObjectDestroyed(event); } } @Override public void beforeListenerRegister() {} @Override public void onListenerRegister() {} }; return client.getListenerService().startListening(request, null, eventHandler); }
public String addDistributedObjectListener(final DistributedObjectListener listener) { ClientMessage request = AddDistributedObjectListenerParameters.encode(); final EventHandler<ClientMessage> eventHandler = new EventHandler<ClientMessage>() { public void handle(ClientMessage clientMessage) { DistributedObjectEventParameters e = DistributedObjectEventParameters.decode(clientMessage); final ObjectNamespace ns = new DefaultObjectNamespace(e.serviceName, e.name); ClientProxyFuture future = proxies.get(ns); ClientProxy proxy = future == null ? null : future.get(); if (proxy == null) { proxy = getOrCreateProxy(e.serviceName, e.name); } DistributedObjectEvent event = new DistributedObjectEvent(e.eventType, e.serviceName, proxy); if (DistributedObjectEvent.EventType.CREATED.equals(e.eventType)) { listener.distributedObjectCreated(event); } else if (DistributedObjectEvent.EventType.DESTROYED.equals(e.eventType)) { listener.distributedObjectDestroyed(event); } } @Override public void beforeListenerRegister() {} @Override public void onListenerRegister() {} }; return client.getListenerService().startListening(request, null, eventHandler); }
public String addDistributedObjectListener(final DistributedObjectListener listener) { final EventHandler<ClientMessage> eventHandler = new DistributedObjectEventHandler(listener, this); return client .getListenerService() .registerListener(distributedObjectListenerCodec, eventHandler); }
private ClientInvocation( HazelcastClientInstanceImpl client, EventHandler handler, ClientMessage clientMessage, int partitionId, Address address, Connection connection) { this.lifecycleService = client.getLifecycleService(); this.invocationService = client.getInvocationService(); this.executionService = client.getClientExecutionService(); this.listenerService = (ClientListenerServiceImpl) client.getListenerService(); this.handler = handler; this.clientMessage = clientMessage; this.partitionId = partitionId; this.address = address; this.connection = connection; final ClientProperties clientProperties = client.getClientProperties(); int waitTime = clientProperties.getInvocationTimeoutSeconds().getInteger(); long retryTimeoutInSeconds = waitTime > 0 ? waitTime : Integer.parseInt(ClientProperties.PROP_INVOCATION_TIMEOUT_SECONDS_DEFAULT); clientInvocationFuture = new ClientInvocationFuture(this, client, clientMessage, handler); this.retryCountLimit = retryTimeoutInSeconds / RETRY_WAIT_TIME_IN_SECONDS; int interval = clientProperties.getHeartbeatInterval().getInteger(); this.heartBeatInterval = interval > 0 ? interval : Integer.parseInt(PROP_HEARTBEAT_INTERVAL_DEFAULT); }
public boolean removeDistributedObjectListener(String id) { final RemoveDistributedObjectListenerRequest request = new RemoveDistributedObjectListenerRequest(id); return client.getListenerService().stopListening(request, id); }
public boolean removeDistributedObjectListener(String id) { ClientMessage request = RemoveDistributedObjectListenerParameters.encode(id); return client.getListenerService().stopListening(request, id); }
public boolean removeDistributedObjectListener(String id) { return client.getListenerService().deregisterListener(id); }