Exemplo n.º 1
0
        public static bool AddAndWait(this Fiber fiber, Action operation, TimeSpan timeout)
        {
            var @event = new ManualResetEvent(false);

            fiber.Add(() =>
            {
                try
                {
                    operation();
                }
                finally
                {
                    @event.Set();
                }
            });

            bool completed = @event.WaitOne(timeout);

            fiber.Add(() =>
            {
                var disposable = @event as IDisposable;
                disposable.Dispose();
            });

            return(completed);
        }
Exemplo n.º 2
0
        public void Add(Guid peerId, Uri peerUri, Guid subscriptionId, Uri endpointUri, string messageName, string correlationId)
        {
            var subscription = new PersistentSubscription(_busUri, peerId, peerUri, subscriptionId, endpointUri, messageName,
                                                          correlationId);

            _fiber.Add(() => Add(subscription));
        }
Exemplo n.º 3
0
 public void Send <T>(T message)
 {
     _fiber.Add(() =>
     {
         _contextFactory.Create(message, _root);
         _agenda.Run();
     });
 }
Exemplo n.º 4
0
        private void Schedule(ExecuteScheduledAction action)
        {
            _fiber.Add(() =>
            {
                _actions.Add(action);

                ExecuteExpiredActions();
            });
        }
Exemplo n.º 5
0
        void Schedule(ScheduledOperationExecuter action)
        {
            _fiber.Add(() =>
            {
                _operations.Add(action);

                ExecuteExpiredActions();
            });
        }
Exemplo n.º 6
0
        public void Add(PersistentSubscription subscription)
        {
            _fiber.Add(() =>
            {
                _subscriptions.Add(subscription);

                _log.DebugFormat("SubscriptionStorage.Add: {0} [{1}]", subscription, _subscriptions.Count);
            });
        }
Exemplo n.º 7
0
        public void Register(Guid key, ActorRef actor)
        {
            _fiber.Add(() =>
            {
                ActorRef existingActor;
                if (_keyIndex.TryGetValue(key, out existingActor))
                {
                    if (ReferenceEquals(existingActor, actor))
                    {
                        return;
                    }

                    Remove(key, existingActor);
                }

                if (_actors.ContainsKey(actor))
                {
                    if (existingActor != actor)
                    {
                        _events.Send(new ActorUnregisteredImpl(this, actor, _actors[actor]));
                    }

                    _actors[actor] = key;
                    _keyIndex[key] = actor;

                    _events.Send(new ActorRegisteredImpl(this, actor, key));
                    return;
                }

                Add(key, actor);
            });
        }
Exemplo n.º 8
0
        public ActorRef GetActor(Action <Inbox> initializer)
        {
            ActorInbox <TActor> inbox = null;

            Fiber fiber = _fiberFactory(new TryCatchOperationExecutor(ex =>
            {
                inbox.Send <Fault>(new
                {
                    ex.Message,
                    ex.StackTrace
                });
            }));

            Scheduler scheduler = _schedulerFactory();

            inbox = new ActorInbox <TActor>(fiber, scheduler);

            TActor instance = CreateActorInstance(fiber, scheduler, inbox);

            ApplyConventions(instance, fiber, scheduler, inbox);

            if (initializer != null)
            {
                fiber.Add(() => initializer(inbox));
            }

            return(inbox);
        }
