Пример #1
0
            public Yield Ping(DreamContext context, DreamMessage request, Result <DreamMessage> response)
            {
                var guid = Guid.NewGuid();

                ContextVar = new ContextLifeSpan(guid);
                context.SetState(ContextVar);
                response.Return(DreamMessage.Ok());
                yield break;
            }
Пример #2
0
            public Yield Exception(DreamContext context, DreamMessage request, Result <DreamMessage> response)
            {
                _log.Debug("in exception feature");
                var guid = Guid.NewGuid();

                ContextVar = new ContextLifeSpan(guid);
                context.SetState(ContextVar);
                throw new CustomException();
            }
Пример #3
0
            public Yield Spawn(DreamContext context, DreamMessage request, Result <DreamMessage> response)
            {
                var guid = Guid.NewGuid();

                ContextVar = new ContextLifeSpan(guid);
                context.SetState(guid);
                context.SetState(ContextVar);
                ContextLifeSpan capturedInner = null;

                yield return(Async.Fork(() =>
                {
                    var innerContextVar = DreamContext.Current.GetState <ContextLifeSpan>();
                    capturedInner = innerContextVar;
                    if (innerContextVar == ContextVar)
                    {
                        throw new Exception("spawned context instances were same");
                    }
                    if (innerContextVar.Guid != guid)
                    {
                        throw new Exception("spawned context guid is wrong");
                    }
                    if (innerContextVar.IsDisposed)
                    {
                        throw new Exception("subcall: context is disposed");
                    }
                }, new Result()));

                var contextVar = context.GetState <ContextLifeSpan>();

                if (contextVar == null)
                {
                    throw new Exception("context instance is gone");
                }
                if (capturedInner == contextVar)
                {
                    throw new Exception("outer instance was changed to inner");
                }
                if (!capturedInner.IsDisposed)
                {
                    throw new Exception("inner instance wasn't disposed after closure completion");
                }
                if (contextVar.Guid != guid)
                {
                    throw new Exception("context guid is wrong");
                }
                if (contextVar != ContextVar)
                {
                    throw new Exception("context instance changed");
                }
                if (contextVar.IsDisposed)
                {
                    throw new Exception("context is disposed");
                }
                response.Return(DreamMessage.Ok());
                yield break;
            }
Пример #4
0
            public Yield CallPlug(DreamContext context, DreamMessage request, Result <DreamMessage> response)
            {
                _log.Debug("callplug start");
                var guid = Guid.NewGuid();

                ContextVar = new ContextLifeSpan(guid);
                context.SetState(guid);
                _log.Debug("setting disposable state");
                context.SetState(ContextVar);
                Result <DreamMessage> sub;

                _log.Debug("calling plug");
                yield return(sub = Self.At("calledplug").GetAsync());

                _log.Debug("return from plug");
                if (!sub.Value.IsSuccessful)
                {
                    response.Return(sub.Value);
                }
                var contextVar = context.GetState <ContextLifeSpan>();

                if (contextVar == null)
                {
                    throw new Exception("context instance is gone");
                }
                if (contextVar.Guid != guid)
                {
                    throw new Exception("context guid is wrong");
                }
                if (contextVar != ContextVar)
                {
                    throw new Exception("context instance changed");
                }
                if (contextVar.IsDisposed)
                {
                    throw new Exception("context is disposed");
                }
                _log.Debug("callplug return");
                response.Return(DreamMessage.Ok());
                _log.Debug("callplug end");
                yield break;
            }
Пример #5
0
            public Yield CallCoroutine(DreamContext context, DreamMessage request, Result <DreamMessage> response)
            {
                _log.Debug("callcoroutine start");
                var guid = Guid.NewGuid();

                ContextVar = new ContextLifeSpan(guid);
                context.SetState(guid);
                context.SetState(ContextVar);
                if (context.GetState <ContextLifeSpan>() == null)
                {
                    throw new Exception("context instance was never set");
                }
                _log.DebugFormat("callcoroutine calling coroutine within Env #{0}", TaskEnv.Current.GetHashCode());
                yield return(Coroutine.Invoke(SubCall, new Result()));

                var contextVar = context.GetState <ContextLifeSpan>();

                _log.DebugFormat("callcoroutine coroutine returned within Env #{0}", TaskEnv.Current.GetHashCode());
                if (contextVar == null)
                {
                    throw new Exception("context instance is gone");
                }
                if (contextVar.Guid != guid)
                {
                    throw new Exception("context guid is wrong");
                }
                if (contextVar != ContextVar)
                {
                    throw new Exception("context instance changed");
                }
                if (contextVar.IsDisposed)
                {
                    throw new Exception("context is disposed");
                }
                response.Return(DreamMessage.Ok());
                yield break;
            }
