public LatencyStrategy(ILatencyPerformer latencyPerformer, RateManager rateManager, Func <TimeSpan> latencyProvider, Func <double> rateProvider, IRequestStrategy baseStrategy)
 {
     this.latencyPerformer = latencyPerformer;
     this.rateManager      = rateManager;
     this.latencyProvider  = latencyProvider;
     this.rateProvider     = rateProvider;
     this.baseStrategy     = baseStrategy;
 }
Exemple #2
0
 public void SetUp()
 {
     idempotencyIdentifier = Substitute.For <IIdempotencyIdentifier>();
     sequential1Strategy   = Substitute.For <IRequestStrategy>();
     forkingStrategy       = Substitute.For <IRequestStrategy>();
     strategy = new IdempotencySignBasedRequestStrategy(idempotencyIdentifier, sequential1Strategy, forkingStrategy);
     request  = Request.Get("http://localhost:80/foo/bar");
 }
 public PiecePicker(IBtClient client, HandlerExchange exchange, IRequestStrategy requestStrategy, int blockLen, CancellationToken?cancelToken)
 {
     _pickerTask         = new Task(StartRequesting);
     _client             = client;
     _exchange           = exchange;
     RequestStrategy     = requestStrategy;
     _blockLen           = blockLen;
     _myCancelTokenOwner = new CancellationTokenSource();
     _outCancelToken     = cancelToken ?? _myCancelTokenOwner.Token;
 }
 private RequestParameters(
     IRequestStrategy strategy,
     RequestPriority?priority,
     ImmutableArrayDictionary <string, object> properties,
     TimeSpan?connectionTimeout)
 {
     Strategy          = strategy;
     Priority          = priority;
     ConnectionTimeout = connectionTimeout;
     this.properties   = properties ?? ImmutableArrayDictionary <string, object> .Empty;
 }
 public OrignIpHashRequestStrategy(SpiderService spiderService) : base(spiderService)
 {
     if (_requestStrategy == null)
     {
         lock (obj)
         {
             if (_requestStrategy == null)
             {
                 _requestStrategy = new RoundRobinRequestStrategy(SpiderService);
             }
         }
     }
 }
 public override IRequestStrategy GetRequestStrategy()
 {
     if (_requestStrategy == null)
     {
         lock (obj)
         {
             if (_requestStrategy == null)
             {
                 _requestStrategy = new RoundRobinRequestStrategy(TargetSpiderService);
             }
         }
     }
     return _requestStrategy;
 }
Exemple #7
0
 public override IRequestStrategy GetRequestStrategy()
 {
     if (_requestStrategy == null)
     {
         lock (obj)
         {
             if (_requestStrategy == null)
             {
                 _requestStrategy = new RandomRequestStrategy(TargetSpiderService);
             }
         }
     }
     return(_requestStrategy);
 }
 public static Task <ClusterResult> SendAsync(
     [NotNull] this IClusterClient client,
     [NotNull] Request request,
     [CanBeNull] TimeSpan?timeout          = null,
     [CanBeNull] IRequestStrategy strategy = null,
     [CanBeNull] RequestPriority?priority  = null,
     CancellationToken cancellationToken   = default)
 => client.SendAsync(
     request,
     RequestParameters.Empty
     .WithStrategy(strategy)
     .WithPriority(priority),
     timeout,
     cancellationToken);
 public static ClusterResult Send(
     [NotNull] this IClusterClient client,
     [NotNull] Request request,
     [CanBeNull] TimeSpan?timeout          = null,
     [CanBeNull] IRequestStrategy strategy = null,
     CancellationToken cancellationToken   = default(CancellationToken),
     [CanBeNull] RequestPriority?priority  = null,
     [CanBeNull] string operationName      = null)
 {
     using (operationName == null ? null : Context.Properties.Use(TracingAnnotationNames.Operation, operationName))
     {
         return(client.SendAsync(request, timeout, strategy, cancellationToken, priority).GetAwaiter().GetResult());
     }
 }
 /// <inheritdoc cref="SendAsync"/>
 public static ClusterResult Send(
     [NotNull] this IClusterClient client,
     [NotNull] Request request,
     [CanBeNull] TimeSpan?timeout          = null,
     [CanBeNull] IRequestStrategy strategy = null,
     [CanBeNull] RequestPriority?priority  = null,
     CancellationToken cancellationToken   = default)
 => client.SendAsync(
     request,
     timeout,
     strategy,
     priority,
     cancellationToken)
 .GetAwaiter()
 .GetResult();
