Beispiel #1
0
            virtual public void Connect(Session owner, bool moveNext, out int streamId)
            {
                if (_hostsIter == null)
                {
                    _hostsIter = owner._policies.LoadBalancingPolicy.NewQueryPlan(Query).GetEnumerator();
                    if (!_hostsIter.MoveNext())
                    {
                        var ex = new NoHostAvailableException(new Dictionary <IPAddress, List <Exception> >());
                        _logger.Error(ex);
                        throw ex;
                    }
                }
                else
                {
                    if (moveNext)
                    {
                        if (!_hostsIter.MoveNext())
                        {
                            var ex = new NoHostAvailableException(InnerExceptions);
                            _logger.Error(ex);
                            throw ex;
                        }
                    }
                }

                Connection = owner.Connect(Query, _hostsIter, TriedHosts, InnerExceptions, out streamId);
            }
        private void SetupEventListener()
        {
            var triedHosts      = new List <IPAddress>();
            var innerExceptions = new Dictionary <IPAddress, List <Exception> >();

            var hostsIter = _session._policies.LoadBalancingPolicy.NewQueryPlan(null).GetEnumerator();

            if (!hostsIter.MoveNext())
            {
                var ex = new NoHostAvailableException(new Dictionary <IPAddress, List <Exception> >());
                _logger.Error(ex);
                throw ex;
            }

            int streamId;
            var nconn = _session.Connect(null, hostsIter, triedHosts, innerExceptions, out streamId);

            listeningOnHost = nconn.GetHostAdress();

            Exception theExc = null;

            nconn.CassandraEvent += new CassandraEventHandler(conn_CassandraEvent);
            using (var ret = nconn.RegisterForCassandraEvent(streamId,
                                                             CassandraEventType.TopologyChange | CassandraEventType.StatusChange | CassandraEventType.SchemaChange))
            {
                if (!(ret is OutputVoid))
                {
                    if (ret is OutputError)
                    {
                        theExc = (ret as OutputError).CreateException();
                    }
                    else
                    {
                        theExc = new DriverInternalError("Expected Error on Output");
                    }
                }
            }

            if (theExc != null)
            {
                _logger.Error(theExc);
                throw theExc;
            }
        }
Beispiel #3
0
        private void SetupEventListener()
        {
            var triedHosts      = new List <IPAddress>();
            var innerExceptions = new Dictionary <IPAddress, List <Exception> >();

            IEnumerator <Host> hostsIter = _session.Policies.LoadBalancingPolicy.NewQueryPlan(null).GetEnumerator();

            if (!hostsIter.MoveNext())
            {
                var ex = new NoHostAvailableException(new Dictionary <IPAddress, List <Exception> >());
                _logger.Error(ex);
                throw ex;
            }

            _activeConnection.Value = _session.Connect(hostsIter, triedHosts, innerExceptions, out _lockingStreamId);

            int streamId = _activeConnection.Value.AllocateStreamId();

            Exception theExc = null;

            _activeConnection.Value.CassandraEvent += conn_CassandraEvent;
            using (IOutput ret = _activeConnection.Value.RegisterForCassandraEvent(streamId,
                                                                                   CassandraEventType.TopologyChange | CassandraEventType.StatusChange |
                                                                                   CassandraEventType.SchemaChange))
            {
                if (!(ret is OutputVoid))
                {
                    if (ret is OutputError)
                    {
                        theExc = (ret as OutputError).CreateException();
                    }
                    else
                    {
                        theExc = new DriverInternalError("Expected Error on Output");
                    }
                }
            }

            if (theExc != null)
            {
                _logger.Error(theExc);
                throw theExc;
            }
        }
Beispiel #4
0
            public virtual void Connect(Session owner, bool moveNext, out int streamId)
            {
                if (_hostsIter == null)
                {
                    _hostsIter = owner._policies.LoadBalancingPolicy.NewQueryPlan(Query).GetEnumerator();
                    if (!_hostsIter.MoveNext())
                    {
                        var ex = new NoHostAvailableException(new Dictionary<IPAddress, List<Exception>>());
                        _logger.Error(ex);
                        throw ex;
                    }
                }
                else
                {
                    if (moveNext)
                        if (!_hostsIter.MoveNext())
                        {
                            var ex = new NoHostAvailableException(InnerExceptions);
                            _logger.Error(ex);
                            throw ex;
                        }
                }

                Connection = owner.Connect(_hostsIter, TriedHosts, InnerExceptions, out streamId);
            }