org.xmpp.component.Component Java Examples

The following examples show how to use org.xmpp.component.Component. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComponentFinder.java    From Whack with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the value of an element selected via an xpath expression from
 * a component's component.xml file.
 *
 * @param component the component.
 * @param xpath the xpath expression.
 * @return the value of the element selected by the xpath expression.
 */
private String getElementValue(Component component, String xpath) {
    File componentDir = componentDirs.get(component);
    if (componentDir == null) {
        return null;
    }
    try {
        File componentConfig = new File(componentDir, "component.xml");
        if (componentConfig.exists()) {
            SAXReader saxReader = new SAXReader();
            Document componentXML = saxReader.read(componentConfig);
            Element element = (Element)componentXML.selectSingleNode(xpath);
            if (element != null) {
                return element.getTextTrim();
            }
        }
    }
    catch (Exception e) {
        manager.getLog().error(e);
    }
    return null;
}
 
Example #2
Source File: ComponentFinder.java    From Whack with Apache License 2.0 6 votes vote down vote up
/**
 * Unloads a component. The {@link ComponentManager#removeComponent(String)} method will be
 * called and then any resources will be released. The name should be the name of the component
 * directory and not the name as given by the component meta-data. This method only removes
 * the component but does not delete the component JAR file. Therefore, if the component JAR
 * still exists after this method is called, the component will be started again the next
 * time the component monitor process runs. This is useful for "restarting" components.<p>
 *
 * This method is called automatically when a component's JAR file is deleted.
 *
 * @param componentName the name of the component to unload.
 */
public void unloadComponent(String componentName) {
    manager.getLog().debug("Unloading component " + componentName);
    Component component = components.get(componentName);
    if (component == null) {
        return;
    }
    File webXML = new File(componentDirectory + File.separator + componentName +
            File.separator + "web" + File.separator + "web.xml");
    if (webXML.exists()) {
        //AdminConsole.removeModel(componentName);
        ComponentServlet.unregisterServlets(webXML);
    }

    ComponentClassLoader classLoader = classloaders.get(component);
    try {
        manager.removeComponent(componentDomains.get(component));
    } catch (ComponentException e) {
        manager.getLog().error("Error shutting down component", e);
    }
    classLoader.destroy();
    components.remove(componentName);
    componentDirs.remove(component);
    classloaders.remove(component);
    componentDomains.remove(component);
}
 
Example #3
Source File: ExternalComponentManager.java    From Whack with Apache License 2.0 5 votes vote down vote up
public void addComponent(String subdomain, Component component, Integer port) 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");
        }
    }
    // 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, subdomain, startEncrypted);
        // Initialize the component
        JID componentJID = new JID(null, externalComponent.getDomain(), null);
        externalComponent.initialize(componentJID, this);
    }
    catch (ComponentException e) {
        // Unregister the new component
        componentsByDomain.remove(subdomain);
        components.remove(component);
        // Re-throw the exception
        throw e;
    }
    // Ask the external component to start processing incoming packets
    externalComponent.start();
}
 
Example #4
Source File: ExternalComponent.java    From Whack with Apache License 2.0 5 votes vote down vote up
public ExternalComponent(Component component, ExternalComponentManager manager, int maxThreads) {
    this.component = component;
    this.manager = manager;

    // Create a pool of threads that will process requests received by this component. If more
    // threads are required then the command will be executed on the SocketReadThread process
    threadPool = new ThreadPoolExecutor(maxThreads, maxThreads, 15, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy());
}
 
Example #5
Source File: ComponentFinder.java    From Whack with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new component manager.
 *
 * @param componentDir the component directory.
 */
public ComponentFinder(ServerContainer server, File componentDir) {
    this.componentDirectory = componentDir;
    components = new HashMap<String,Component>();
    componentDirs = new HashMap<Component,File>();
    classloaders = new HashMap<Component,ComponentClassLoader>();
    componentDomains = new HashMap<Component,String>();
    manager = (ExternalComponentManager) server.getManager();
    setupMode = server.isSetupMode();
}
 
