////////////////////////////////////////////////////////////////////////// // Lifecycle ////////////////////////////////////////////////////////////////////////// public static Service install(Service self) { try { List types = FanObj.@typeof(self).inheritance(); lock (m_lock) { // if already installed, short circuit if (self.isInstalled()) { return(self); } // add to byService map byService[self] = new State(self); // add to map for each type service implements for (int i = 0; i < types.sz(); ++i) { Type t = (Type)types.get(i); if (!isServiceType(t)) { continue; } Node node = new Node(self); Node x = (Node)byType[t.qname()]; if (x == null) { byType[t.qname()] = node; } else { while (x.next != null) { x = x.next; } x.next = node; } } } } catch (System.Exception e) { Err.dumpStack(e); } return(self); }
public static Service uninstall(Service self) { try { List types = FanObj.@typeof(self).inheritance(); lock (m_lock) { // ensure service is stopped stop(self); // remove from byService map, it not installed short circuit if (byService[self] == null) { return(self); } byService.Remove(self); // remove from map for each type implemented by service for (int i = 0; i < types.sz(); ++i) { // get next type in inheritance and check if service type Type t = (Type)types.get(i); if (!isServiceType(t)) { continue; } // lookup linked list for that type Node node = (Node)byType[t.qname()]; if (node == null) { continue; } // find this thread in the linked list Node last = null; bool cont = false; while (node.service != self) { last = node; node = node.next; if (node == null) { cont = true; break; } } if (cont) { continue; } // update the map or linked list if (last == null) { byType[t.qname()] = node.next; } else { last.next = node.next; } } } } catch (System.Exception e) { Err.dumpStack(e); } return(self); }