Пример #1
0
        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));
        }
Пример #2
0
 public ClientMembershipListener(HazelcastClient client)
 {
     _client            = client;
     _connectionManager = (ClientConnectionManager)client.GetConnectionManager();
     _partitionService  = (ClientPartitionService)client.GetClientPartitionService();
     _clusterService    = (ClientClusterService)client.GetClientClusterService();
 }
 public ClientMembershipListener(HazelcastClient client)
 {
     _client = client;
     _connectionManager = (ClientConnectionManager) client.GetConnectionManager();
     _partitionService = (ClientPartitionService) client.GetClientPartitionService();
     _clusterService = (ClientClusterService) client.GetClientClusterService();
 }
Пример #4
0
        private ClientConnection GetConnectionForInvocation(ClientInvocation invocation)
        {
            if (invocation.BoundConnection != null)
            {
                if (!invocation.BoundConnection.Live)
                {
                    throw new HazelcastException(invocation.BoundConnection + " is no longer available");
                }
                return(invocation.BoundConnection);
            }

            Address address = null;

            if (invocation.Address != null)
            {
                address = invocation.Address;
            }
            else if (invocation.MemberUuid != null)
            {
                var member = _client.GetClientClusterService().GetMember(invocation.MemberUuid);
                if (member == null)
                {
                    throw new InvalidOperationException("Could not find a member with UUID " + invocation.MemberUuid);
                }
                address = member.GetAddress();
            }

            else if (invocation.PartitionId != -1)
            {
                address = _client.GetClientPartitionService().GetPartitionOwner(invocation.PartitionId);
            }
            return(GetConnection(address));
        }
        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));
        }
        private void ReinvokeInvocation(ClientInvocation invocation)
        {
            Address address = null;

            if (invocation.Address != null)
            {
                address = invocation.Address;
            }
            else if (invocation.MemberUuid != null)
            {
                var member = _client.GetClientClusterService().GetMember(invocation.MemberUuid);
                if (member == null)
                {
                    throw new InvalidOperationException("Could not find a member with UUID " + invocation.MemberUuid);
                }
                address = member.GetAddress();
            }
            else if (invocation.PartitionId != -1)
            {
                address = _client.GetClientPartitionService().GetPartitionOwner(invocation.PartitionId);
            }
            Invoke(invocation, address);
        }
Пример #7
0
        private Address GetNewInvocationAddress(ClientInvocation invocation)
        {
            Address newAddress = null;

            if (invocation.Address != null)
            {
                newAddress = invocation.Address;
            }
            else if (invocation.MemberUuid != null)
            {
                var member = _client.GetClientClusterService().GetMember(invocation.MemberUuid);
                if (member == null)
                {
                    Logger.Finest("Could not find a member with UUID " + invocation.MemberUuid);
                    throw new InvalidOperationException("Could not find a member with UUID " + invocation.MemberUuid);
                }
                newAddress = member.GetAddress();
            }
            else if (invocation.PartitionId != -1)
            {
                newAddress = _client.GetClientPartitionService().GetPartitionOwner(invocation.PartitionId);
            }
            return(newAddress);
        }