Init() 공개 메소드

public Init ( ISocketInterceptor socketInterceptor ) : void
socketInterceptor ISocketInterceptor
리턴 void
        private ClientConnection InitializeConnection(Address address, Authenticator authenticator)
        {
            CheckLive();
            ClientConnection connection = null;
            var id = _nextConnectionId;

            try
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Creating new connection for " + address + " with id " + id);
                }

                connection = new ClientConnection(this, (ClientInvocationService)_client.GetInvocationService(), id, address, _networkConfig);

                connection.Init(_socketInterceptor);
                authenticator(connection);
                Interlocked.Increment(ref _nextConnectionId);
                Logger.Finest("Authenticated to " + connection);
                return(connection);
            }
            catch (Exception e)
            {
                Logger.Severe("Error connecting to " + address + " with id " + id, e);
                if (connection != null)
                {
                    connection.Close();
                }
                throw ExceptionUtil.Rethrow(e, typeof(IOException), typeof(SocketException),
                                            typeof(TargetDisconnectedException));
            }
        }
        private void ClusterAuthenticator(ClientConnection connection)
        {
            var ss             = _client.GetSerializationService();
            var clusterService = (ClientClusterService)_client.GetClientClusterService();
            var principal      = clusterService.GetPrincipal();

            var           uuid      = principal.GetUuid();
            var           ownerUuid = principal.GetOwnerUuid();
            ClientMessage request;

            if (_credentials is UsernamePasswordCredentials)
            {
                var usernamePasswordCr = (UsernamePasswordCredentials)_credentials;
                request = ClientAuthenticationCodec.EncodeRequest(usernamePasswordCr.GetUsername(),
                                                                  usernamePasswordCr.GetPassword(), uuid, ownerUuid, false,
                                                                  ClientTypes.Csharp, _client.GetSerializationService().GetVersion());
            }
            else
            {
                var data = ss.ToData(_credentials);
                request = ClientAuthenticationCustomCodec.EncodeRequest(data, uuid, ownerUuid, false,
                                                                        ClientTypes.Csharp, _client.GetSerializationService().GetVersion());
            }

            connection.Init();
            IClientMessage response;

            try
            {
                var future = ((ClientInvocationService)_client.GetInvocationService()).InvokeOnConnection(request, connection);
                response = ThreadUtil.GetResult(future);
            }
            catch (Exception e)
            {
                throw ExceptionUtil.Rethrow(e);
            }
            var rp     = ClientAuthenticationCodec.DecodeResponse(response);
            var member = _client.GetClientClusterService().GetMember(rp.address);

            if (member == null)
            {
                throw new HazelcastException("Node with address '" + rp.address + "' was not found in the member list");
            }
            connection.SetRemoteMember(member);
        }
