Пример #1
0
        public static BaseClientApplication CreateRoom(BaseClientApplication defaultRoom, string roomFullName, uint id = 0)
        {
            var config = defaultRoom.Configuration.Clone();

            config[Defines.CONF_APPLICATION_NAME] = roomFullName;
            var application = (BaseClientApplication)Activator.CreateInstance(defaultRoom.GetType(), (object)config);

            application.Id = id;
            RegisterApplication(application);
            application.Initialize();
            return(application);
        }
Пример #2
0
 public static bool RegisterApplication(this BaseClientApplication pClientApplication)
 {
     if (pClientApplication.Id == 0)
     {
         if (IsSlave)
         {
             pClientApplication.Id = ClusterApplication.GetProtocolHandler <SlaveClusterAppProtocolHandler>().GetAppId(pClientApplication.Name);
         }
         else
         {
             pClientApplication.Id = ++BaseClientApplication._idGenerator;
             ClusterApplication.SOManager["appList"][pClientApplication.Name] = pClientApplication.Id;
             ClusterApplication.SOManager["appList"].Track();
         }
     }
     Logger.INFO("RegisterApplication:{0}({1})", pClientApplication.Name, pClientApplication.Id);
     if (ApplicationById.ContainsKey(pClientApplication.Id))
     {
         Logger.FATAL("Client application with id {0} already registered", pClientApplication.Id);
         return(false);
     }
     if (ApplicationByName.ContainsKey(pClientApplication.Name))
     {
         Logger.FATAL("Client application with name `{0}` already registered", pClientApplication.Name);
         return(false);
     }
     if (pClientApplication.Aliases.Any(x => ApplicationByName.ContainsKey(x)))
     {
         Logger.FATAL("Client application with alias `{0}` already registered", pClientApplication.Name);
         return(false);
     }
     if (pClientApplication.Id != 0)
     {
         ApplicationById[pClientApplication.Id] = pClientApplication;
     }
     ApplicationByName[pClientApplication.Name] = pClientApplication;
     //foreach (var aliases in pClientApplication.Aliases)
     //    ApplicationByName[aliases] = pClientApplication;
     if (pClientApplication.IsDefault)
     {
         DefaultApplication = pClientApplication;
     }
     return(true);
 }
Пример #3
0
        public static BaseClientApplication GetOrCreateRoom(string roomFullName, uint id = 0)
        {
            BaseClientApplication app = FindAppByName(roomFullName);

            if (app != null)
            {
                if (id == 0 || app.Id != 0)
                {
                    return(app);
                }
                app.Id = id;
                ApplicationById[id] = app;
                return(app);
            }

            var appName = GetAppName(roomFullName);

            app = FindAppByName(appName);
            return(app == null?null:CreateRoom(app, roomFullName, id));
        }
        public static void Shutdown(BaseClientApplication pApplication)
        {
            //1. Get the list of all active protocols
            var protocols = ProtocolManager.ActiveProtocols;

            //2. enqueue for delete for all protocols bound to pApplication
            foreach (var p in protocols.Where(x => x.Value.Application != null && x.Value.Application.Id == pApplication.Id).Select(x => x.Value))
            {
                p.Application = null;
                p.EnqueueForDelete();
            }

            //1. Get the list of all active IOHandlers and enqueue for delete for all services bound to pApplication
            var handlers = IOHandlerManager.ActiveIoHandler;

            foreach (var h in handlers)
            {
                BaseProtocol pTemp = h.Value.Protocol;
                while (pTemp != null)
                {
                    if ((pTemp.Application != null) &&
                        (pTemp.Application.Id == pApplication.Id))
                    {
                        IOHandlerManager.EnqueueForDelete(h.Value);
                        break;
                    }
                    pTemp = pTemp.NearProtocol;
                }
            }

            handlers = IOHandlerManager.ActiveIoHandler;
            foreach (var h in handlers)
            {
                if (h.Value.Type == IOHandlerType.IOHT_ACCEPTOR && ((TCPAcceptor)h.Value).Application != null && ((TCPAcceptor)h.Value).Application.Id == pApplication.Id)
                {
                    IOHandlerManager.EnqueueForDelete(h.Value);
                }
            }
            //4. Unregister it
            ClientApplicationManager.UnRegisterApplication(pApplication);
        }
Пример #5
0
 public static void UnRegisterApplication(this BaseClientApplication pClientApplication)
 {
     if (ApplicationById.ContainsKey(pClientApplication.Id))
     {
         ApplicationById.Remove(pClientApplication.Id);
     }
     if (ApplicationByName.ContainsKey(pClientApplication.Name))
     {
         ApplicationByName.Remove(pClientApplication.Name);
     }
     foreach (var item in ApplicationByName.Where(x => pClientApplication.Aliases.Contains(x.Key)).ToArray())
     {
         ApplicationByName.Remove(item.Key);
     }
     if (DefaultApplication?.Id == pClientApplication.Id)
     {
         DefaultApplication = null;
     }
     pClientApplication.Log().Info("Application `{0}` ({1}) unregistered", pClientApplication.Name,
                                   pClientApplication.Id);
 }
Пример #6
0
 public static void Shutdown()
 {
     ApplicationById.Clear();
     ApplicationByName.Clear();
     DefaultApplication = null;
 }