private void OnClientMessage(Message msg)
        {
            Log.Debug("Received " + msg);
            try
            {
                NetContractDescription contractDesc = Node.Dispatcher.GetContractForMessage(msg.Id);

                var actorHeader = msg.GetHeader <ActorHeader>();
                if (actorHeader != null)
                {
                    Node.DispatchOperationToActor(actorHeader.ActorLocalId, msg, this, true);
                }
                else //by default operations are handled by client associated peer
                {
                    NetContractHandler handler;
                    if (_handlersByNetContractId.TryGetValue(contractDesc.TypeId, out handler))
                    {
                        LockType lockType = handler.GetLockTypeForOperation(msg);
                        Log.Debug("Dispatching {0} to client peer", msg);
                        if (lockType == LockType.None)
#pragma warning disable 4014
                        {
                            //for this lock level we really don't wait for any results
                            DispatchAndReplyAsync(handler.Implementer, msg);
                        }
#pragma warning restore 4014
                        else
                        {
                            Fiber.ProcessAsync(() => DispatchAndReplyAsync(handler.Implementer, msg), lockType);
                        }
                    }
                    else
                    {
                        Log.Debug("Skipping {0} because no handler is present", msg);
                        MessageFactory.Free(msg);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageFactory.Free(msg);
                Log.Error("Channel will be closed after: " + ex);
                Channel.Close();
            }
        }
 private void OnServerMessage(Message msg)
 {
     Log.Debug("Received " + msg);
     try
     {
         var actorHeader = msg.GetHeader <ActorHeader>();
         if (actorHeader != null)
         {
             Log.Debug("Dispatching {0} to service", msg);
             Node.DispatchOperationToActor(actorHeader.ActorLocalId, msg, this, false);
         }
         else
         {
             Log.Warn("Received {0} without actor header, skip it", msg);
             MessageFactory.Free(msg);
         }
     }
     catch (Exception ex)
     {
         MessageFactory.Free(msg);
         Log.Error("Channel will be closed after: " + ex);
         Channel.Close();
     }
 }