internal static string SerializeProtocols(ICommunicationSchema schema)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append("[" + String.Join(",", schema.SynReqProtocolDescriptors.Select(_ => SerializeProtocol(_))) + "]");
            sb.Append("[" + String.Join(",", schema.SynReqRspProtocolDescriptors.Select(_ => SerializeProtocol(_))) + "]");
            sb.Append("[" + String.Join(",", schema.AsynReqProtocolDescriptors.Select(_ => SerializeProtocol(_))) + "]");
            sb.Append("}");
            return(sb.ToString());
        }
Beispiel #2
0
        private void _InitializeModules()
        {
            HashSet <Type> cur_types = new HashSet <Type>();
            HashSet <Type> add_types = new HashSet <Type>(GetRegisteredCommunicationModuleTypes());

            Type[]   ctor_ptypes = new Type[] { };
            object[] ctor_params = new object[] { };

            ICommunicationSchema schema = this.GetCommunicationSchema();

            this.SynReqIdOffset     = (ushort)schema.SynReqProtocolDescriptors.Count();
            this.SynReqRspIdOffset  = (ushort)schema.SynReqRspProtocolDescriptors.Count();
            this.AsynReqIdOffset    = (ushort)schema.AsynReqProtocolDescriptors.Count();
            this.AsynReqRspIdOffset = (ushort)schema.AsynReqRspProtocolDescriptors.Count();

            /* TODO check circular dependency */

            while (add_types.Count != 0)
            {
                var added_modules = add_types
                                    .Select(type => type.GetConstructor(ctor_ptypes).Invoke(ctor_params) as CommunicationModule)
                                    .ToList();

                foreach (var t in add_types)
                {
                    cur_types.Add(t);
                }

                add_types.Clear();

                foreach (var m in added_modules)
                {
                    /* Register and initialize the module */

                    m_CommunicationModules[m.GetModuleName()] = m;
                    m.Initialize(this);

                    foreach (var t in m.GetRegisteredCommunicationModuleTypes())
                    {
                        if (!cur_types.Contains(t))
                        {
                            add_types.Add(t);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private unsafe void ServerInitialize(CommunicationInstance instance)
        {
            m_memorycloud = Global.CloudStorage;
            ICommunicationSchema schema = this.GetCommunicationSchema();

            this.SynReqIdOffset     = instance.SynReqIdOffset;
            this.SynReqRspIdOffset  = instance.SynReqRspIdOffset;
            this.AsynReqIdOffset    = instance.AsynReqIdOffset;
            this.AsynReqRspIdOffset = instance.AsynReqRspIdOffset;

            checked
            {
                instance.SynReqIdOffset     += (ushort)schema.SynReqProtocolDescriptors.Count();
                instance.SynReqRspIdOffset  += (ushort)schema.SynReqRspProtocolDescriptors.Count();
                instance.AsynReqIdOffset    += (ushort)schema.AsynReqProtocolDescriptors.Count();
                instance.AsynReqRspIdOffset += (ushort)schema.AsynReqRspProtocolDescriptors.Count();
                // each ASYNC_WITH_RSP message comes with a response handler.
                instance.AsynReqIdOffset += (ushort)schema.AsynReqRspProtocolDescriptors.Count();
            }
        }
        /// <summary>
        /// It is guaranteed that CloudStorage can be accessed (native server started)
        /// before an instance calls module Initialize() method.
        /// </summary>
        internal unsafe void Initialize(CommunicationInstance instance)
        {
            //Debug.Assert(TrinityConfig.CurrentRunningMode != RunningMode.Client);
            //Debug.Assert(TrinityConfig.CurrentRunningMode != RunningMode.Embedded);
            //Debug.Assert(TrinityConfig.CurrentRunningMode != RunningMode.Undefined);

            ICommunicationSchema schema = this.GetCommunicationSchema();

            m_memoryCloud = instance.CloudStorage;

            this.SynReqIdOffset    = instance.SynReqIdOffset;
            this.SynReqRspIdOffset = instance.SynReqRspIdOffset;
            this.AsynReqIdOffset   = instance.AsynReqIdOffset;

            checked
            {
                instance.SynReqIdOffset    += (ushort)schema.SynReqProtocolDescriptors.Count();
                instance.SynReqRspIdOffset += (ushort)schema.SynReqRspProtocolDescriptors.Count();
                instance.AsynReqIdOffset   += (ushort)schema.AsynReqProtocolDescriptors.Count();
            }

            this.RegisterMessageHandler();
            SetupMessagePassingInterfaces(instance.RunningMode);
        }