Search in sources :

Example 1 with Configurable

use of org.jpos.core.Configurable in project jPOS by jpos.

the class LoggerAdaptor method addListener.

private void addListener(Element e) throws ConfigurationException {
    QFactory factory = getServer().getFactory();
    String clazz = e.getAttributeValue("class");
    LogListener listener = (LogListener) factory.newInstance(clazz);
    if (listener instanceof Configurable) {
        try {
            ((Configurable) listener).setConfiguration(factory.getConfiguration(e));
        } catch (ConfigurationException ex) {
            throw new ConfigurationException(ex);
        }
    }
    logger.addListener(listener);
}
Also used : LogListener(org.jpos.util.LogListener) ConfigurationException(org.jpos.core.ConfigurationException) QFactory(org.jpos.q2.QFactory) Configurable(org.jpos.core.Configurable)

Example 2 with Configurable

use of org.jpos.core.Configurable in project jPOS by jpos.

the class CardAgentAdaptor method startService.

protected void startService() throws Exception {
    Object obj = getObject();
    if (obj instanceof Configurable) {
        QFactory factory = getServer().getFactory();
        Element e = getPersist();
        ((Configurable) obj).setConfiguration(factory.getConfiguration(e));
    }
    CardAgentLookup.add((CardAgent) getObject());
}
Also used : Element(org.jdom2.Element) Configurable(org.jpos.core.Configurable) QFactory(org.jpos.q2.QFactory)

Example 3 with Configurable

use of org.jpos.core.Configurable in project jPOS by jpos.

the class BaseChannel method setConfiguration.

/**
 * Implements Configurable<br>
 * Properties:<br>
 * <ul>
 * <li>host - destination host (if ClientChannel)
 * <li>port - port number      (if ClientChannel)
 * <li>local-iface - local interfase to use (if ClientChannel)
 * <li>local-port - local port to bind (if ClientChannel)
 * </ul>
 * (host not present indicates a ServerChannel)
 *
 * @param cfg Configuration
 * @throws ConfigurationException
 */
public void setConfiguration(Configuration cfg) throws ConfigurationException {
    this.cfg = cfg;
    String h = cfg.get("host");
    int port = cfg.getInt("port");
    maxPacketLength = cfg.getInt("max-packet-length", 100000);
    if (h != null && h.length() > 0) {
        if (port == 0)
            throw new ConfigurationException("invalid port for host '" + h + "'");
        setHost(h, port);
        setLocalAddress(cfg.get("local-iface", null), cfg.getInt("local-port"));
        String[] altHosts = cfg.getAll("alternate-host");
        int[] altPorts = cfg.getInts("alternate-port");
        hosts = new String[altHosts.length + 1];
        ports = new int[altPorts.length + 1];
        if (hosts.length != ports.length) {
            throw new ConfigurationException("alternate host/port misconfiguration");
        }
        hosts[0] = host;
        ports[0] = port;
        System.arraycopy(altHosts, 0, hosts, 1, altHosts.length);
        System.arraycopy(altPorts, 0, ports, 1, altPorts.length);
    }
    setOverrideHeader(cfg.getBoolean("override-header", false));
    keepAlive = cfg.getBoolean("keep-alive", false);
    expectKeepAlive = cfg.getBoolean("expect-keep-alive", false);
    roundRobin = cfg.getBoolean("round-robin", false);
    if (socketFactory != this && socketFactory instanceof Configurable)
        ((Configurable) socketFactory).setConfiguration(cfg);
    try {
        setTimeout(cfg.getInt("timeout", DEFAULT_TIMEOUT));
        connectTimeout = cfg.getInt("connect-timeout", timeout);
    } catch (SocketException e) {
        throw new ConfigurationException(e);
    }
}
Also used : ConfigurationException(org.jpos.core.ConfigurationException) Configurable(org.jpos.core.Configurable)

Example 4 with Configurable

use of org.jpos.core.Configurable in project jPOS by jpos.

the class PackagerWrapper method setConfiguration.

/**
 * requires <code>inner-packager</code> property
 * @param cfg Configuration object
 * @throws ConfigurationException
 */
public void setConfiguration(Configuration cfg) throws ConfigurationException {
    this.cfg = cfg;
    String packagerName = cfg.get("inner-packager");
    try {
        Class p = Class.forName(packagerName);
        setPackager((ISOPackager) p.newInstance());
        if (standardPackager instanceof Configurable)
            ((Configurable) standardPackager).setConfiguration(cfg);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationException("Invalid inner-packager", e);
    } catch (InstantiationException e) {
        throw new ConfigurationException("Invalid inner-packager", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException("Invalid inner-packager", e);
    }
}
Also used : ConfigurationException(org.jpos.core.ConfigurationException) Configurable(org.jpos.core.Configurable)

Example 5 with Configurable

use of org.jpos.core.Configurable in project jPOS by jpos.

the class DailyTaskAdaptor method startService.

protected void startService() throws Exception {
    if (task instanceof Configurable) {
        Element e = getPersist();
        QFactory factory = getServer().getFactory();
        ((Configurable) task).setConfiguration(factory.getConfiguration(e));
    }
    (thisThread = new Thread(this)).start();
}
Also used : Element(org.jdom2.Element) Configurable(org.jpos.core.Configurable) QFactory(org.jpos.q2.QFactory)

Aggregations

Configurable (org.jpos.core.Configurable)7 ConfigurationException (org.jpos.core.ConfigurationException)4 QFactory (org.jpos.q2.QFactory)4 Element (org.jdom2.Element)2 UnknownHostException (java.net.UnknownHostException)1 Configuration (org.jpos.core.Configuration)1 LogListener (org.jpos.util.LogListener)1 LogSource (org.jpos.util.LogSource)1 ThreadPool (org.jpos.util.ThreadPool)1