public override void Created(BoltConnection connection) { BoltConnection previous = _activeConnections[connection.Id()] = connection; // We do not expect the same (keyed) connection twice Debug.Assert(previous == null); }
private void HandleCompletion(BoltConnection connection, bool?shouldContinueScheduling, Exception error) { try { if (error != null && ExceptionUtils.hasCause(error, typeof(RejectedExecutionException))) { connection.HandleSchedulingError(error); return; } } finally { // we need to ensure that the entry is removed only after any possible handleSchedulingError // call is completed. Otherwise, we can end up having different threads executing against // bolt state machine. _activeWorkItems.Remove(connection.Id()); } if (error != null) { _log.error(string.Format("Unexpected error during job scheduling for session '{0}'.", connection.Id()), error); StopConnection(connection); } else { if (shouldContinueScheduling && connection.HasPendingJobs()) { HandleSubmission(connection); } } }
private BoltConnection NewConnection(string id) { BoltConnection result = mock(typeof(BoltConnection)); when(result.Id()).thenReturn(id); when(result.RemoteAddress()).thenReturn(new InetSocketAddress("localhost", 32_000)); return(result); }
public override void Closed(BoltConnection connection) { string id = connection.Id(); try { CompletableFuture <bool> currentFuture = _activeWorkItems.Remove(id); if (currentFuture != null) { currentFuture.cancel(false); } } finally { _activeConnections.Remove(id); } }
internal virtual bool IsActive(BoltConnection connection) { return(_activeWorkItems.ContainsKey(connection.Id())); }
internal virtual bool IsRegistered(BoltConnection connection) { return(_activeConnections.ContainsKey(connection.Id())); }
private void StopConnection(BoltConnection connection) { try { connection.Stop(); } catch (Exception t) { _log.warn(string.Format("An unexpected error occurred while stopping BoltConnection [{0}]", connection.Id()), t); } }
private void HandleSubmission(BoltConnection connection) { _activeWorkItems.computeIfAbsent(connection.Id(), key => ScheduleBatchOrHandleError(connection).whenCompleteAsync((result, error) => handleCompletion(connection, result, error), _forkJoinPool)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void idShouldReturnBoltChannelId() public virtual void IdShouldReturnBoltChannelId() { BoltConnection connection = NewConnection(); assertEquals(_boltChannel.id(), connection.Id()); }