Exemple #1
0
            public serverImplementer(ServerHandler handler, ServerEndPoint sep, Type contract)
            {
                Handler        = handler;
                ServerEndPoint = sep;
                Contract       = contract;

                var implementers = sep.ContractServers.Where(ts => contract.IsAssignableFrom(ts)).ToArray();

                if (implementers.Length == 0)
                {
                    throw new ServerContractException(string.Format(StringConsts.GLUE_ENDPOINT_CONTRACT_NOT_IMPLEMENTED_ERROR, sep.Name, contract.FullName));
                }

                if (implementers.Length > 1)
                {
                    handler.WriteLog(LogSrc.Server,
                                     MessageType.Warning,
                                     string.Format(StringConsts.GLUE_ENDPOINT_CONTRACT_MANY_SERVERS_WARNING, contract.FullName, sep.Name),
                                     from: "serverImplementer");
                }

                Implementation = implementers[0];

                //pre-alloc Contract/Implementation method infos
                var intfMapping = Implementation.GetInterfaceMap(Contract);

                foreach (var miContract in Contract.GetMethods())
                {
                    var mspec  = new MethodSpec(miContract);
                    var miImpl = intfMapping.TargetMethods.FirstOrDefault(tmi => new MethodSpec(tmi).Equals(mspec));
                    if (miImpl == null)
                    {
                        throw new ServerContractException(StringConsts.GLUE_ENDPOINT_CONTRACT_INTF_MAPPING_ERROR.Args(sep.Name,
                                                                                                                      contract.FullName,
                                                                                                                      miContract.Name,
                                                                                                                      Implementation.FullName));
                    }
                    var fBody = getFBody(miContract);
                    methodMap.Add(mspec, new mapping(miContract, miImpl, fBody));//todo DODELAT Functor!
                }

                var lifeCycle = Contract.GetCustomAttributes(typeof(LifeCycleAttribute), false).FirstOrDefault() as LifeCycleAttribute;

                if (lifeCycle != null)
                {
                    InstanceMode      = lifeCycle.Mode;
                    InstanceTimeoutMs = lifeCycle.TimeoutMs;
                }

                if (InstanceTimeoutMs == 0)
                {
                    InstanceTimeoutMs = DEFAULT_INSTANCE_TIMEOUT_MS;
                }

                ThreadSafe = Attribute.IsDefined(Implementation, typeof(ThreadSafeAttribute), false);

                AuthenticationSupport = Attribute.IsDefined(Contract, typeof(AuthenticationSupportAttribute), false);

                SupportsGlueCtor = Implementation.GetConstructor(ServerHandler.GLUE_CTOR_SIGNATURE) != null;
            }
Exemple #2
0
        protected override void DoWaitForCompleteStop()
        {
            const string FROM = "GlueService.DoWaitForCompleteStop()";
            const string STOP = "stopping";

            base.DoWaitForCompleteStop();

            try
            {
                m_Thread.Join();
                m_Thread = null;

                foreach (var s in m_Servers)
                {
                    run(() => s.Close(), STOP, "server", s.Name, s.GetType(), false);
                }
                foreach (var b in m_Bindings)
                {
                    run(() => b.WaitForCompleteStop(), STOP, "binding", b.Name, b.GetType(), false);
                }
                foreach (var p in m_Providers)
                {
                    run(() => p.WaitForCompleteStop(), STOP, "provider", p.Name, p.GetType(), false);
                }

                run(() => m_ServerHandler.WaitForCompleteStop(), STOP, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType(), false);

                m_ServerHandler.Dispose();
                m_ServerHandler = null;

                m_Calls = null;
            }
            catch (Exception error)
            {
                if (m_ServerHandler != null)
                {
                    try
                    {
                        m_ServerHandler.Dispose();
                        m_ServerHandler = null;
                    }
                    catch
                    {
                    }
                }

                log(MessageType.CatastrophicError, "Exception: " + error.ToMessageWithType(), FROM);
                throw error;
            }
        }
