예제 #1
0
        /// <summary>
        /// Removes a stored object from the pool and return it.
        /// If the pool is empty, instanceFactory will be called to generate a new object.
        /// </summary>
        /// <param name="instanceFactory">The instance factory method used to create a new instance if pool is empty.</param>
        public static T Get(Func <T> instanceFactory)
        {
            T item;

            if (!m_bag.TryPop(out item))
            {
                return(instanceFactory());
            }
            return(item);
        }
예제 #2
0
파일: Pool.cs 프로젝트: RocChing/ChatServer
        public IBuffer Pop()
        {
            IBuffer item;

            if (!mPool.TryPop(out item))
            {
                item = CreateBuffer();
            }
            item.Reset();
            return(item);
        }
예제 #3
0
파일: Pool.cs 프로젝트: zphcxj/BeetleX
        public IBuffer Pop()
        {
            IBuffer item;

            if (!mPool.TryPop(out item))
            {
                item = CreateBuffer();
            }
            item.Reset();
            Interlocked.Decrement(ref mCount);
            return(item);
        }
예제 #4
0
        public TcpClient Pop()
        {
            TcpClient result;

            if (!mPools.TryPop(out result))
            {
                int value = System.Threading.Interlocked.Increment(ref mConnections);
                if (value > mMaxConnections)
                {
                    System.Threading.Interlocked.Decrement(ref mConnections);
                    throw new Exception("Unable to reach HTTP request, exceeding maximum number of connections");
                }
                var packet = new HttpClientPacket();
                result           = SocketFactory.CreateClient <TcpClient>(packet, Host, Port);
                packet.Client    = result;
                result.Connected = c => { c.Socket.NoDelay = true; };
                result.Connect();
                result.Socket.SendTimeout    = TimeOut;
                result.Socket.ReceiveTimeout = TimeOut;
            }
            else
            {
                var value = System.Threading.Interlocked.Decrement(ref mPoolConnectins);
            }
            return(result);
        }
예제 #5
0
 public byte[] Pop()
 {
     byte[] result = null;
     if (mPool.TryPop(out result))
     {
         return(result);
     }
     return(new byte[mBufferSize]);
 }
예제 #6
0
        public ICall Pop()
        {
            ICall call;

            if (!_stack.TryPop(out call))
            {
                throw new InvalidOperationException("Stack empty");
            }
            return(call);
        }
예제 #7
0
        public bool TryPop(out T data)
        {
            bool result;

            result = mQueues.TryPop(out data);
            if (result)
            {
                System.Threading.Interlocked.Decrement(ref mCount);
            }
            return(result);
        }
예제 #8
0
        public static LineBuffer Pop()
        {
            LineBuffer buffer = null;

            if (!LineBUfferPool.TryPop(out buffer))
            {
                return(new LineBuffer());
            }
            buffer.Reset();
            return(buffer);
        }
예제 #9
0
        public IProtocolBuffer Pop()
        {
            IProtocolBuffer result = null;

            if (!mPool.TryPop(out result))
            {
                result = CreateBuffer();
            }

            result.Reset();
            return(result);
        }
예제 #10
0
        SocketAsyncEventArgs GetEventArgs()
        {
            SocketAsyncEventArgs outea = null;

            freeEventArgs.TryPop(out outea);
            if (outea == null)
            {
                outea            = new SocketAsyncEventArgs();
                outea.Completed += this.onCompleted;
            }
            return(outea);
        }
예제 #11
0
 public byte[] Pop()
 {
     byte[] result = null;
     if (mPools.TryPop(out result))
     {
         return(result);
     }
     else
     {
         return(new byte[mBufferLength]);
     }
 }
예제 #12
0
 public string[] ReadLines()
 {
     do
     {
         string[] lines;
         if (q.TryPop(out lines))
         {
             return(lines);
         }
         Task.Delay(5).Wait();
     }while (fileReadCompleted == false);
     return(null);
 }
예제 #13
0
        public T GetObject()
        {
            T obj;

            if (objects.TryPop(out obj))
            {
                return(obj);
            }
            else
            {
                return(objectGenerator());
            }
        }
예제 #14
0
        public virtual void HttpGetAsync(IEnumerable <string> urls)
        {
            UseCache = false;
            int ThreadNum = 4;

            System.Collections.Concurrent.ConcurrentStack <string> stack = new System.Collections.Concurrent.ConcurrentStack <string>(urls.Distinct());

            List <System.Threading.Tasks.Task <List <DownloadData> > > tasks = new List <System.Threading.Tasks.Task <List <DownloadData> > >();

            for (int i = 0; i < ThreadNum; i++)
            {
                var task = System.Threading.Tasks.Task.Factory.StartNew <List <DownloadData> >((n) =>
                {
                    List <DownloadData> list = new List <DownloadData>();
                    var c = this.GetCopy();
                    while (true)
                    {
                        string url = string.Empty;
                        if (stack.TryPop(out url))
                        {
                            DownloadData dd = new DownloadData()
                            {
                                Url = url, HTML = c.HttpGet(url)
                            };
                            list.Add(dd);
                        }
                        else
                        {
                            break;
                        }
                    }
                    c.Dispose();
                    return(list);
                }, System.Threading.Tasks.TaskCreationOptions.LongRunning);
                if (task != null)
                {
                    tasks.Add(task);
                }
            }
            System.Threading.Tasks.Task.WaitAll(tasks.ToArray());


            foreach (var item in tasks.SelectMany(n => n.Result))
            {
                casheDic.GetValueOrAdd(item.Url, item.HTML);
            }
            UseCache = true;
        }
예제 #15
0
파일: Log.cs 프로젝트: zdmta/openrpa
        public static void FunctionOutdent(string cls, string func, string message = "")
        {
            if (Config.local.log_to_file)
            {
                if (string.IsNullOrEmpty(message))
                {
                    LogLine(string.Join("::", functions.Reverse()) + "::END", "Func");
                    //LogLine(string.Format("[{0}][{1}][{2}]::END", cls, func, Indent, message), "Func");
                }
                else
                {
                    LogLine(string.Join("::", functions.Reverse()) + " " + message + "::END", "Func");
                    //LogLine(string.Format("[{0}][{1}][{2}]::END:{3}", cls, func, Indent, message), "Func");
                }
            }
            Indent--;
            string dummy = "";

            functions.TryPop(out dummy);
        }
예제 #16
0
            public T Get()
            {
                if (!_lastPlaced)
                {
                    lock (this)
                    {
                        if (!_lastPlaced)
                        {
                            var  setting = default(T);
                            bool gotLast = false;

                            while (_timestamped.Count > 0 && !gotLast)
                            {
                                gotLast = _timestamped.TryPop(out setting);
                            }

                            _last       = setting;
                            _lastPlaced = true;
                        }
                    }
                }
                Thread.MemoryBarrier();
                return(_last);
            }
예제 #17
0
 public bool TryPop(out T data)
 {
     return(mQueues.TryPop(out data));
 }