/// <summary> /// It is guaranteed that this method does not throw exceptions. /// When no event handlers subscribes to UnhandledException of the current running communication instance (if there is one), /// then the default exception logging routine will be called. /// </summary> internal static unsafe void _RaiseUnhandledExceptionEvents(object reqArgs, MessagingUnhandledExceptionEventArgs e) { try { CommunicationInstance comm_instance = Global.CommunicationInstance; MessagingUnhandledExceptionEventHandler exception_event_handler = null; if (comm_instance != null) { exception_event_handler = comm_instance.UnhandledException; } if (exception_event_handler != null) { exception_event_handler(reqArgs, e); } else { _LogMessageReqArgsAndException(reqArgs, e); } } catch (Exception exception) { //The unhandled exception event handler throws exception. //We first log the original exception down, and then explain //how the exception handler failed. _LogMessageReqArgsAndException(reqArgs, e); Log.WriteLine(LogLevel.Error, "Exceptions are caught in the UnhandledException event handler."); Log.WriteLine(LogLevel.Error, exception.Message); Log.WriteLine(LogLevel.Error, exception.StackTrace); } }
/// <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) { if (instance.RunningMode == RunningMode.Client) { ClientInitialize(RunningMode.Server); } else { ServerInitialize(instance); } RegisterMessageHandler(); }
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); }