public string AddDistributedObjectListener(IDistributedObjectListener listener) { var isSmart = _client.GetClientConfig().GetNetworkConfig().IsSmartRouting(); var request = ClientAddDistributedObjectListenerCodec.EncodeRequest(isSmart); var context = new ClientContext(_client.GetSerializationService(), _client.GetClientClusterService(), _client.GetClientPartitionService(), _client.GetInvocationService(), _client.GetClientExecutionService(), _client.GetListenerService(), _client.GetNearCacheManager(), this, _client.GetClientConfig()); DistributedEventHandler eventHandler = delegate(IClientMessage message) { ClientAddDistributedObjectListenerCodec.EventHandler.HandleEvent(message, (name, serviceName, eventType) => { var _event = new LazyDistributedObjectEvent(eventType, serviceName, name, this); switch (eventType) { case DistributedObjectEvent.EventType.Created: listener.DistributedObjectCreated(_event); break; case DistributedObjectEvent.EventType.Destroyed: listener.DistributedObjectDestroyed(_event); break; default: Logger.Warning(string.Format("Undefined DistributedObjectListener event type received: {0} !!!", eventType)); break; } }); }; return(context.GetListenerService().RegisterListener(request, m => ClientAddDistributedObjectListenerCodec.DecodeResponse(m).response, ClientRemoveDistributedObjectListenerCodec.EncodeRequest, eventHandler)); }
protected override ClusterSubscription CreateSubscription() { return(new ClusterSubscription( ClientAddDistributedObjectListenerCodec.EncodeRequest(_isSmart), (message, state) => ClientAddDistributedObjectListenerCodec.DecodeResponse(message).Response, (id, state) => ClientRemoveDistributedObjectListenerCodec.EncodeRequest(id), (message, state) => ClientRemoveDistributedObjectListenerCodec.DecodeResponse(message).Response, (message, state) => ClientAddDistributedObjectListenerCodec.HandleEventAsync(message, HandleInternal, LoggerFactory))); }
public string AddDistributedObjectListener(IDistributedObjectListener listener) { var isSmart = _client.GetClientConfig().GetNetworkConfig().IsSmartRouting(); var request = ClientAddDistributedObjectListenerCodec.EncodeRequest(isSmart); var context = new ClientContext(_client.GetSerializationService(), _client.GetClientClusterService(), _client.GetClientPartitionService(), _client.GetInvocationService(), _client.GetClientExecutionService(), _client.GetListenerService(), this, _client.GetClientConfig()); //EventHandler<PortableDistributedObjectEvent> eventHandler = new _EventHandler_211(this, listener); DistributedEventHandler eventHandler = delegate(IClientMessage message) { ClientAddDistributedObjectListenerCodec.AbstractEventHandler.Handle(message, (name, serviceName, type) => { var ns = new ObjectNamespace(serviceName, name); ClientProxy proxy; _proxies.TryGetValue(ns, out proxy); if (proxy == null) { proxy = GetProxy(serviceName, name); } var _event = new DistributedObjectEvent(type, serviceName, proxy); if (DistributedObjectEvent.EventType.Created.Equals(type)) { listener.DistributedObjectCreated(_event); } else { if (DistributedObjectEvent.EventType.Destroyed.Equals(type)) { listener.DistributedObjectDestroyed(_event); } } }); }; //PortableDistributedObjectEvent return(context.GetListenerService().RegisterListener(request, m => ClientAddDistributedObjectListenerCodec.DecodeResponse(m).response, ClientRemoveDistributedObjectListenerCodec.EncodeRequest, eventHandler)); }
public Guid AddDistributedObjectListener(IDistributedObjectListener listener) { var listenerService = _client.ListenerService; var request = ClientAddDistributedObjectListenerCodec.EncodeRequest(listenerService.RegisterLocalOnly); void HandleDistributedObjectEvent(string name, string serviceName, string eventTypeName, Guid source) { var ns = new DistributedObjectInfo(serviceName, name); _proxies.TryGetValue(ns, out var lazyProxy); // ClientProxy proxy = future == null ? null : future.get(); var eventType = (DistributedObjectEvent.DistributedEventType)Enum.Parse(typeof(DistributedObjectEvent.DistributedEventType), eventTypeName); var _event = new DistributedObjectEvent(eventType, serviceName, name, lazyProxy.Value, source, this); switch (eventType) { case DistributedObjectEvent.DistributedEventType.CREATED: listener.DistributedObjectCreated(_event); break; case DistributedObjectEvent.DistributedEventType.DESTROYED: listener.DistributedObjectDestroyed(_event); break; default: Logger.Warning($"Undefined DistributedObjectListener event type received: {eventType} !!!"); break; } } void EventHandler(ClientMessage message) => ClientAddDistributedObjectListenerCodec.EventHandler.HandleEvent(message, HandleDistributedObjectEvent); return(listenerService.RegisterListener(request, m => ClientAddDistributedObjectListenerCodec.DecodeResponse(m).Response, ClientRemoveDistributedObjectListenerCodec.EncodeRequest, EventHandler)); }