예제 #1
0
 private void DoAIteration(AsyncPattern target, Action done, GenCtx baseGCX)
 {
     abh.ch   = new CommonHandoff(looper.Handoff.cT, looper.Handoff.bc, baseGCX);
     abh.done = done;
     //RunPrepend steps the coroutine and places it before the current one,
     //so we can continue running on the same frame that the child finishes (if using waitchild).
     abh.RunPrependRIEnumerator(target(abh));
 }
예제 #2
0
 public IPromise <string> RequestToken()
 {
     return(new Promise <string>((resolve, reject) =>
     {
         var correlationId = new CorrelationID();
         AsyncHandlers.Add(correlationId, AsyncPattern <string> .Create(resolve, reject));
         Session.GenerateToken(correlationId);
     }));
 }
 public IPromise <Service> Request(string uri)
 {
     return(new Promise <Service>((resolve, reject) =>
     {
         var correlationId = new CorrelationID();
         AsyncHandlers.Add(correlationId, AsyncPattern <Service> .Create(resolve, reject));
         Session.OpenServiceAsync(uri, correlationId);
     }));
 }
        public StreamingClusterDataService(string host, int port)
        {
            Host = host;
            StreamingPort = port;

            _listenerAsync = AsyncPattern.Create(
                (listener, pattern) => listener.BeginGetContext(pattern.OnCompleted, null),
                OnBeginGetContextReceived,
                OnBeginGetContextError);
        }
예제 #5
0
        public RequestStreamWriter(Stream stream, Func<MemcachedCommand, MemcachedCommand> onCommandSent, Action onDisconnect)
        {
            _stream = stream;
            _onCommandSent = onCommandSent;
            _onDisconnect = onDisconnect;

            _writeAsync = AsyncPattern.Create(
                (strea, pattern) => BeginWrite(),
                OnBeginWriteComplete,
                OnBeginWriteFailed);
        }
        public override IPromise <bool> Request(Session session, Service service, Identity identity)
        {
            return(new Promise <bool>((resolve, reject) =>
            {
                var correlationId = new CorrelationID();
                AsyncHandlers.Add(correlationId, AsyncPattern <bool> .Create(resolve, reject));

                var request = CreateRequest(service, _clientIpAddress, _uuid);
                SendAuthorizationRequest(session, identity, request, correlationId);
            }));
        }
        private IPromise <bool> Request(Session session, Service service, Identity identity, string token)
        {
            return(new Promise <bool>((resolve, reject) =>
            {
                var correlationId = new CorrelationID();
                AsyncHandlers.Add(correlationId, AsyncPattern <bool> .Create(resolve, reject));

                var request = CreateRequest(service, token);
                SendAuthorizationRequest(session, identity, request, correlationId);
            }));
        }
예제 #8
0
        public MemcachedServer(string hostName, int port)
        {
            HostName = hostName;
            this.Port = port;

            _acceptTcpClientAsync = AsyncPattern.Create((listener, pattern) => listener.BeginAcceptTcpClient(pattern.OnCompleted, null), OnTcpClient, OnAcceptError);
            _readAsync = AsyncPattern.Create<Stream>((stream, pattern) => stream.BeginRead(_readBuffer, _currentByteInReadBuffer, _readBuffer.Length - _currentByteInReadBuffer, pattern.OnCompleted, null), OnRead, OnReadError);

            try
            {
                _tcpListener = new TcpListener(new IPEndPoint(IPAddress.Any, port));
                _tcpListener.Start();

                _acceptTcpClientAsync.BeginAsync(_tcpListener);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        public ResponseStreamReader(
            Stream stream,
            Func<int, MemcachedCommand> commandRetriever,
            Action<MemcachedCommand> onCommandComplete,
            Action<MemcachedCommand> onError,
            Action onDisconnect)
        {
            _onError = onError;
            _onCommandComplete = onCommandComplete;
            _commandRetriever = commandRetriever;
            _onDisconnect = onDisconnect;

            _stream = stream;
            _currentReadState = ReadResponseHeader;

            _readAsync = AsyncPattern.Create(
                (strea, pattern) => strea.BeginRead(_receiveBuffer, 0, _receiveBuffer.Length, pattern.OnCompleted, null),
                OnBeginReadCompleted,
                OnBeginReadFailed);

            BeginReading();
        }
예제 #10
0
        public CouchbaseClient(string bucketName, params Server[] servers)
        {
            lock (_gate)
            {
                _reconnectMemcachedAsync = AsyncPattern.Create<TcpClient, ReconnectAttempt>(
                    BeginMemcachedReconnection,
                    OnMemcacachedReconnectionCompleted,
                    OnMemcachedReconnectionError);

                _bucketName = bucketName;
                var cluster = new Cluster();

                foreach (var server in servers)
                {
                    cluster.AddServer(server);
                }
                
                BeginStreamingFromNewServersInCluster(cluster);
                
                _cluster = cluster;
            }
        }
예제 #11
0
        public HttpClient(string serverId, string hostName, int port, Action<string, HttpCommand> onFailure)
        {
            ServerId = serverId;
            HostName = hostName;
            Port = port;

            _onFailure = onFailure;

            _getResponseAsync = new AsyncPattern<HttpWebRequest, HttpCommand>(
                (request, pattern, command) => request.BeginGetResponse(pattern.OnCompleted, command),
                OnBeginGetResponseCompleted,
                OnBeginGetResponseFailed);

            _readAsync = new AsyncPattern<Stream, HttpCommand>(
                (stream, pattern, command) => 
                    {
                        ArraySegment<byte> buffer = command.HttpReadState.Buffer;
                        return stream.BeginRead(buffer.Array, buffer.Offset, buffer.Count, pattern.OnCompleted, command);
                    },
                OnBeginReadCompleted,
                OnBeginReadFailed);
        }
예제 #12
0
 public static SyncPattern Reexec(AsyncPattern ap) => sbh =>
 sbh.GCX.exec.RunRIEnumerator(ap(new AsyncHandoff(sbh)));
예제 #13
0
        private IAsyncResult BeginMemcachedReconnection(TcpClient tcpClient, AsyncPattern<TcpClient, ReconnectAttempt> pattern, ReconnectAttempt reconnectAttempt)
        {
            var result = tcpClient.BeginConnect(
                reconnectAttempt.Server.HostName,
                reconnectAttempt.Server.MemcachedPort,
                pattern.OnCompleted,
                reconnectAttempt);

            return result;
        }