Exemple #11
0
 public Task <ClusterResult> SendAsync(
     Request request,
     TimeSpan?timeout                    = null,
     IRequestStrategy strategy           = null,
     CancellationToken cancellationToken = default(CancellationToken),
     RequestPriority?priority            = null)
 {
     return(pipelineDelegate(
                CreateContext(
                    request,
                    timeout ?? configuration.DefaultTimeout,
                    strategy ?? configuration.DefaultRequestStrategy,
                    cancellationToken,
                    priority ?? configuration.DefaultPriority,
                    configuration.MaxReplicasUsedPerRequest)
                ));
 }
        public RequestContext(
            Request request,
            IRequestStrategy strategy,
            IRequestTimeBudget budget,
            ILog log,
            CancellationToken cancellationToken,
            RequestPriority?priority,
            int maximumReplicasToUse)
        {
            Request              = request;
            Strategy             = strategy;
            Budget               = budget;
            Log                  = log;
            Priority             = priority;
            CancellationToken    = cancellationToken;
            MaximumReplicasToUse = maximumReplicasToUse;

            ResetReplicaResults();
        }
            public override void PreStart()
            {
                _receiveBuffer   = new ModuloFixedSizeBuffer <TOut>(Settings.BufferCapacity);
                _requestStrategy = new WatermarkRequestStrategy(highWatermark: _receiveBuffer.Capacity);

                _stageActor = GetStageActor(InitialReceive);

                Log.Debug("[{0}] Allocated receiver: {1}", StageActorName, Self);

                var initialPartnerRef = _stage._initialPartnerRef;

                if (initialPartnerRef != null) // this will set the partnerRef
                {
                    ObserveAndValidateSender(initialPartnerRef, "<should never happen>");
                }

                _promise.SetResult(new SinkRefImpl <TOut>(Self));

                //this timer will be cancelled if we receive the handshake from the remote SinkRef
                // either created in this method and provided as self.ref as initialPartnerRef
                // or as the response to first CumulativeDemand request sent to remote SinkRef
                ScheduleOnce(SubscriptionTimeoutKey, SubscriptionTimeout.Timeout);
            }
 /// <summary>
 /// Create a new instance of <see cref="RequestParameters"/> with specified <paramref name="strategy"/> and <paramref name="priority"/>.
 /// </summary>
 public RequestParameters([CanBeNull] IRequestStrategy strategy = null, [CanBeNull] RequestPriority?priority = null)
     : this(strategy, priority, null, null)
 {
     Strategy = strategy;
     Priority = priority;
 }
 public RequestStrategySubscriber(IActorRef probe, IRequestStrategy strat)
 {
     _probe          = probe;
     RequestStrategy = strat;
 }
 public static Props Props(IActorRef probe, IRequestStrategy strat)
 => Akka.Actor.Props.Create(() => new RequestStrategySubscriber(probe, strat)).WithDispatcher("akka.test.stream-dispatcher");
 public RequestStrategySubscriber(IActorRef probe, IRequestStrategy strat)
 {
     _probe = probe;
     RequestStrategy = strat;
 }
 public static Props Props(IActorRef probe, IRequestStrategy strat)
     => Akka.Actor.Props.Create(() => new RequestStrategySubscriber(probe, strat)).WithDispatcher("akka.test.stream-dispatcher");
 /// <returns>New instance of <see cref="RequestParameters"/> with specified <paramref name="strategy"/>.</returns>
 public RequestParameters WithStrategy([CanBeNull] IRequestStrategy strategy)
 => ReferenceEquals(Strategy, strategy)
         ? this
         : new RequestParameters(strategy, Priority, properties, ConnectionTimeout);
Exemple #20
0
 public IdempotencySignBasedRequestStrategy(IIdempotencyIdentifier idempotencyIdentifier, IRequestStrategy sequential1Strategy, IRequestStrategy forkingStrategy)
 {
     this.sequential1Strategy   = sequential1Strategy;
     this.forkingStrategy       = forkingStrategy;
     this.idempotencyIdentifier = idempotencyIdentifier;
 }
