public AsyncCluster(AsyncClientPolicy policy, Host[] hosts) : base(policy, hosts)
        {
            maxCommands = policy.asyncMaxCommands;

            switch (policy.asyncMaxCommandAction)
            {
            case MaxCommandAction.REJECT: commandQueue = new AsyncCommandRejectingQueue(); break;

            case MaxCommandAction.BLOCK: commandQueue = new AsyncCommandBlockingQueue(); break;

            case MaxCommandAction.DELAY: commandQueue = new AsyncCommandDelayingQueue(); break;

            default: throw new AerospikeException(ResultCode.PARAMETER_ERROR, "Unsupported MaxCommandAction value: " + policy.asyncMaxCommandAction.ToString() + ".");
            }

            for (int i = 0; i < maxCommands; i++)
            {
                SocketAsyncEventArgs eventArgs = new SocketAsyncEventArgs();
                eventArgs.UserToken  = new BufferSegment();
                eventArgs.Completed += AsyncCommand.SocketListener;
                commandQueue.ReleaseArgs(eventArgs);
            }

            bufferPool = new BufferPool();
            InitTendThread(policy.failIfNotConnected);
        }
        public override void RunExample(Arguments a)
        {
            this.args = (BenchmarkArguments)a;
            shared = new BenchmarkShared(args);

            if (args.sync)
            {
                ClientPolicy policy = new ClientPolicy();
                policy.user = args.user;
                policy.password = args.password;
                policy.failIfNotConnected = true;
                client = new AerospikeClient(policy, args.host, args.port);

                try
                {
                    args.SetServerSpecific(client);
                    threads = new BenchmarkThreadSync[args.threadMax];
                    for (int i = 0; i < args.threadMax; i++)
                    {
                        threads[i] = new BenchmarkThreadSync(console, args, shared, this, client);
                    }
                    RunThreads();
                }
                finally
                {
                    client.Close();
                }
            }
            else
            {
                console.Info("Maximum concurrent commands: " + args.commandMax);

                AsyncClientPolicy policy = new AsyncClientPolicy();
                policy.user = args.user;
                policy.password = args.password;
                policy.failIfNotConnected = true;
                policy.asyncMaxCommands = args.commandMax;

                AsyncClient client = new AsyncClient(policy, args.host, args.port);
                this.client = client;

                try
                {
                    args.SetServerSpecific(client);
                    threads = new BenchmarkThreadAsync[args.threadMax];
                    for (int i = 0; i < args.threadMax; i++)
                    {
                        threads[i] = new BenchmarkThreadAsync(console, args, shared, this, client);
                    }
                    RunThreads();
                }
                finally
                {
                    client.Close();
                }
            }
        }
        public AsyncCluster(AsyncClientPolicy policy, Host[] hosts) : base(policy, hosts)
        {
            maxCommands = policy.asyncMaxCommands;
            block       = policy.asyncMaxCommandAction == MaxCommandAction.BLOCK;
            argsQueue   = new BlockingCollection <SocketAsyncEventArgs>(maxCommands);

            for (int i = 0; i < maxCommands; i++)
            {
                SocketAsyncEventArgs eventArgs = new SocketAsyncEventArgs();
                eventArgs.Completed += AsyncCommand.SocketListener;
                argsQueue.Add(eventArgs);
            }

            bufferPool = new BufferPool();
            InitTendThread(policy.failIfNotConnected);
        }
        public AsyncCluster(AsyncClientPolicy policy, Host[] hosts)
            : base(policy, hosts)
        {
            maxCommands = policy.asyncMaxCommands;
            block = policy.asyncMaxCommandAction == MaxCommandAction.BLOCK;
            argsQueue = new BlockingCollection<SocketAsyncEventArgs>(maxCommands);

            for (int i = 0; i < maxCommands; i++)
            {
                SocketAsyncEventArgs eventArgs = new SocketAsyncEventArgs();
                eventArgs.Completed += AsyncCommand.SocketListener;
                argsQueue.Add(eventArgs);
            }

            bufferPool = new BufferPool();
            InitTendThread(policy.failIfNotConnected);
        }
        public override void RunExample(Arguments args)
        {
            AsyncClientPolicy policy = new AsyncClientPolicy();
            policy.user = args.user;
            policy.password = args.password;
            policy.asyncMaxCommands = args.commandMax;
            policy.failIfNotConnected = true;

            AsyncClient client = new AsyncClient(policy, args.host, args.port);

            try
            {
                args.SetServerSpecific(client);
                RunExample(client, args);
            }
            finally
            {
                client.Close();
            }
        }
Example #6
0
        private void ConnectAsync()
        {
            AsyncClientPolicy policy = new AsyncClientPolicy();
            policy.asyncMaxCommands = 300;
            policy.failIfNotConnected = true;

            if (!user.Equals(""))
            {
                policy.user = user;
                policy.password = password;
            }

            asyncClient = new AsyncClient(policy, host, port);
        }
 /// <summary>
 /// Initialize asynchronous client with suitable hosts to seed the cluster map.
 /// The client policy is used to set defaults and size internal data structures.
 /// For each host connection that succeeds, the client will:
 /// <list type="bullet">
 /// <item>Add host to the cluster map</item>
 /// <item>Request host's list of other nodes in cluster</item>
 /// <item>Add these nodes to cluster map</item>
 /// </list>
 /// <para>
 /// In most cases, only one host is necessary to seed the cluster. The remaining hosts 
 /// are added as future seeds in case of a complete network failure.
 /// </para>
 /// <para>
 /// If one connection succeeds, the client is ready to process database requests.
 /// If all connections fail and the policy's failIfNotConnected is true, a connection 
 /// exception will be thrown. Otherwise, the cluster will remain in a disconnected state
 /// until the server is activated.
 /// </para>
 /// </summary>
 /// <param name="policy">client configuration parameters, pass in null for defaults</param>
 /// <param name="hosts">array of potential hosts to seed the cluster</param>
 /// <exception cref="AerospikeException">if all host connections fail</exception>
 public AsyncClient(AsyncClientPolicy policy, params Host[] hosts)
     : base(policy)
 {
     if (policy == null)
     {
         policy = new AsyncClientPolicy();
     }
     this.cluster = new AsyncCluster(policy, hosts);
     base.cluster = this.cluster;
 }
 /// <summary>
 /// Initialize asynchronous client.
 /// The client policy is used to set defaults and size internal data structures.
 /// If the host connection succeeds, the client will:
 /// <list type="bullet">
 /// <item>Add host to the cluster map</item>
 /// <item>Request host's list of other nodes in cluster</item>
 /// <item>Add these nodes to cluster map</item>
 /// </list>
 /// <para>
 /// If the connection succeeds, the client is ready to process database requests.
 /// If the connection fails and the policy's failOnInvalidHosts is true, a connection 
 /// exception will be thrown. Otherwise, the cluster will remain in a disconnected state
 /// until the server is activated.
 /// </para>
 /// </summary>
 /// <param name="policy">client configuration parameters, pass in null for defaults</param>
 /// <param name="hostname">host name</param>
 /// <param name="port">host port</param>
 /// <exception cref="AerospikeException">if host connection fails</exception>
 public AsyncClient(AsyncClientPolicy policy, string hostname, int port)
     : this(policy, new Host(hostname, port))
 {
 }