Example #1
0
        public void RegisterCallback(String variableName, int agentInstanceId, VariableChangeCallback variableChangeCallback)
        {
            var metaData = _variables.Get(variableName);

            if (metaData == null)
            {
                return;
            }

            IDictionary <int, ICollection <VariableChangeCallback> > cps = _changeCallbacksPerCP[metaData.VariableNumber];

            if (cps == null)
            {
                cps = new Dictionary <int, ICollection <VariableChangeCallback> >();
                _changeCallbacksPerCP[metaData.VariableNumber] = cps;
            }

            if (metaData.ContextPartitionName == null)
            {
                agentInstanceId = EPStatementStartMethodConst.DEFAULT_AGENT_INSTANCE_ID;
            }

            ICollection <VariableChangeCallback> callbacks = cps.Get(agentInstanceId);

            if (callbacks == null)
            {
                callbacks = new CopyOnWriteArraySet <VariableChangeCallback>();
                cps.Put(agentInstanceId, callbacks);
            }
            callbacks.Add(variableChangeCallback);
        }
Example #2
0
        /// <summary>
        ///     Ctor.
        /// </summary>
        /// <param name="specification">configuration</param>
        /// <param name="runtimeURI">runtime URI</param>
        /// <param name="rwLockManager">the read-write lock manager</param>
        public MetricReportingServiceImpl(
            ConfigurationRuntimeMetricsReporting specification,
            string runtimeURI,
            IReaderWriterLockManager rwLockManager)
        {
            this.specification = specification;
            this.runtimeURI = runtimeURI;
            if (!specification.IsEnableMetricsReporting) {
                schedule = null;
                stmtMetricRepository = null;
                statementMetricHandles = null;
                metricsExecutor = null;
                return;
            }

            if (specification.IsEnableMetricsReporting) {
                //MetricUtil.Initialize();
            }

            schedule = new MetricScheduleService();

            stmtMetricRepository = new StatementMetricRepository(runtimeURI, specification, rwLockManager);
            statementGroupExecutions = new LinkedHashMap<string, MetricExecStatement>();
            statementMetricHandles = new Dictionary<DeploymentIdNamePair, StatementMetricHandle>();
            StatementOutputHooks = new CopyOnWriteArraySet<MetricsStatementResultListener>();

            if (specification.IsThreading) {
                metricsExecutor = new MetricsExecutorThreaded(runtimeURI);
            }
            else {
                metricsExecutor = new MetricsExecutorUnthreaded();
            }
        }
Example #3
0
 /// <summary>Constructor. </summary>
 protected FilterServiceBase(FilterServiceGranularLockFactory lockFactory, bool allowIsolation)
 {
     _lockFactory            = lockFactory;
     _eventTypeIndex         = new EventTypeIndex(lockFactory);
     _indexBuilder           = new EventTypeIndexBuilder(_eventTypeIndex, allowIsolation);
     _filterServiceListeners = new CopyOnWriteArraySet <FilterServiceListener>();
 }
        public void RegisterCallback(
            string deploymentId,
            string variableName,
            int agentInstanceId,
            VariableChangeCallback variableChangeCallback)
        {
            var entry = DeploymentsWithVariables.Get(deploymentId);

            var variable = entry?.GetVariable(variableName);
            if (variable == null) {
                return;
            }

            var cps = changeCallbacksPerCP[variable.VariableNumber];
            if (cps == null) {
                cps = new Dictionary<int, ICollection<VariableChangeCallback>>();
                changeCallbacksPerCP[variable.VariableNumber] = cps;
            }

            if (variable.MetaData.OptionalContextName == null) {
                agentInstanceId = DEFAULT_AGENT_INSTANCE_ID;
            }

            var callbacks = cps.Get(agentInstanceId);
            if (callbacks == null) {
                callbacks = new CopyOnWriteArraySet<VariableChangeCallback>();
                cps.Put(agentInstanceId, callbacks);
            }

            callbacks.Add(variableChangeCallback);
        }
Example #5
0
 protected FilterServiceBase(
     FilterServiceGranularLockFactory lockFactory,
     int stageId)
 {
     this.lockFactory = lockFactory;
     this.stageId = stageId;
     eventTypeIndex = new EventTypeIndex(lockFactory);
     indexBuilder = new EventTypeIndexBuilder(eventTypeIndex);
     filterServiceListeners = new CopyOnWriteArraySet<FilterServiceListener>();
 }