Exemple #21
0
 private RequestContext CreateContext(Request request, TimeSpan timeout, IRequestStrategy strategy, CancellationToken cancellationToken, RequestPriority?priority, int maxReplicasToUse)
 {
     return(new RequestContext(request, strategy, RequestTimeBudget.StartNew(timeout, budgetPrecision), configuration.Log, cancellationToken, priority, maxReplicasToUse));
 }
Exemple #22
0
 public StrategySubscriber(IRequestStrategy requestStrategy)
 {
     RequestStrategy = requestStrategy;
 }
Exemple #23
0
        /// <summary>
        /// Creates new BtClient
        /// </summary>
        /// <param name="meta">Torrent metainfo</param>
        /// <param name="clientEndPoint">Client's external network endpoint. Must be accessible by other peers</param>
        /// <param name="defaultEncoding">Message text encoding</param>
        /// <param name="output">Output stream. If torrent contains multiple files </param>
        /// <param name="blockLen">Piece block length in bytes. 10^14 bytes if not specified</param>
        /// <param name="fileName">File name to download. If not specified all files will be downloaded</param>
        /// <param name="dhtEndPoint">Mainline DHT's client endpoint. DHT will not be used if parameter is null</param>
        /// <param name="storage">Storage for caching pieces. If not specified MemCachedPieceStorage will be used</param>
        /// <param name="cancelToken">Requesting cancel on this CancellationToken causes forcefull shutdown of client</param>
        public BtClient(Metainfo meta, IPEndPoint clientEndPoint, Encoding defaultEncoding, Stream output, int blockLen = 16384, string fileName = null, PiecePickStrategy piecePickStrategy = PiecePickStrategy.RarestFirst, IPEndPoint dhtEndPoint = null, IPieceStorage storage = null, CancellationToken?cancelToken = null)
        {
            Metainfo           = meta;
            _endPoint          = clientEndPoint;
            DefaultEncoding    = defaultEncoding;
            _peerId            = GeneratePeerId();
            Handshake          = CalcHandshake();
            BlockLength        = blockLen;
            BlocksInPieceCount = Metainfo.PieceLength / BlockLength;

            AnnounceManager = new AnnounceManager(this, Metainfo.Announces);
            IResourcePool <Peers.Peer> peersPool = AnnounceManager;

            if (dhtEndPoint != null)
            {
                MainlineManager = new MainlineManagerExt(clientEndPoint, dhtEndPoint, meta.InfoHash);

                peersPool = new MergedPool <Peer>(new IResourcePool <Peer>[] {
                    AnnounceManager,
                    MainlineManager
                });
            }

            if (storage == null)
            {
                storage = new FileStorage(Metainfo, BlockLength);
            }

            PieceStorage = storage;
            BitField piecesHave = PieceStorage.GetValidPieces();

            IRequestStrategy rqStrat = null;

            switch (piecePickStrategy)
            {
            case PiecePickStrategy.RarestFirst:
                RarestFirstRqStrategy rarestFirstRqStrategy = new RarestFirstRqStrategy(Metainfo.PiecesCount, piecesHave);
                rqStrat        = rarestFirstRqStrategy;
                PeerStateCache = new PeerStateCache(rarestFirstRqStrategy);
                break;

            case PiecePickStrategy.Random:
                rqStrat = new RandomPieceRqStrategy(Metainfo.PiecesCount, piecesHave);
                break;

            case PiecePickStrategy.Sequential:
                rqStrat = new SequentialPieceRqStrategy(Metainfo.PiecesCount);
                break;

            case PiecePickStrategy.SequentialOneFile:
                if (string.IsNullOrEmpty(fileName))
                {
                    throw new ArgumentException("fileName");
                }

                rqStrat = new SequentialPieceRqStrategyOneFile(Metainfo, fileName);
                break;

            default:
                break;
            }

            if (PeerStateCache == null)
            {
                PeerStateCache = new PeerStateCache();
            }

            ConnectionManager = new ConnectionHub(this, clientEndPoint, peersPool, PeerStateCache);

            HandlerExchange = new HandlerExchange(ConnectionManager, PeerStateCache);

            PiecePicker = new PiecePicker(this, HandlerExchange, rqStrat, BlockLength, cancelToken);
        }
Exemple #24
0
 public RequestController(IRequestStrategy requestStrategy)
 {
     _requestStrategy = requestStrategy;
 }