示例#1
0
        public void MigrateActor(global::System.UInt64 actorId, global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.Byte[]> callback)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = OpCode.MIGRATE_ACTOR_REQ;
                if (protoCode < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = Global.NetManager.GetPeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { actorId, callback, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { actorId, callback });
                }
                return;
            }
            Task.Run(() => {
                var msg = new MigrateActorReq()
                {
                    actorId = actorId
                };
                var cb = new Action <byte[]>((cbData) => {
                    var cbMsg = cbData == null?new MigrateActorReq.Callback():RpcUtil.Deserialize <MigrateActorReq.Callback>(cbData);
                    callback?.Invoke(cbMsg.code, cbMsg.arg1);
                });
                this.CallRemoteMethod(OpCode.MIGRATE_ACTOR_REQ, msg, cb);
            });
        }
示例#2
0
        public void MigrateActor(UInt64 actorId)
        {
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                var protoCode = OpCode.MIGRATE_ACTOR_REQ;
                if (protoCode < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = Global.NetManager.GetPeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { actorId, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { actorId });
                }
                return;
            }
            var msg = new MigrateActorReq()
            {
                actorId = actorId
            };

            this.CallRemoteMethod(OpCode.MIGRATE_ACTOR_REQ, msg, null);
        }
示例#3
0
        public async Task <MigrateActorReq.Callback> MigrateActorAsync(global::System.UInt64 actorId, global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.Byte[]> callback = null)
        {
            var t        = new TaskCompletionSource <MigrateActorReq.Callback>();
            var toHostId = Global.IdManager.GetHostIdByActorId(this.toActorId, this.isClient);

            if (this.FromHostId == toHostId)
            {
                global::System.Action <global::Fenix.Common.DefaultErrCode, global::System.Byte[]> _cb = (code, arg1) =>
                {
                    var cbMsg = new MigrateActorReq.Callback();
                    cbMsg.code = code;
                    cbMsg.arg1 = arg1;
                    callback?.Invoke(cbMsg.code, cbMsg.arg1);
                    t.TrySetResult(cbMsg);
                };
                var protoCode = OpCode.MIGRATE_ACTOR_REQ;
                if (protoCode < OpCode.CALL_ACTOR_METHOD)
                {
                    var peer    = Global.NetManager.GetPeerById(this.FromHostId, this.NetType);
                    var context = new RpcContext(null, peer);
                    Global.Host.CallMethodWithParams(protoCode, new object[] { actorId, _cb, context });
                }
                else
                {
                    Global.Host.GetActor(this.toActorId).CallMethodWithParams(protoCode, new object[] { actorId, _cb });
                }
            }
            else
            {
                Action <MigrateActorReq.Callback> _cb = (cbMsg) =>
                {
                    callback?.Invoke(cbMsg.code, cbMsg.arg1);
                    t.TrySetResult(cbMsg);
                };
                await Task.Run(() => {
                    var msg = new MigrateActorReq()
                    {
                        actorId = actorId
                    };
                    var cb = new Action <byte[]>((cbData) => {
                        var cbMsg = cbData == null ? new MigrateActorReq.Callback() : RpcUtil.Deserialize <MigrateActorReq.Callback>(cbData);
                        _cb?.Invoke(cbMsg);
                    });
                    this.CallRemoteMethod(OpCode.MIGRATE_ACTOR_REQ, msg, cb);
                });
            }
            return(await t.Task);
        }