componentsByDomain.put(subdomain, externalComponent); components.put(component, externalComponent);
componentsByDomain.remove(subdomain); components.remove(component);
    public void addComponent(String subdomain, Component component) throws ComponentException {        if (componentsByDomain.containsKey(subdomain)) {            if (componentsByDomain.get(subdomain).getComponent() == component) {                // Do nothing since the component has already been registered                return;            }            else {                throw new IllegalArgumentException("Subdomain already in use by another component");            }        }        // Find the proper secret key to connect as the subdomain.        String secretKey = secretKeys.get(subdomain);        if (secretKey == null) {            secretKey = defaultSecretKey;        }        // Create a wrapping ExternalComponent on the component        ExternalComponent externalComponent = new ExternalComponent(component, this);        try {            // Register the new component            componentsByDomain.put(subdomain, externalComponent);            components.put(component, externalComponent);            // Ask the ExternalComponent to connect with the remote server            externalComponent.connect(host, port, SocketFactory.getDefault(), subdomain);        } catch (ComponentException e) {            // Unregister the new component            componentsByDomain.put(subdomain, externalComponent);            components.put(component, externalComponent);            // Re-throw the exception            throw e;        }        // Initialize the component        JID componentJID = new JID(null, externalComponent.getDomain(), null);        externalComponent.initialize(componentJID, this);        // Asl the external component to start processing incoming packets        externalComponent.start();    }