public void Register(IAppHost appHost)
        {
            var container = appHost.GetContainer();

            if (!container.Exists <IServerEvents>())
            {
                var broker = new MemoryServerEvents
                {
                    IdleTimeout                  = IdleTimeout,
                    HouseKeepingInterval         = HouseKeepingInterval,
                    OnSubscribe                  = OnSubscribe,
                    OnUnsubscribe                = OnUnsubscribe,
                    NotifyChannelOfSubscriptions = NotifyChannelOfSubscriptions,
                    OnError = OnError,
                };
                container.Register <IServerEvents>(broker);
            }

            appHost.RawHttpHandlers.Add(httpReq =>
                                        httpReq.PathInfo.EndsWith(StreamPath)
                    ? (IHttpHandler) new ServerEventsHandler()
                    : httpReq.PathInfo.EndsWith(HeartbeatPath)
                      ? new ServerEventsHeartbeatHandler()
                      : null);

            if (UnRegisterPath != null)
            {
                appHost.RegisterService(typeof(ServerEventsUnRegisterService), UnRegisterPath);
            }

            if (SubscribersPath != null)
            {
                appHost.RegisterService(typeof(ServerEventsSubscribersService), SubscribersPath);
            }
        }
Beispiel #2
0
        public void Register(IAppHost appHost)
        {
            var broker = new MemoryServerEvents
            {
                Timeout       = Timeout,
                OnSubscribe   = OnSubscribe,
                OnUnsubscribe = OnUnsubscribe,
                NotifyChannelOfSubscriptions = NotifyChannelOfSubscriptions,
            };
            var container = appHost.GetContainer();

            if (container.TryResolve <IServerEvents>() == null)
            {
                container.Register <IServerEvents>(broker);
            }

            appHost.RawHttpHandlers.Add(httpReq =>
                                        httpReq.PathInfo.EndsWith(StreamPath)
                    ? (IHttpHandler) new ServerEventsHandler()
                    : httpReq.PathInfo.EndsWith(HeartbeatPath)
                      ? new ServerEventsHeartbeatHandler()
                      : null);

            if (UnRegisterPath != null)
            {
                appHost.RegisterService(typeof(ServerEventsUnRegisterService), UnRegisterPath);
            }

            if (SubscribersPath != null)
            {
                appHost.RegisterService(typeof(ServerEventsSubscribersService), SubscribersPath);
            }
        }
Beispiel #3
0
        public RedisServerEvents(IRedisPubSubServer redisPubSub)
        {
            this.RedisPubSub      = redisPubSub;
            this.clientsManager   = redisPubSub.ClientsManager;
            redisPubSub.OnInit    = OnInit;
            redisPubSub.OnError   = ex => Log.Error("Exception in RedisServerEvents: " + ex.Message, ex);
            redisPubSub.OnMessage = HandleMessage;

            KeepAliveRetryAfterMs = 2000;

            local = new MemoryServerEvents
            {
                NotifyJoin      = HandleOnJoin,
                NotifyLeave     = HandleOnLeave,
                NotifyHeartbeat = HandleOnHeartbeat,
                Serialize       = HandleSerialize,
            };

            var appHost = HostContext.AppHost;
            var feature = appHost != null?appHost.GetPlugin <ServerEventsFeature>() : null;

            if (feature != null)
            {
                Timeout       = feature.IdleTimeout;
                OnSubscribe   = feature.OnSubscribe;
                OnUnsubscribe = feature.OnUnsubscribe;
                NotifyChannelOfSubscriptions = feature.NotifyChannelOfSubscriptions;
            }
        }
Beispiel #4
0
        public RedisServerEvents(IRedisPubSubServer redisPubSub)
        {
            this.RedisPubSub      = redisPubSub;
            this.clientsManager   = redisPubSub.ClientsManager;
            redisPubSub.OnInit    = OnInit;
            redisPubSub.OnError   = ex => Log.Error("Exception in RedisServerEvents: " + ex.Message, ex);
            redisPubSub.OnMessage = HandleMessage;

            WaitBeforeNextRestart = TimeSpan.FromMilliseconds(2000);

            local = new MemoryServerEvents
            {
                NotifyJoin      = HandleOnJoin,
                NotifyLeave     = HandleOnLeave,
                NotifyUpdate    = HandleOnUpdate,
                NotifyHeartbeat = HandleOnHeartbeat,
                Serialize       = HandleSerialize,
            };

            var appHost = HostContext.AppHost;
            var feature = appHost != null?appHost.GetPlugin <ServerEventsFeature>() : null;

            if (feature != null)
            {
                Timeout = feature.IdleTimeout;
                HouseKeepingInterval         = feature.HouseKeepingInterval;
                OnSubscribe                  = feature.OnSubscribe;
                OnUnsubscribe                = feature.OnUnsubscribe;
                NotifyChannelOfSubscriptions = feature.NotifyChannelOfSubscriptions;
            }
        }
        public void Dispose()
        {
            try
            {
                foreach (var entry in local.Subcriptions)
                {
                    var info = local.GetSubscriptionInfo(entry.Key);
                    if (info != null)
                    {
                        RemoveSubscriptionFromRedis(info);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warn("Error trying to remove local.Subcriptions during Dispose()...", ex);
            }

            if (RedisPubSub != null)
            {
                RedisPubSub.Dispose();
            }

            if (local != null)
            {
                local.Dispose();
            }

            RedisPubSub = null;
            local       = null;
        }
Beispiel #6
0
        public void Dispose()
        {
            if (RedisPubSub != null)
            {
                RedisPubSub.Dispose();
            }

            if (local != null)
            {
                local.Dispose();
            }

            RedisPubSub = null;
            local       = null;
        }
Beispiel #7
0
        public void Register(IAppHost appHost)
        {
            var container = appHost.GetContainer();

            if (!container.Exists <IServerEvents>())
            {
                var broker = new MemoryServerEvents
                {
                    IdleTimeout                  = IdleTimeout,
                    HouseKeepingInterval         = HouseKeepingInterval,
                    OnSubscribe                  = OnSubscribe,
                    OnUnsubscribe                = OnUnsubscribe,
                    NotifyChannelOfSubscriptions = NotifyChannelOfSubscriptions,
                    OnError = OnError,
                };
                container.Register <IServerEvents>(broker);
            }

            appHost.RawHttpHandlers.Add(httpReq =>
                                        httpReq.PathInfo.EndsWith(StreamPath)
                                        ? (IServiceStackHandler) new ServerEventsHandler()
                                        : httpReq.PathInfo.EndsWith(HeartbeatPath)
                                          ? new ServerEventsHeartbeatHandler()
                                          : null);

            if (UnRegisterPath != null)
            {
                appHost.RegisterService(typeof(ServerEventsUnRegisterService), UnRegisterPath);
            }

            if (SubscribersPath != null)
            {
                appHost.RegisterService(typeof(ServerEventsSubscribersService), SubscribersPath);
            }

            appHost.GetPlugin <MetadataFeature>()
            ?.AddLink(MetadataFeature.AvailableFeatures, "http://docs.servicestack.net/server-events", "Server Events");
        }