internal override void SendMessage(byte *message, int size) { TrinityMessageType msgType = (TrinityMessageType)message[TrinityProtocol.MsgTypeOffset]; int msgId = message[TrinityProtocol.MsgIdOffset]; TrinityErrorCode msgProcessResult; switch (msgType) { case TrinityMessageType.PRESERVED_SYNC: SynReqArgs preserved_sync_args = new SynReqArgs(message, TrinityProtocol.MsgHeader, size - TrinityProtocol.MsgHeader, MessageHandlers.DefaultParser.preserved_sync_handlers[msgId]); msgProcessResult = preserved_sync_args.MessageProcess(); break; case TrinityMessageType.SYNC: SynReqArgs sync_args = new SynReqArgs(message, TrinityProtocol.MsgHeader, size - TrinityProtocol.MsgHeader, MessageHandlers.DefaultParser.sync_handlers[msgId]); msgProcessResult = sync_args.MessageProcess(); break; case TrinityMessageType.PRESERVED_ASYNC: { AsynReqArgs aut_request = new AsynReqArgs(message, TrinityProtocol.MsgHeader, size - TrinityProtocol.MsgHeader, MessageHandlers.DefaultParser.preserved_async_handlers[msgId]); msgProcessResult = aut_request.AsyncProcessMessage(); } break; case TrinityMessageType.ASYNC: { AsynReqArgs aut_request = new AsynReqArgs(message, TrinityProtocol.MsgHeader, size - TrinityProtocol.MsgHeader, MessageHandlers.DefaultParser.async_handlers[msgId]); msgProcessResult = aut_request.AsyncProcessMessage(); } break; default: throw new IOException("Wrong message type."); } if (msgProcessResult == TrinityErrorCode.E_RPC_EXCEPTION) { throw new IOException("Local message handler throws an exception."); } }
private unsafe void PostResponse_impl(SynReqArgs args) { /****************************** * Protocol: PostResponse * Request: |4B InstanceId|4B Cookie|8B p| TrinityResponse | * Response: VOID ******************************/ PointerHelper sp = PointerHelper.New(args.Buffer + args.Offset); int instanceId = *sp.ip++; int cookie = *sp.ip++; long p = *sp.lp++; var stg = CheckInstanceCookie(cookie, instanceId); stg.PostResponse_impl(p, sp.bp, args.Size - sizeof(int) * 2 - sizeof(long)); }
private unsafe void RedirectMessage_impl(SynReqArgs args) { /****************************** * Protocol: RedirectMessage * Request: |4B PartitionId| TrinityMessage | * Response: VOID * * Redirects the message to another instance. ******************************/ PointerHelper sp = PointerHelper.New(args.Buffer + args.Offset); int partitionId = *sp.ip++; TrinityMessage tm = new TrinityMessage(sp.bp, (*sp.ip) + TrinityProtocol.SocketMsgHeader); m_memorycloud[partitionId].SendMessage(tm); }
private unsafe void RedirectMessage_impl(SynReqArgs args) { /****************************** * Protocol: RedirectMessage * Request: |4B InstanceId| TrinityMessage | * Response: VOID * * Redirects the message to another instance. ******************************/ PointerHelper sp = PointerHelper.New(args.Buffer + args.Offset); int instanceId = *sp.ip++; TrinityMessage tm = new TrinityMessage(sp.bp, *sp.ip + sizeof(int)); m_memorycloud[instanceId].SendMessage(tm); }
internal static void P2PBarrierHandler(SynReqArgs args) { int taskId; taskId = *(int *)(args.Buffer + args.Offset); SpinLockInt32.GetLock(ref spin_lock); if (BSPCheckInCount.ContainsKey(taskId)) { BSPCheckInCount[taskId]++; } else { BSPCheckInCount[taskId] = 1; } SpinLockInt32.ReleaseLock(ref spin_lock); }
private unsafe void _PingHandler(SynReqArgs args) { PingHandler(); }
internal void *DispatchMessage(MessageBuff *sendRecvBuff) { byte *ByteArray = sendRecvBuff->Buffer; int Length = (int)sendRecvBuff->Length; TrinityMessageType msgType = *(TrinityMessageType *)(sendRecvBuff->Buffer + TrinityProtocol.TrinityMsgTypeOffset); ushort msgId = *(ushort *)(ByteArray + TrinityProtocol.TrinityMsgIdOffset); TrinityErrorCode msgProcessResult; try { switch (msgType) { case TrinityMessageType.SYNC_WITH_RSP: SynReqRspArgs sync_rsp_args = new SynReqRspArgs(ByteArray, TrinityProtocol.TrinityMsgHeader, Length - TrinityProtocol.TrinityMsgHeader, sync_rsp_handlers[msgId]); msgProcessResult = sync_rsp_args.MessageProcess(); _SetSendRecvBuff(msgProcessResult, sendRecvBuff, sync_rsp_args.Response); return(null); case TrinityMessageType.PRESERVED_SYNC_WITH_RSP: SynReqRspArgs preserved_sync_rsp_args = new SynReqRspArgs(ByteArray, TrinityProtocol.TrinityMsgHeader, Length - TrinityProtocol.TrinityMsgHeader, preserved_sync_rsp_handlers[msgId]); msgProcessResult = preserved_sync_rsp_args.MessageProcess(); _SetSendRecvBuff(msgProcessResult, sendRecvBuff, preserved_sync_rsp_args.Response); return(null); case TrinityMessageType.SYNC: SynReqArgs sync_args = new SynReqArgs(ByteArray, TrinityProtocol.TrinityMsgHeader, Length - TrinityProtocol.TrinityMsgHeader, sync_handlers[msgId]); msgProcessResult = sync_args.MessageProcess(); _SetSendRecvBuff(msgProcessResult, sendRecvBuff); return(null); case TrinityMessageType.PRESERVED_SYNC: SynReqArgs preserved_sync_args = new SynReqArgs(ByteArray, TrinityProtocol.TrinityMsgHeader, Length - TrinityProtocol.TrinityMsgHeader, preserved_sync_handlers[msgId]); msgProcessResult = preserved_sync_args.MessageProcess(); _SetSendRecvBuff(msgProcessResult, sendRecvBuff); return(null); case TrinityMessageType.ASYNC: AsynReqArgs async_args = new AsynReqArgs(ByteArray, TrinityProtocol.TrinityMsgHeader, Length - TrinityProtocol.TrinityMsgHeader, async_handlers[msgId]); msgProcessResult = async_args.AsyncProcessMessage(); _SetSendRecvBuff(msgProcessResult, sendRecvBuff); return(null); case TrinityMessageType.PRESERVED_ASYNC: AsynReqArgs preserved_async_args = new AsynReqArgs(ByteArray, TrinityProtocol.TrinityMsgHeader, Length - TrinityProtocol.TrinityMsgHeader, preserved_async_handlers[msgId]); msgProcessResult = preserved_async_args.AsyncProcessMessage(); _SetSendRecvBuff(msgProcessResult, sendRecvBuff); return(null); case TrinityMessageType.ASYNC_WITH_RSP: AsynReqRspArgs async_rsp_args = new AsynReqRspArgs(ByteArray, TrinityProtocol.TrinityMsgHeader, Length - TrinityProtocol.TrinityMsgHeader, async_rsp_handlers[msgId]); msgProcessResult = async_rsp_args.AsyncProcessMessage(); _SetSendRecvBuff(msgProcessResult, sendRecvBuff); return(null); default: throw new Exception("Not recognized message type."); } } catch (MessageTooLongException ex) { Log.WriteLine("Message Type: " + msgType); Log.WriteLine("Message SN: " + msgId); Log.WriteLine(ex.Message); Log.WriteLine(ex.StackTrace); _SetSendRecvBuff(TrinityErrorCode.E_MSG_OVERFLOW, sendRecvBuff); return(null); } catch (Exception ex) { Log.WriteLine("Message Type: " + msgType); Log.WriteLine("Message SN: " + msgId); Log.WriteLine(ex.Message); Log.WriteLine(ex.StackTrace); _SetSendRecvBuff(TrinityErrorCode.E_RPC_EXCEPTION, sendRecvBuff); return(null); } }
void _t_protocol_name_4Handler(SynReqArgs args) { }