public void Cancel() { PeerInfo current = Current; if (current == null) { return; } lock (_allocationLock) { current.Free(Contexts); Current = null; } AllocationChangeEventArgs args = new AllocationChangeEventArgs(current, null); Cancelled?.Invoke(this, args); }
public void AllocateBestPeer(IEnumerable <PeerInfo> peers, INodeStatsManager nodeStatsManager, IBlockTree blockTree) { PeerInfo current = Current; PeerInfo selected = _peerAllocationStrategy.Allocate(Current, peers, nodeStatsManager, blockTree); if (selected == current) { return; } AllocationChangeEventArgs args; lock (_allocationLock) { if (selected != null && selected.TryAllocate(Contexts)) { Current = selected; args = new AllocationChangeEventArgs(current, selected); current?.Free(Contexts); Replaced?.Invoke(this, args); } } }