Ejemplo n.º 1
0
        public IAsyncResult BeginCreateWithCallback(byte[] key, byte[] value, int ttl, AsyncCallback acb, object state)
        {
            BrunetDhtPutOp op = new BrunetDhtPutOp(this._dht.Create);
            IAsyncResult   ar = op.BeginInvoke(key, value, ttl, acb, state);

            return(ar);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles results of async puts of pieces.
        /// </summary>
        /// <remarks>Fails on the first failed piece.</remarks>
        public void OnDhtPutReturns(IAsyncResult result)
        {
            AsyncResult              ar           = (AsyncResult)result;
            AsyncFragsOpState        apfs         = (AsyncFragsOpState)ar.AsyncState;
            BrunetDhtPutOp           op           = (BrunetDhtPutOp)ar.AsyncDelegate;
            AsyncPutFragsGlobalState global_state =
                (AsyncPutFragsGlobalState)apfs.GlobalState;
            AsyncOpState piece_state = apfs.PieceState;

            bool succ = op.EndInvoke(ar);

            lock (global_state.SyncRoot) {
                if (succ)
                {
                    Logger.WriteLineIf(LogLevel.Verbose, _log_props,
                                       string.Format("Put succeeded for piece: {0}",
                                                     Encoding.UTF8.GetString(piece_state.Key)));

                    global_state.OpSuccCount++;
                    if (global_state.OpSuccCount == global_state.ExpectedPositiveReturnNum)
                    {
                        Logger.WriteLineIf(LogLevel.Verbose, _log_props,
                                           string.Format("All pieces of {0} successfully put. Firing PutStoppedEvent",
                                                         Encoding.UTF8.GetString(global_state.BaseKey)));
                        global_state.Returns.Enqueue(new PutFragsStoppedEventArgs(null));
                    }
                    if ((global_state.Concurrency > 1 && global_state.OpSuccCount %
                         global_state.Concurrency == 0) || global_state.OpSuccCount ==
                        global_state.ExpectedPositiveReturnNum)
                    {
                        // put concurrently and a batch finishes.
                        global_state.BatchFinishedEvent.Set();
                    }
                }
                else
                {
                    Logger.WriteLineIf(LogLevel.Verbose, _log_props,
                                       string.Format("Put failed for piece: {0}. Firing PutStoppedEvent",
                                                     Encoding.UTF8.GetString(piece_state.Key)));
                    //No retry at this level currently, stop put operation.
                    global_state.Returns.Enqueue(new PutFragsStoppedEventArgs(piece_state));
                }
            }
        }
Ejemplo n.º 3
0
 public IAsyncResult BeginPutWithCallback(byte[] key, byte[] value, int ttl, AsyncCallback acb, object state)
 {
     BrunetDhtPutOp op = new BrunetDhtPutOp(this._dht.Put);
       IAsyncResult ar = op.BeginInvoke(key, value, ttl, acb, state);
       return ar;
 }