Example #6
0
 internal BaseConnection(string path, string connectionId, IDictionary parameters)
 {
     this._syncLock       = new object();
     this._basicScopes    = new CopyOnWriteArraySet <IBasicScope>();
     this._connectionId   = connectionId;
     this._objectEncoding = FluorineFx.ObjectEncoding.AMF0;
     this._path           = path;
     this._parameters     = parameters;
     this.SetIsClosed(false);
 }
Example #7
0
        public void Disconnect(IConnection connection)
        {
            IClient key = connection.Client;

            if (this._clients.ContainsKey(key))
            {
                Exception exception;
                CopyOnWriteArraySet <IConnection> set = this._clients[key];
                set.Remove(connection);
                IScopeHandler handler = null;
                if (this.HasHandler)
                {
                    handler = this.Handler;
                    try
                    {
                        handler.Disconnect(connection, this);
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        if ((log != null) && log.get_IsErrorEnabled())
                        {
                            log.Error(string.Concat(new object[] { "Error while executing \"disconnect\" for connection ", connection, " on handler ", handler }), exception);
                        }
                    }
                }
                if (set.Count == 0)
                {
                    this._clients.Remove(key);
                    if (handler != null)
                    {
                        try
                        {
                            handler.Leave(key, this);
                        }
                        catch (Exception exception2)
                        {
                            exception = exception2;
                            if ((log != null) && log.get_IsErrorEnabled())
                            {
                                log.Error(string.Concat(new object[] { "Error while executing \"leave\" for client ", key, " on handler ", handler }), exception);
                            }
                        }
                    }
                }
                this.RemoveEventListener(connection);
            }
            if (base.HasParent)
            {
                this.Parent.Disconnect(connection);
            }
        }
 public void TestConstructor3()
 {
     Object[] ints = new Object[SIZE];
     for (int i = 0; i < SIZE-1; ++i)
     {
         ints[i] = i;
     }
     CopyOnWriteArraySet<Object> a = new CopyOnWriteArraySet<Object>(Arrays.AsList(ints));
     for (int i = 0; i < SIZE; ++i)
     {
         Assert.IsTrue(a.Contains(ints[i]));
     }
 }
        static CopyOnWriteArraySet<Object> PopulatedSet(int n)
        {
            CopyOnWriteArraySet<Object> a = new CopyOnWriteArraySet<Object>();
            Assert.IsTrue(a.IsEmpty());

            for (int i = 0; i < n; ++i)
            {
                a.Add(i);
            }

            Assert.IsFalse(a.IsEmpty());
            Assert.AreEqual(n, a.Size());
            return a;
        }