Exemple #3
0
        protected override void DoStart()
        {
            const string START = "starting";
            const string STOP  = "stopping";

            base.DoStart();

            try
            {
                m_ServerHandler = new ServerHandler(this);

                m_Calls          = new Calls(0);
                m_CallsWithTasks = new CallsWithTasks();

                run(() => m_ServerHandler.Start(), START, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType());

                foreach (var p in m_Providers)
                {
                    run(() => p.Start(), START, "provider", p.Name, p.GetType());
                }
                foreach (var b in m_Bindings)
                {
                    run(() => b.Start(), START, "binding", b.Name, b.GetType());
                }
                foreach (var s in m_Servers)
                {
                    run(() => s.Open(), START, "server", s.Name, s.GetType());
                }

                m_Waiter      = new AutoResetEvent(false);
                m_Thread      = new Thread(threadSpin);
                m_Thread.Name = THREAD_NAME;
                m_Thread.Start();

                WriteLog(MessageType.Trace, nameof(DoStart), "Started OK");
            }
            catch (Exception error)
            {
                AbortStart();

                WriteLog(MessageType.CatastrophicError, nameof(DoStart), "Leaked: " + error.ToMessageWithType(), error);

                if (m_Thread != null)
                {
                    m_Thread.Join();
                    m_Thread = null;
                }

                foreach (var s in m_Servers)
                {
                    run(() => s.Close(), STOP, "server", s.Name, s.GetType(), false);
                }
                foreach (var b in m_Bindings)
                {
                    run(() => b.WaitForCompleteStop(), STOP, "binding", b.Name, b.GetType(), false);
                }
                foreach (var p in m_Providers)
                {
                    run(() => p.WaitForCompleteStop(), STOP, "provider", p.Name, p.GetType(), false);
                }

                if (m_ServerHandler != null)
                {
                    run(() => m_ServerHandler.Dispose(), STOP, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType(), false);
                    m_ServerHandler = null;
                }

                throw error;
            }
        }
Exemple #4
0
        protected override void DoStart()
        {
            const string FROM  = "GlueService.DoStart()";
            const string START = "starting";
            const string STOP  = "stopping";

            base.DoStart();

            try
            {
                m_ServerHandler = new ServerHandler(this);

                m_Calls = new Calls(0);

                run(() => m_ServerHandler.Start(), START, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType());

                //todo  Add partial failure handling, i.e. what if 2nd binding fails? then Providers that have started already need to stop
                foreach (var p in m_Providers)
                {
                    run(() => p.Start(), START, "provider", p.Name, p.GetType());
                }
                foreach (var b in m_Bindings)
                {
                    run(() => b.Start(), START, "binding", b.Name, b.GetType());
                }
                foreach (var s in m_Servers)
                {
                    run(() => s.Open(), START, "server", s.Name, s.GetType());
                }

                m_Thread      = new Thread(threadSpin);
                m_Thread.Name = THREAD_NAME;
                m_Thread.Start();

                log(MessageType.Info, "Started OK", FROM);
            }
            catch (Exception error)
            {
                AbortStart();

                log(MessageType.CatastrophicError, "Exception: " + error.ToMessageWithType(), FROM);

                if (m_Thread != null)
                {
                    m_Thread.Join();
                    m_Thread = null;
                }

                foreach (var s in m_Servers)
                {
                    run(() => s.Close(), STOP, "server", s.Name, s.GetType(), false);
                }
                foreach (var b in m_Bindings)
                {
                    run(() => b.WaitForCompleteStop(), STOP, "binding", b.Name, b.GetType(), false);
                }
                foreach (var p in m_Providers)
                {
                    run(() => p.WaitForCompleteStop(), STOP, "provider", p.Name, p.GetType(), false);
                }

                if (m_ServerHandler != null)
                {
                    run(() => m_ServerHandler.Dispose(), STOP, "server handler", m_ServerHandler.Name, m_ServerHandler.GetType(), false);
                    m_ServerHandler = null;
                }

                throw error;
            }
        }