예제 #3
0
        private ClientConnection InitializeConnection(Address address, bool isOwner)
        {
            CheckLive();
            ClientConnection connection = null;
            var id = _nextConnectionId;

            var publicAddress = _client.GetAddressProvider().TranslateToPublic(address);

            try
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Creating new connection for " + publicAddress + " with id " + id);
                }
                connection = new ClientConnection(this, (ClientInvocationService)_client.GetInvocationService(), id,
                                                  publicAddress, _networkConfig);
                connection.Init(_socketInterceptor);
                Authenticate(connection, isOwner);
                Interlocked.Increment(ref _nextConnectionId);
                Logger.Finest("Authenticated to " + connection);
                return(connection);
            }
            catch (Exception e)
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Error connecting to " + publicAddress + " with id " + id, e);
                }

                if (connection != null)
                {
                    connection.Close();
                }
                throw ExceptionUtil.Rethrow(e, typeof(IOException), typeof(SocketException), typeof(TargetDisconnectedException));
            }
        }
        private ClientConnection InitializeConnection(Address address, Authenticator authenticator)
        {
            CheckLive();
            ClientConnection connection = null;
            var id = _nextConnectionId;
            try
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Creating new connection for " + address + " with id " + id);
                }

                connection = new ClientConnection(this, (ClientInvocationService) _client.GetInvocationService(), id, address, _networkConfig);

                connection.Init(_socketInterceptor);
                authenticator(connection);
                Interlocked.Increment(ref _nextConnectionId);
                Logger.Finest("Authenticated to " + connection);
                return connection;
            }
            catch (Exception e)
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Error connecting to " + address + " with id " + id, e);
                }

                if (connection != null)
                {
                    connection.Close();
                }
                throw ExceptionUtil.Rethrow(e, typeof (IOException), typeof (SocketException),
                    typeof (TargetDisconnectedException));
            }
        }
        private void ClusterAuthenticator(ClientConnection connection)
        {
            var ss = _client.GetSerializationService();
            var clusterService = (ClientClusterService) _client.GetClientClusterService();
            var principal = clusterService.GetPrincipal();

            var uuid = principal.GetUuid();
            var ownerUuid = principal.GetOwnerUuid();
            ClientMessage request;

            var usernamePasswordCr = _credentials as UsernamePasswordCredentials;
            if (usernamePasswordCr != null)
            {
                request = ClientAuthenticationCodec.EncodeRequest(usernamePasswordCr.GetUsername(),
                    usernamePasswordCr.GetPassword(), uuid, ownerUuid, false,
                    ClientTypes.Csharp, _client.GetSerializationService().GetVersion());
            }
            else
            {
                var data = ss.ToData(_credentials);
                request = ClientAuthenticationCustomCodec.EncodeRequest(data, uuid, ownerUuid, false,
                    ClientTypes.Csharp, _client.GetSerializationService().GetVersion());
            }

            connection.Init();
            IClientMessage response;
            try
            {
                var future = ((ClientInvocationService) _client.GetInvocationService()).InvokeOnConnection(request,
                    connection);
                response = ThreadUtil.GetResult(future);
            }
            catch (Exception e)
            {
                throw ExceptionUtil.Rethrow(e);
            }
            var rp = ClientAuthenticationCodec.DecodeResponse(response);
            var member = _client.GetClientClusterService().GetMember(rp.address);
            if (member == null)
            {
                throw new HazelcastException("Node with address '" + rp.address + "' was not found in the member list");
            }
            connection.SetRemoteMember(member);
        }
        private void ManagerAuthenticator(ClientConnection connection)
        {
            Logger.Finest("Authenticating against the owner node");
            var ss = _client.GetSerializationService();

            string uuid = null;
            string ownerUuid = null;
            if (_principal != null)
            {
                uuid = _principal.GetUuid();
                ownerUuid = _principal.GetOwnerUuid();
            }
            ClientMessage request;
            if (_credentials is UsernamePasswordCredentials)
            {
                var usernamePasswordCr = (UsernamePasswordCredentials) _credentials;
                request = ClientAuthenticationCodec.EncodeRequest(usernamePasswordCr.GetUsername(),
                    usernamePasswordCr.GetPassword(), uuid, ownerUuid, true,
                    ClientTypes.Csharp, _client.GetSerializationService().GetVersion());
            }
            else
            {
                var data = ss.ToData(_credentials);
                request = ClientAuthenticationCustomCodec.EncodeRequest(data, uuid, ownerUuid, false,
                    ClientTypes.Csharp, _client.GetSerializationService().GetVersion());
            }

            connection.Init();
            IClientMessage response;
            try
            {
                var invocationService = (ClientInvocationService) _client.GetInvocationService();
                response = ThreadUtil.GetResult(invocationService.InvokeOnConnection(request, connection));
            }
            catch (Exception e)
            {
                throw ExceptionUtil.Rethrow(e);
            }
            var result = ClientAuthenticationCodec.DecodeResponse(response);

            var member = new Member(result.address, result.ownerUuid);
            _principal = new ClientPrincipal(result.uuid, result.ownerUuid);

            connection.SetRemoteMember(member);
        }