Example #10
0
        public void Disconnect(IConnection connection)
        {
            // We call the disconnect handlers in reverse order they were called
            // during connection, i.e. roomDisconnect is called before
            // appDisconnect.
            IClient client = connection.Client;

            if (_clients.ContainsKey(client))
            {
                CopyOnWriteArraySet <IConnection> connections = _clients[client];
                connections.Remove(connection);
                IScopeHandler handler = null;
                if (HasHandler)
                {
                    handler = this.Handler;
                    try
                    {
                        handler.Disconnect(connection, this);
                    }
                    catch (Exception)
                    {
                    }
                }

                if (connections.Count == 0)
                {
                    _clients.Remove(client);
                    if (handler != null)
                    {
                        try
                        {
                            // there may be a timeout here ?
                            handler.Leave(client, this);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                RemoveEventListener(connection);
            }
            if (HasParent)
            {
                this.Parent.Disconnect(connection);
            }
        }
Example #11
0
        /// <summary>
        ///     NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="object">to cast</param>
        /// <param name="typeToCastTo">target</param>
        /// <param name="pairs">cache</param>
        /// <returns>null or object</returns>
        public static object SimpleTypeCasterCast(
            object @object,
            Type typeToCastTo,
            CopyOnWriteArraySet<Pair<Type, bool>> pairs)
        {
            if (@object.GetType() == typeToCastTo) {
                return @object;
            }

            // check cache to see if this is cast-able
            foreach (var pair in pairs) {
                if (pair.First == typeToCastTo) {
                    if (!pair.Second) {
                        return null;
                    }

                    return @object;
                }
            }

            // Not found in cache, add to cache;
            lock (pairs) {
                // search cache once more
                foreach (var pair in pairs) {
                    if (pair.First == typeToCastTo) {
                        if (!pair.Second) {
                            return null;
                        }

                        return @object;
                    }
                }

                // Determine if any of the super-types and interfaces that the object implements or extends
                // is the same as any of the target types
                var passed = TypeHelper.IsSubclassOrImplementsInterface(@object.GetType(), typeToCastTo);

                if (passed) {
                    pairs.Add(new Pair<Type, bool>(@object.GetType(), true));
                    return @object;
                }

                pairs.Add(new Pair<Type, bool>(@object.GetType(), false));
                return null;
            }
        }
Example #12
0
        /// <summary>
        /// Adds given connection to the scope.
        /// </summary>
        /// <param name="connection">Connection object.</param>
        /// <param name="parameters">Parameters passed.</param>
        /// <returns>
        /// true on success, false if the specified connection already belongs to this scope.
        /// </returns>
        public bool Connect(IConnection connection, object[] parameters)
        {
            if (HasParent && !Parent.Connect(connection, parameters))
            {
                return(false);
            }
            if (HasHandler && !Handler.Connect(connection, this, parameters))
            {
                return(false);
            }
            IClient client = connection.Client;

            if (!connection.IsConnected)
            {
                // Timeout while connecting client
                return(false);
            }
            //We would not get this far if there is no handler
            if (HasHandler && !Handler.Join(client, this))
            {
                return(false);
            }
            if (!connection.IsConnected)
            {
                // Timeout while connecting client
                return(false);
            }

            CopyOnWriteArraySet <IConnection> connections;

            if (_clients.ContainsKey(client))
            {
                connections = _clients[client];
            }
            else
            {
                connections      = new CopyOnWriteArraySet <IConnection>();
                _clients[client] = connections;
            }
            connections.Add(connection);
            _clientStats.Increment();
            AddEventListener(connection);
            _connectionStats.Increment();
            return(true);
        }
Example #13
0
        /// <summary>
        ///     Constructor - initializes services.
        /// </summary>
        /// <param name="configuration">is the runtime configuration</param>
        /// <param name="runtimeURI">
        ///     is the runtime URI or "default" (or null which it assumes as "default") if this is the default
        ///     provider
        /// </param>
        /// <param name="runtimes">map of URI and runtime</param>
        /// <throws>ConfigurationException is thrown to indicate a configuraton error</throws>
        public EPRuntimeImpl(
            Configuration configuration,
            string runtimeURI,
            IDictionary<string, EPRuntimeSPI> runtimes)
        {
            if (configuration == null) {
                throw new ArgumentNullException(nameof(configuration), "Unexpected null value received for configuration");
            }

            this.Container = configuration.Container;
            this._runtimes = runtimes;
            URI = runtimeURI ?? throw new ArgumentNullException(nameof(runtimeURI), "runtime URI should not be null at this stage");

            _serviceListeners = new CopyOnWriteArraySet<EPRuntimeStateListener>();

            _configLastProvided = TakeSnapshot(configuration);

            DoInitialize(null);
        }
Example #14
0
        /// <summary>Ctor. </summary>
        /// <param name="specification">configuration</param>
        /// <param name="engineUri">engine URI</param>
        public MetricReportingServiceImpl(ConfigurationMetricsReporting specification, String engineUri)
        {
            _specification = specification;
            _engineUri     = engineUri;
            _schedule      = new MetricScheduleService();

            _stmtMetricRepository     = new StatementMetricRepository(engineUri, specification);
            _statementGroupExecutions = new LinkedHashMap <String, MetricExecStatement>();
            _statementMetricHandles   = new Dictionary <String, StatementMetricHandle>();
            StatementOutputHooks      = new CopyOnWriteArraySet <StatementResultListener>();

            if (specification.IsThreading)
            {
                _metricsExecutor = new MetricsExecutorThreaded(engineUri);
            }
            else
            {
                _metricsExecutor = new MetricsExecutorUnthreaded();
            }
        }
Example #15
0
        /// <param name="logs"> A list of <seealso cref="Log"/> instances that messages should be duplicated to </param>
        public DuplicatingLog(IList <Log> logs)
        {
            List <Logger> debugLoggers = new List <Logger>(logs.Count);
            List <Logger> infoLoggers  = new List <Logger>(logs.Count);
            List <Logger> warnLoggers  = new List <Logger>(logs.Count);
            List <Logger> errorLoggers = new List <Logger>(logs.Count);

            foreach (Log log in logs)
            {
                debugLoggers.Add(log.DebugLogger());
                infoLoggers.Add(log.InfoLogger());
                warnLoggers.Add(log.WarnLogger());
                errorLoggers.Add(log.ErrorLogger());
            }

            this._logs        = new CopyOnWriteArraySet <Log>(logs);
            this._debugLogger = new DuplicatingLogger(debugLoggers);
            this._infoLogger  = new DuplicatingLogger(infoLoggers);
            this._warnLogger  = new DuplicatingLogger(warnLoggers);
            this._errorLogger = new DuplicatingLogger(errorLoggers);
        }
Example #16
0
        public bool Connect(IConnection connection, object[] parameters)
        {
            if (!(!base.HasParent || this.Parent.Connect(connection, parameters)))
            {
                return(false);
            }
            if (!(!this.HasHandler || this.Handler.Connect(connection, this, parameters)))
            {
                return(false);
            }
            IClient client = connection.Client;

            if (!connection.IsConnected)
            {
                return(false);
            }
            if (!(!this.HasHandler || this.Handler.Join(client, this)))
            {
                return(false);
            }
            if (!connection.IsConnected)
            {
                return(false);
            }
            CopyOnWriteArraySet <IConnection> set = null;

            if (this._clients.ContainsKey(client))
            {
                set = this._clients[client];
            }
            else
            {
                set = new CopyOnWriteArraySet <IConnection>();
                this._clients[client] = set;
            }
            set.Add(connection);
            this.AddEventListener(connection);
            return(true);
        }
Example #17
0
 internal DuplicatingLogger(IList <Logger> loggers)
 {
     this.Loggers = new CopyOnWriteArraySet <Logger>(loggers);
 }
Example #18
0
        /// <summary>
        /// Disconnects the specified connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        public void Disconnect(IConnection connection)
        {
            // We call the disconnect handlers in reverse order they were called during connection, i.e. roomDisconnect is called before appDisconnect.
            IClient client = connection.Client;

            if (client == null)
            {
                // Early bail out
                RemoveEventListener(connection);
                _connectionStats.Decrement();
                if (HasParent)
                {
                    Parent.Disconnect(connection);
                }
                return;
            }

            if (_clients.ContainsKey(client))
            {
                CopyOnWriteArraySet <IConnection> connections = _clients[client];
                connections.Remove(connection);
                IScopeHandler handler = null;
                if (HasHandler)
                {
                    handler = Handler;
                    try
                    {
                        handler.Disconnect(connection, this);
                    }
                    catch (Exception ex)
                    {
#if !SILVERLIGHT
                        if (log != null && log.IsErrorEnabled)
                        {
                            log.Error("Error while executing \"disconnect\" for connection " + connection + " on handler " + handler, ex);
                        }
#endif
                    }
                }

                if (connections.Count == 0)
                {
                    _clients.Remove(client);
                    _clientStats.Decrement();
                    if (handler != null)
                    {
                        try
                        {
                            // there may be a timeout here ?
                            handler.Leave(client, this);
                        }
                        catch (Exception ex)
                        {
#if !SILVERLIGHT
                            if (log != null && log.IsErrorEnabled)
                            {
                                log.Error("Error while executing \"leave\" for client " + client + " on handler " + handler, ex);
                            }
#endif
                        }
                    }
                }
                RemoveEventListener(connection);
                _connectionStats.Decrement();
            }
            if (HasParent)
            {
                Parent.Disconnect(connection);
            }
        }
Example #19
0
 /// <summary>Ctor.</summary>
 public EPStatementListenerSet()
 {
     Events = new CopyOnWriteArraySet <UpdateEventHandler>();
 }
Example #20
0
 /// <summary>Copy the update listener set to from another.</summary>
 /// <param name="listenerSet">a collection of Update listeners</param>
 public void Copy(EPStatementListenerSet listenerSet)
 {
     Events = listenerSet.Events;
 }
Example #21
0
 /// <param name="logProviders"> A list of <seealso cref="LogProvider"/> instances that messages should be duplicated to </param>
 public DuplicatingLogProvider(params LogProvider[] logProviders)
 {
     this._logProviders = new CopyOnWriteArraySet <LogProvider>(Arrays.asList(logProviders));
 }
 public void TestIsEmpty()
 {
     CopyOnWriteArraySet<Object> empty = new CopyOnWriteArraySet<Object>();
     CopyOnWriteArraySet<Object> full = PopulatedSet(3);
     Assert.IsTrue(empty.IsEmpty());
     Assert.IsFalse(full.IsEmpty());
 }
 public void TestSize()
 {
     CopyOnWriteArraySet<Object> empty = new CopyOnWriteArraySet<Object>();
     CopyOnWriteArraySet<Object> full = PopulatedSet(3);
     Assert.AreEqual(3, full.Size());
     Assert.AreEqual(0, empty.Size());
 }
 public void TestConstructor()
 {
     CopyOnWriteArraySet<Object> a = new CopyOnWriteArraySet<Object>();
     Assert.IsTrue(a.IsEmpty());
 }