Exemple #1
0
 public static void Record(IInstrumentation inst, string source, long value)
 {
     if (inst != null && inst.Enabled)
     {
         inst.Record(new MessagingSinkErrorCount(source, value));
     }
 }
        public Connection(IPAddress address, TransportConfig config, ILogger logger, IInstrumentation instrumentation)
        {
            Endpoint = address;
            _config = config;
            _logger = logger;
            _instrumentation = instrumentation;
            _tcpClient = new TcpClient();
            _tcpClient.Connect(address, _config.Port);
            _streaming = config.Streaming;

            for (byte idx = 0; idx < MAX_STREAMID; ++idx)
            {
                _availableStreamIds.Push(idx);
            }

            _socket = _tcpClient.Client;

            // start a new read task
            Task.Factory.StartNew(ReadNextFrameHeader, _cancellation.Token);

            // readify the connection
            _logger.Debug("Readyfying connection for {0}", Endpoint);
            //GetOptions();
            ReadifyConnection();
            _logger.Debug("Connection to {0} is ready", Endpoint);
        }
 public LongRunningConnectionFactory(TransportConfig config, KeyspaceConfig keyspaceConfig, ILogger logger, IInstrumentation instrumentation)
 {
     _config = config;
     _keyspaceConfig = keyspaceConfig;
     _logger = logger;
     _instrumentation = instrumentation;
 }
        public LongRunningConnection(IPAddress address, TransportConfig config, KeyspaceConfig keyspaceConfig, ILogger logger, IInstrumentation instrumentation)
        {
            try
            {
                for (byte streamId = 0; streamId < MAX_STREAMID; ++streamId)
                {
                    _availableStreamIds.Push(streamId);
                }

                _config          = config;
                _keyspaceConfig  = keyspaceConfig;
                _logger          = logger;
                _instrumentation = instrumentation;

                Endpoint = address;
                DefaultConsistencyLevel = config.DefaultConsistencyLevel;
                DefaultExecutionFlags   = config.DefaultExecutionFlags;

                _tcpClient = new TcpClient
                {
                    ReceiveTimeout = _config.ReceiveTimeout,
                    SendTimeout    = _config.SendTimeout,
                    NoDelay        = true,
                    LingerState    = { Enabled = true, LingerTime = 0 },
                };

                _tcpClient.Connect(address, _config.Port);
                _socket = _tcpClient.Client;

                _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, _config.KeepAlive);
                if (_config.KeepAlive && 0 != _config.KeepAliveTime)
                {
                    SetTcpKeepAlive(_socket, _config.KeepAliveTime, 1000);
                }

                _pushResult = _config.ReceiveBuffering
                                      ? (Action <QueryInfo, IFrameReader, bool>)((qi, fr, a) => Task.Factory.StartNew(() => PushResult(qi, fr, a)))
                                      : PushResult;
                _responseWorker = Task.Factory.StartNew(() => RunWorker(ReadResponse), TaskCreationOptions.LongRunning);
                _queryWorker    = Task.Factory.StartNew(() => RunWorker(SendQuery), TaskCreationOptions.LongRunning);

                // readify the connection
                _logger.Debug("Readyfying connection for {0}", Endpoint);
                //GetOptions();
                ReadifyConnection();
                _logger.Debug("Connection to {0} is ready", Endpoint);
            }
            catch (Exception ex)
            {
                Dispose();

                _logger.Error("Failed building connection {0}", ex);
                throw;
            }
        }
 private static void QueryAndPushTracingSessionWorker(IConnection connection, Guid tracingId, InstrumentationToken token,
                                                      IInstrumentation instrumentation,
                                                      ILogger logger)
 {
     try
     {
         QueryAndPushTracingSession(connection, tracingId, token, instrumentation);
     }
     catch (Exception ex)
     {
         logger.Error("Failed to read performance for {0}: {1}", tracingId, ex);
     }
 }
        public static void Configure(CassandraSharpConfig config)
        {
            config.CheckArgumentNotNull("config");

            if (null != _config)
            {
                throw new InvalidOperationException("ClusterManager is already initialized");
            }

            _logger = Logger.Factory.Create(config.Logger);
            _recoveryService = Recovery.Factory.Create(config.Recovery, _logger);
            _instrumentation = Instrumentation.Factory.Create(config.Instrumentation);
            _config = config;
        }
        private static void QueryAndPushTracingSession(IConnection connection, Guid tracingId, InstrumentationToken token, IInstrumentation instrumentation)
        {
            string queryEvents = "select * from system_traces.events where session_id=" + tracingId;
            IDataMapperFactory facEvents = new DataMapperFactory<TracingEvent>(null);
            var obsEvents = CQLCommandHelpers.CreateQuery(connection, queryEvents, ConsistencyLevel.ONE, facEvents, ExecutionFlags.None).Cast<TracingEvent>();
            var tracingEvents = obsEvents.AsFuture().Result.ToList();
            tracingEvents.Sort(CompareTracingEvent);
            TracingEvent[] events = tracingEvents.ToArray();

            string querySession = "select * from system_traces.sessions where session_id=" + tracingId;

            IDataMapperFactory facSession = new DataMapperFactory<TracingSession>(null);
            var obsSession =
                    CQLCommandHelpers.CreateQuery(connection, querySession, ConsistencyLevel.ONE, facSession, ExecutionFlags.None).Cast<TracingSession>();
            TracingSession tracingSession = obsSession.AsFuture().Result.Single();
            tracingSession.TracingEvents = events;

            instrumentation.ServerTrace(token, tracingSession);
        }
        public void Shutdown()
        {
            lock (_lock)
            {
                _recoveryService.SafeDispose();
                _recoveryService = null;

                _instrumentation.SafeDispose();
                _instrumentation = null;

                _logger.SafeDispose();
                _logger = null;

                _config = null;
            }
        }
        public void Configure(CassandraSharpConfig config)
        {
            config.CheckArgumentNotNull("config");

            lock (_lock)
            {
                if (null != _config)
                {
                    throw new InvalidOperationException("ClusterManager is already initialized");
                }

                _logger = ServiceActivator<Logger.Factory>.Create<ILogger>(config.Logger.Type, config.Logger);
                _recoveryService = ServiceActivator<Recovery.Factory>.Create<IRecoveryService>(config.Recovery.Type, config.Recovery, _logger);
                _instrumentation = ServiceActivator<Instrumentation.Factory>.Create<IInstrumentation>(config.Instrumentation.Type, config.Instrumentation);
                _config = config;
            }
        }
 public ConnectionFactory(TransportConfig config, ILogger logger, IInstrumentation instrumentation)
 {
     _config = config;
     _logger = logger;
     _instrumentation = instrumentation;
 }
 public static void AsyncQueryAndPushTracingSession(IConnection connection, Guid tracingId, InstrumentationToken token, IInstrumentation instrumentation,
                                                    ILogger logger)
 {
     Task.Factory.StartNew(() => QueryAndPushTracingSessionWorker(connection, tracingId, token, instrumentation, logger));
 }