Example #6
Source File: ComponentFinder.java    From Whack with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the name of a component. The value is retrieved from the component.xml file
 * of the component. If the value could not be found, <tt>null</tt> will be returned.
 * Note that this value is distinct from the name of the component directory.
 *
 * @param component the component.
 * @return the component's name.
 */
public String getName(Component component) {
    String name = getElementValue(component, "/component/name");
    if (name != null) {
        return name;
    }
    else {
        return componentDirs.get(component).getName();
    }
}
 
Example #7
Source File: ExternalComponent.java    From Whack with Apache License 2.0 4 votes vote down vote up
public Component getComponent() {
    return component;
}
 
Example #8
Source File: ExternalComponentManager.java    From Whack with Apache License 2.0 4 votes vote down vote up
public void addComponent(String subdomain, Component component) throws ComponentException {
    addComponent(subdomain, component, this.port);
}
 
Example #9
Source File: ExternalComponent.java    From Whack with Apache License 2.0 4 votes vote down vote up
public ExternalComponent(Component component, ExternalComponentManager manager) {
    // Be default create a pool of 25 threads to process the received requests
    this(component, manager, 25);
}
 
Example #10
Source File: ComponentFinder.java    From Whack with Apache License 2.0 4 votes vote down vote up
public Class loadClass(String className, Component component) throws ClassNotFoundException,
        IllegalAccessException, InstantiationException
{
    ComponentClassLoader loader = classloaders.get(component);
    return loader.loadClass(className);
}
 
Example #11
Source File: ExternalComponentManager.java    From Whack with Apache License 2.0 4 votes vote down vote up
public void query(Component component, IQ packet, IQResultListener listener) throws ComponentException {
    ExternalComponent externalComponent = components.get(component);
    // Add listenet with a timeout of 5 minutes to prevent memory leaks
    externalComponent.addIQResultListener(packet.getID(), listener, 300000);
    sendPacket(component, packet);
}
 
Example #12
Source File: ExternalComponentManager.java    From Whack with Apache License 2.0 4 votes vote down vote up
public void sendPacket(Component component, Packet packet) {
    // Get the ExternalComponent that is wrapping the specified component and ask it to
    // send the packet
    components.get(component).send(packet);
}
 
Example #13
Source File: ComponentFinder.java    From Whack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the component's directory.
 *
 * @param component the component.
 * @return the component's directory.
 */
public File getComponentDirectory(Component component) {
    return componentDirs.get(component);
}
 
Example #14
Source File: ComponentFinder.java    From Whack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the description of a component. The value is retrieved from the component.xml file
 * of the component. If the value could not be found, <tt>null</tt> will be returned.
 *
 * @param component the component.
 * @return the component's description.
 */
public String getDescription(Component component) {
    return getElementValue(component, "/component/description");
}
 
Example #15
Source File: ComponentFinder.java    From Whack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the author of a component. The value is retrieved from the component.xml file
 * of the component. If the value could not be found, <tt>null</tt> will be returned.
 *
 * @param component the component.
 * @return the component's author.
 */
public String getAuthor(Component component) {
    return getElementValue(component, "/component/author");
}
 
Example #16
Source File: ComponentFinder.java    From Whack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the version of a component. The value is retrieved from the component.xml file
 * of the component. If the value could not be found, <tt>null</tt> will be returned.
 *
 * @param component the component.
 * @return the component's version.
 */
public String getVersion(Component component) {
    return getElementValue(component, "/component/version");
}
 
Example #17
Source File: ComponentFinder.java    From Whack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a component by name or <tt>null</tt> if a component with that name does not
 * exist. The name is the name of the directory that the component is in such as
 * "broadcast".
 *
 * @param name the name of the component.
 * @return the component.
 */
public Component getComponent(String name) {
    return components.get(name);
}
 
Example #18
Source File: ComponentFinder.java    From Whack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a Collection of all found components.
 *
 * @return a Collection of all found components.
 */
public Collection<Component> getComponents() {
    return Collections.unmodifiableCollection(components.values());
}