public void DestroyConnection(ClientConnection connection) { var address = connection.GetAddress(); Logger.Finest("Destroying connection " + connection); lock (_connectionMutex) { if (address != null) { ClientConnection conn; if (_addresses.TryRemove(address, out conn)) { if (conn == connection) { connection.Close(); FireConnectionListenerEvent(f => f.ConnectionRemoved(connection)); } else { Logger.Warning(connection + " is already destroyed."); _addresses.TryAdd(address, conn); } } } } }
public void DestroyConnection(ClientConnection connection, Exception cause) { var address = connection.GetAddress(); Logger.Finest("Destroying connection " + connection + " due to " + cause.Message); if (address != null) { ClientConnection conn; if (_activeConnections.TryRemove(address, out conn)) { connection.Close(); FireConnectionListenerEvent(f => f.ConnectionRemoved(connection)); } else { Logger.Warning("Could not find connection " + connection + " in list of connections, could not destroy connection. Current list of connections are " + string.Join(", ", _activeConnections.Keys)); connection.Close(); } } else { // connection has not authenticated yet ((ClientInvocationService)_client.GetInvocationService()).CleanUpConnectionResources(connection); } }
public void DestroyConnection(ClientConnection connection) { var address = connection.GetAddress(); // ReSharper disable once InconsistentlySynchronizedField Logger.Finest("Destroying connection " + connection); if (address != null) { ClientConnection conn; if (_addresses.TryRemove(address, out conn)) { connection.Close(); FireConnectionListenerEvent(f => f.ConnectionRemoved(connection)); } } else { // connection has not authenticated yet ((ClientInvocationService)_client.GetInvocationService()).CleanUpConnectionResources(connection); } }
public void DestroyConnection(ClientConnection connection, Exception cause) { var address = connection.GetAddress(); Logger.Finest("Destroying connection " + connection + " due to " + cause.Message); if (address != null) { ClientConnection conn; if (_addresses.TryRemove(address, out conn)) { connection.Close(); FireConnectionListenerEvent(f => f.ConnectionRemoved(connection)); } else { Logger.Warning("Could not find connection " + connection + " in list of connections, could not destroy connection. Current list of connections are " + string.Join(", ", _addresses.Keys)); connection.Close(); } } else { // connection has not authenticated yet ((ClientInvocationService) _client.GetInvocationService()).CleanUpConnectionResources(connection); } }
public void DestroyConnection(ClientConnection connection) { var address = connection.GetAddress(); // ReSharper disable once InconsistentlySynchronizedField Logger.Finest("Destroying connection " + connection); if (address != null) { ClientConnection conn; if (_addresses.TryRemove(address, out conn)) { connection.Close(); FireConnectionListenerEvent(f => f.ConnectionRemoved(connection)); } } else { // connection has not authenticated yet ((ClientInvocationService) _client.GetInvocationService()).CleanUpConnectionResources(connection); } }
private void FailRequest(ClientConnection connection, ClientInvocation invocation) { if (_client.GetConnectionManager().Live) { HandleException(invocation, new TargetDisconnectedException(connection.GetAddress())); } else { FailRequestDueToShutdown(invocation); } }
private void ValidateInvocation(ClientInvocation clientInvocation, ClientConnection connection, bool bypassHeartbeat) { if (clientInvocation.MemberUuid != null && clientInvocation.MemberUuid != connection.Member.GetUuid()) { throw new TargetNotMemberException( "The member UUID on the invocation doesn't match the member UUID on the connection."); } if (!connection.IsHeartBeating && !bypassHeartbeat) { throw new TargetDisconnectedException(connection.GetAddress() + " has stopped heartbeating."); } if (_isShutDown) { throw new HazelcastException("Client is shut down."); } }
private void InvokeInternal(ClientInvocation invocation, Address address = null, ClientConnection connection = null, bool bypassHeartbeat = false) { try { if (connection == null) { if (address == null) { address = GetRandomAddress(); } connection = GetConnection(address); if (connection == null) { //Create an async conneciion and send the invocation afterward. _clientConnectionManager.GetOrConnectAsync(address).ContinueWith(t => { if (t.IsFaulted) { HandleInvocationException(invocation, t.Exception.Flatten().InnerExceptions.First()); } else { InvokeInternal(invocation, address, t.Result); } }) .ContinueWith(t => { HandleInvocationException(invocation, t.Exception.Flatten().InnerExceptions.First()); }, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); return; } } //Sending Invocation via connection UpdateInvocation(invocation, connection); ValidateInvocation(invocation, connection, bypassHeartbeat); if (!TrySend(invocation, connection)) { //Sending failed. if (_client.GetConnectionManager().Live) { throw new TargetDisconnectedException(connection.GetAddress(), "Error writing to socket."); } throw new HazelcastException("Client is shut down."); } //Successfully sended. } catch (Exception e) { HandleInvocationException(invocation, e); } }
private void CleanupInvocations(ClientConnection connection) { var keys = new List<long>(); foreach (var entry in _invocations) { if (entry.Value.SentConnection == connection) { keys.Add(entry.Key); } } foreach (var key in keys) { ClientInvocation invocation; if (_invocations.TryRemove(key, out invocation)) { var ex = _client.GetConnectionManager().Live ? new TargetDisconnectedException(connection.GetAddress(), "connection was closed.") : new HazelcastException("Client is shut down."); HandleInvocationException(invocation, ex); } } }
public void HeartBeatStopped(ClientConnection connection) { if (connection.GetAddress().Equals(_ownerConnectionAddress)) { _connectionManager.DestroyConnection(connection); } }
public void ConnectionRemoved(ClientConnection connection) { var executionService = (ClientExecutionService) _client.GetClientExecutionService(); if (Equals(connection.GetAddress(), _ownerConnectionAddress)) { if (_client.GetLifecycleService().IsRunning()) { executionService.SubmitInternal(() => { try { FireConnectionEvent(LifecycleEvent.LifecycleState.ClientDisconnected); ConnectToCluster(); } catch (Exception e) { Logger.Warning("Could not re-connect to cluster shutting down the client", e); _client.GetLifecycleService().Shutdown(); } }); } } }