Search in sources :

Example 46 with Configuration

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

the class JPOSLogger method isLevelEnabled.

protected boolean isLevelEnabled(int logLevel) {
    Logger logger = log.getLogger();
    Configuration cfg = logger.getConfiguration();
    if (cfg == null)
        cfg = new SimpleConfiguration();
    String levelString = cfg.get("slf4j.level", System.getProperty("slf4j.level"));
    int currentLogLevel = levelString != null ? stringToLevel(levelString) : DEFAULT_LOG_LEVEL;
    return (logLevel >= currentLogLevel);
}
Also used : Configuration(org.jpos.core.Configuration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Logger(org.jpos.util.Logger) LocationAwareLogger(org.slf4j.spi.LocationAwareLogger)

Example 47 with Configuration

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

the class QFactory method getConfiguration.

public Configuration getConfiguration(Element e) throws ConfigurationException {
    String configurationFactoryClazz = e.getAttributeValue("configuration-factory");
    ConfigurationFactory cf = configurationFactoryClazz != null ? (ConfigurationFactory) newInstance(configurationFactoryClazz) : defaultConfigurationFactory;
    Configuration cfg = cf.getConfiguration(e);
    String merge = e.getAttributeValue("merge-configuration");
    if (merge != null) {
        StringTokenizer st = new StringTokenizer(merge, ", ");
        while (st.hasMoreElements()) {
            try {
                Configuration c = QConfig.getConfiguration(st.nextToken());
                for (String k : c.keySet()) {
                    if (cfg.get(k, null) == null) {
                        String[] v = c.getAll(k);
                        switch(v.length) {
                            case 0:
                                break;
                            case 1:
                                cfg.put(k, v[0]);
                                break;
                            default:
                                cfg.put(k, v);
                        }
                    }
                }
            } catch (NameRegistrar.NotFoundException ex) {
                throw new ConfigurationException(ex.getMessage());
            }
        }
    }
    return cfg;
}
Also used : StringTokenizer(java.util.StringTokenizer) NameRegistrar(org.jpos.util.NameRegistrar) Configuration(org.jpos.core.Configuration) ConfigurationException(org.jpos.core.ConfigurationException)

Example 48 with Configuration

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

the class DirPollAdaptor method initService.

protected void initService() throws Exception {
    QFactory factory = getServer().getFactory();
    dirPoll = createDirPoll();
    dirPoll.setPath(getPath());
    dirPoll.setThreadPool(new ThreadPool(1, poolSize));
    dirPoll.setPollInterval(pollInterval);
    if (priorities != null)
        dirPoll.setPriorities(priorities);
    dirPoll.setLogger(getLog().getLogger(), getLog().getRealm());
    Configuration cfg = factory.getConfiguration(getPersist());
    dirPoll.setConfiguration(cfg);
    dirPoll.createDirs();
    Object dpp = factory.newInstance(getProcessor());
    if (dpp instanceof LogSource) {
        ((LogSource) dpp).setLogger(getLog().getLogger(), getLog().getRealm());
    }
    if (dpp instanceof Configurable) {
        ((Configurable) dpp).setConfiguration(cfg);
    }
    dirPoll.setProcessor(dpp);
}
Also used : Configuration(org.jpos.core.Configuration) LogSource(org.jpos.util.LogSource) ThreadPool(org.jpos.util.ThreadPool) QFactory(org.jpos.q2.QFactory) Configurable(org.jpos.core.Configurable)

Example 49 with Configuration

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

the class IncomingListener method setConfiguration.

@SuppressWarnings("unchecked")
public void setConfiguration(Configuration cfg) throws ConfigurationException {
    timeout = cfg.getLong("timeout", 15000L);
    sp = (Space<String, Context>) SpaceFactory.getSpace(cfg.get("space"));
    queue = cfg.get("queue", null);
    if (queue == null)
        throw new ConfigurationException("queue property not specified");
    source = cfg.get("source", ContextConstants.SOURCE.toString());
    request = cfg.get("request", ContextConstants.REQUEST.toString());
    timestamp = cfg.get("timestamp", ContextConstants.TIMESTAMP.toString());
    remote = cfg.getBoolean("remote") || cfg.get("space").startsWith("rspace:");
    Map<String, String> m = new HashMap<>();
    cfg.keySet().stream().filter(s -> s.startsWith("ctx.")).forEach(s -> m.put(s.substring(4), cfg.get(s)));
    if (m.size() > 0)
        additionalContextEntries = m;
}
Also used : Context(org.jpos.transaction.Context) Context(org.jpos.transaction.Context) SpaceFactory(org.jpos.space.SpaceFactory) ConfigurationException(org.jpos.core.ConfigurationException) Date(java.util.Date) SpaceSource(org.jpos.space.SpaceSource) LocalSpace(org.jpos.space.LocalSpace) Log(org.jpos.util.Log) HashMap(java.util.HashMap) Configurable(org.jpos.core.Configurable) ContextConstants(org.jpos.transaction.ContextConstants) Space(org.jpos.space.Space) Configuration(org.jpos.core.Configuration) Map(java.util.Map) ConfigurationException(org.jpos.core.ConfigurationException) HashMap(java.util.HashMap)

Aggregations

Configuration (org.jpos.core.Configuration)49 Test (org.junit.Test)45 SimpleConfiguration (org.jpos.core.SimpleConfiguration)39 SubConfiguration (org.jpos.core.SubConfiguration)35 ConfigurationException (org.jpos.core.ConfigurationException)8 Properties (java.util.Properties)4 Logger (org.jpos.util.Logger)4 LogEvent (org.jpos.util.LogEvent)3 Configurable (org.jpos.core.Configurable)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 ISOChannel (org.jpos.iso.ISOChannel)1 ISOMsg (org.jpos.iso.ISOMsg)1 ISOVMsg (org.jpos.iso.ISOVMsg)1 CSChannel (org.jpos.iso.channel.CSChannel)1 LogChannel (org.jpos.iso.channel.LogChannel)1