Пример #6
0
 public Yield Spawn(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     var guid = Guid.NewGuid();
     ContextVar = new ContextLifeSpan(guid);
     context.SetState(guid);
     context.SetState(ContextVar);
     ContextLifeSpan capturedInner = null;
     yield return Async.Fork(() =>
     {
         var innerContextVar = DreamContext.Current.GetState<ContextLifeSpan>();
         capturedInner = innerContextVar;
         if(innerContextVar == ContextVar) {
             throw new Exception("spawned context instances were same");
         }
         if(innerContextVar.Guid != guid) {
             throw new Exception("spawned context guid is wrong");
         }
         if(innerContextVar.IsDisposed) {
             throw new Exception("subcall: context is disposed");
         }
     }, new Result());
     var contextVar = context.GetState<ContextLifeSpan>();
     if(contextVar == null) {
         throw new Exception("context instance is gone");
     }
     if(capturedInner == contextVar) {
         throw new Exception("outer instance was changed to inner");
     }
     if(!capturedInner.IsDisposed) {
         throw new Exception("inner instance wasn't disposed after closure completion");
     }
     if(contextVar.Guid != guid) {
         throw new Exception("context guid is wrong");
     }
     if(contextVar != ContextVar) {
         throw new Exception("context instance changed");
     }
     if(contextVar.IsDisposed) {
         throw new Exception("context is disposed");
     }
     response.Return(DreamMessage.Ok());
     yield break;
 }
Пример #7
0
 public Yield Ping(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     var guid = Guid.NewGuid();
     ContextVar = new ContextLifeSpan(guid);
     context.SetState(ContextVar);
     response.Return(DreamMessage.Ok());
     yield break;
 }
Пример #8
0
 public Yield Exception(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     _log.Debug("in exception feature");
     var guid = Guid.NewGuid();
     ContextVar = new ContextLifeSpan(guid);
     context.SetState(ContextVar);
     throw new CustomException();
 }
Пример #9
0
 public Yield CallPlug(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     _log.Debug("callplug start");
     var guid = Guid.NewGuid();
     ContextVar = new ContextLifeSpan(guid);
     context.SetState(guid);
     _log.Debug("setting disposable state");
     context.SetState(ContextVar);
     Result<DreamMessage> sub;
     _log.Debug("calling plug");
     yield return sub = Self.At("calledplug").GetAsync();
     _log.Debug("return from plug");
     if(!sub.Value.IsSuccessful) {
         response.Return(sub.Value);
     }
     var contextVar = context.GetState<ContextLifeSpan>();
     if(contextVar == null) {
         throw new Exception("context instance is gone");
     }
     if(contextVar.Guid != guid) {
         throw new Exception("context guid is wrong");
     }
     if(contextVar != ContextVar) {
         throw new Exception("context instance changed");
     }
     if(contextVar.IsDisposed) {
         throw new Exception("context is disposed");
     }
     _log.Debug("callplug return");
     response.Return(DreamMessage.Ok());
     _log.Debug("callplug end");
     yield break;
 }
Пример #10
0
 public Yield CallCoroutine(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     _log.Debug("callcoroutine start");
     var guid = Guid.NewGuid();
     ContextVar = new ContextLifeSpan(guid);
     context.SetState(guid);
     context.SetState(ContextVar);
     if(context.GetState<ContextLifeSpan>() == null) {
         throw new Exception("context instance was never set");
     }
     _log.DebugFormat("callcoroutine calling coroutine within Env #{0}", TaskEnv.Current.GetHashCode());
     yield return Coroutine.Invoke(SubCall, new Result());
     var contextVar = context.GetState<ContextLifeSpan>();
     _log.DebugFormat("callcoroutine coroutine returned within Env #{0}", TaskEnv.Current.GetHashCode());
     if(contextVar == null) {
         throw new Exception("context instance is gone");
     }
     if(contextVar.Guid != guid) {
         throw new Exception("context guid is wrong");
     }
     if(contextVar != ContextVar) {
         throw new Exception("context instance changed");
     }
     if(contextVar.IsDisposed) {
         throw new Exception("context is disposed");
     }
     response.Return(DreamMessage.Ok());
     yield break;
 }