Exemplo n.º 9
0
        public void Send <T>(T message)
        {
            _fiber.Add(() =>
            {
                try
                {
                    var envelope = new WcfMessageEnvelope
                    {
                        MessageType = typeof(T).AssemblyQualifiedName,
                        Body        = Serializer.Serialize(message),
                    };

                    WcfChannel <WcfMessageEnvelope> proxy = _channelFactory.CreateChannel();
                    proxy.Send(envelope);

                    var channel = proxy as IClientChannel;
                    if (channel != null)
                    {
                        channel.Close();
                    }

                    var disposable = proxy as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                catch
                {
                    // i hate doing this, but we don't want to take down the entire appdomain
                }
            });
        }
Exemplo n.º 10
0
 void ScheduleUpdate()
 {
     if (!_updatePending)
     {
         _updatePending = true;
         _fiber.Add(PublishWorkerAvailability);
     }
 }
Exemplo n.º 11
0
        public void Start()
        {
            if (_log.IsInfoEnabled)
            {
                _log.Info("Timeout Service Starting");
            }

            _unsubscribeToken  = _bus.SubscribeInstance(this);
            _unsubscribeToken += _bus.SubscribeSaga <TimeoutSaga>(_repository);

            _fiber.Add(CheckExistingTimeouts);

            if (_log.IsInfoEnabled)
            {
                _log.Info("Timeout Service Started");
            }
        }
Exemplo n.º 12
0
 public void Send(ConnectionContext context)
 {
     _fiber.Add(() =>
     {
         context.Response.WriteHtml(_message);
         context.Complete();
     });
 }
Exemplo n.º 13
0
 void ScheduleUpdate()
 {
     if (!_updatePending)
     {
         _updatePending = true;
         _fiber.Add(() => PublishWorkerAvailability(10.Seconds()));
     }
 }
Exemplo n.º 14
0
 public void Send(ConnectionContext context)
 {
     _fiber.Add(() =>
     {
         context.Response.RenderSparkView(_repo, "status.html");
         context.Complete();
     });
 }
Exemplo n.º 15
0
 void ScheduleWakeUp()
 {
     if (!_wakeUpPending)
     {
         _wakeUpPending = true;
         _fiber.Add(() =>
         {
             try
             {
                 _bus.Endpoint.Send(new WakeUpWorker());
             }
             catch
             {
             }
         });
     }
 }
Exemplo n.º 16
0
        public void Send(T message)
        {
            _fiber.Add(() =>
            {
                string body = _serializer.Serialize(message);

                _output.Send(body);
            });
        }
Exemplo n.º 17
0
        public void Send <T>(T message)
        {
            _fiber.Add(() =>
            {
                GetInbox <T>();

                _adapter.Send(message);
            });
        }
Exemplo n.º 18
0
        public void Send(string message)
        {
            _fiber.Add(() =>
            {
                var msg = _serializer.Deserialize <T>(message);

                _output.Send(msg);
            });
        }
Exemplo n.º 19
0
        public void Send(ICollection <T> messages)
        {
            if (messages.Count == 0)
            {
                return;
            }

            _fiber.Add(() => SendMessageToOutputChannel(messages.Last()));
        }
Exemplo n.º 20
0
        public void Send(TInput message)
        {
            _fiber.Add(() =>
            {
                TOutput outputMessage = Converter(message);

                Output.Send(outputMessage);
            });
        }
Exemplo n.º 21
0
        /// <summary>
        /// Enqueues the message to be written, after which it will invoke the completed action
        /// to complete the request/response exchange
        /// </summary>
        /// <param name="message"></param>
        public void Send(T message)
        {
            _fiber.Add(() =>
            {
                _writer.Write(message);

                _completed(this);
            });
        }
        public void Execute()
        {
            if (_cancelled)
            {
                return;
            }

            _fiber.Add(_operation);
        }
Exemplo n.º 23
0
 public void Write(ArraySegment <byte> chunk, Action <ArraySegment <byte> > unsentCallback)
 {
     _fiber.Add(() =>
     {
         if (_output != null)
         {
             _output.Send(chunk);
         }
     });
 }
Exemplo n.º 24
0
 public void Send(T message)
 {
     _fiber.Add(() =>
     {
         if (Filter(message))
         {
             Output.Send(message);
         }
     });
 }
Exemplo n.º 25
0
 public void Send(T message)
 {
     _fiber.Add(() =>
     {
         Consumer <T> consumer = _selectiveConsumer(message);
         if (consumer != null)
         {
             consumer(message);
         }
     });
 }
Exemplo n.º 26
0
        public void Send(T message)
        {
            _fiber.Add(() =>
            {
                Channel <T> channel = Provider.GetChannel(message);
                if (channel == null)
                {
                    return;
                }

                channel.Send(message);
            });
        }
        public void Send(T message)
        {
            _fiber.Add(() =>
            {
                Type messageType = Type.GetType(message.MessageType, true, true);
                if (messageType == null)
                {
                    return;
                }

                this.FastInvoke(new[] { messageType }, "Deserialize", message.Body);
            });
        }
Exemplo n.º 28
0
        public ActorInstance Create(Action <Inbox> initializer)
        {
            Fiber     fiber     = _fiberFactory();
            Scheduler scheduler = _schedulerFactory();

            var inbox = new ActorInbox <AnonymousActor>(fiber, scheduler);

            _factory(fiber, scheduler, inbox);

            fiber.Add(() => initializer(inbox));

            return(inbox);
        }
Exemplo n.º 29
0
        public void Send <T>(T message)
        {
            _fiber.Add(() =>
            {
                var envelope = new WcfMessageEnvelope
                {
                    MessageType = typeof(T).AssemblyQualifiedName,
                    Body        = Serializer.Serialize(message),
                };

                _proxy.Send(envelope);
            });
        }
        public void Send(T message)
        {
            _fiber.Add(() =>
            {
                Type messageType = Type.GetType(message.MessageType, true, true);
                if (messageType == null)
                {
                    _log.Warn(x => x.Write("Unknown message type {0}, unable to deserialize message", message.MessageType));
                    return;
                }

                this.FastInvoke(new[] { messageType }, "Deserialize", message.Body);
            });
        }