Example usage for org.apache.commons.configuration Configuration getByte

List of usage examples for org.apache.commons.configuration Configuration getByte

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getByte.

Prototype

byte getByte(String key);

Source Link

Document

Get a byte associated with the given configuration key.

Usage

From source file:com.manydesigns.elements.configuration.CommonsConfigurationFunctions.java

public static byte getByte(Configuration configuration, String key) {
    return configuration.getByte(key);
}

From source file:org.lable.oss.dynamicconfig.core.commonsconfiguration.ConcurrentConfigurationTest.java

@Test
public void testMethodWrappers() {
    CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class);
    Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null);

    concurrentConfiguration.subset("subset");
    concurrentConfiguration.isEmpty();/*from   w  w  w.j a v a 2s.  c o  m*/
    concurrentConfiguration.containsKey("key");
    concurrentConfiguration.getProperty("getprop");
    concurrentConfiguration.getKeys("getkeys");
    concurrentConfiguration.getKeys();
    concurrentConfiguration.getProperties("getprops");
    concurrentConfiguration.getBoolean("getboolean1");
    concurrentConfiguration.getBoolean("getboolean2", true);
    concurrentConfiguration.getBoolean("getboolean3", Boolean.FALSE);
    concurrentConfiguration.getByte("getbyte1");
    concurrentConfiguration.getByte("getbyte2", (byte) 0);
    concurrentConfiguration.getByte("getbyte3", Byte.valueOf((byte) 0));
    concurrentConfiguration.getDouble("getdouble1");
    concurrentConfiguration.getDouble("getdouble2", 0.2);
    concurrentConfiguration.getDouble("getdouble3", Double.valueOf(0.2));
    concurrentConfiguration.getFloat("getfloat1");
    concurrentConfiguration.getFloat("getfloat2", 0f);
    concurrentConfiguration.getFloat("getfloat3", Float.valueOf(0f));
    concurrentConfiguration.getInt("getint1");
    concurrentConfiguration.getInt("getint2", 0);
    concurrentConfiguration.getInteger("getint3", 0);
    concurrentConfiguration.getLong("getlong1");
    concurrentConfiguration.getLong("getlong2", 0L);
    concurrentConfiguration.getLong("getlong3", Long.valueOf(0L));
    concurrentConfiguration.getShort("getshort1");
    concurrentConfiguration.getShort("getshort2", (short) 0);
    concurrentConfiguration.getShort("getshort3", Short.valueOf((short) 0));
    concurrentConfiguration.getBigDecimal("getbigd1");
    concurrentConfiguration.getBigDecimal("getbigd2", BigDecimal.valueOf(0.4));
    concurrentConfiguration.getBigInteger("getbigi1");
    concurrentConfiguration.getBigInteger("getbigi2", BigInteger.valueOf(2L));
    concurrentConfiguration.getString("getstring1");
    concurrentConfiguration.getString("getstring2", "def");
    concurrentConfiguration.getStringArray("stringarray");
    concurrentConfiguration.getList("getlist1");
    concurrentConfiguration.getList("getlist2", Arrays.asList("a", "b"));

    verify(mockConfiguration, times(1)).subset("subset");
    verify(mockConfiguration, times(1)).isEmpty();
    verify(mockConfiguration, times(1)).containsKey("key");
    verify(mockConfiguration, times(1)).getProperty("getprop");
    verify(mockConfiguration, times(1)).getKeys("getkeys");
    verify(mockConfiguration, times(1)).getKeys();
    verify(mockConfiguration, times(1)).getProperties("getprops");
    verify(mockConfiguration, times(1)).getBoolean("getboolean1");
    verify(mockConfiguration, times(1)).getBoolean("getboolean2", true);
    verify(mockConfiguration, times(1)).getBoolean("getboolean3", Boolean.FALSE);
    verify(mockConfiguration, times(1)).getByte("getbyte1");
    verify(mockConfiguration, times(1)).getByte("getbyte2", (byte) 0);
    verify(mockConfiguration, times(1)).getByte("getbyte3", Byte.valueOf((byte) 0));
    verify(mockConfiguration, times(1)).getDouble("getdouble1");
    verify(mockConfiguration, times(1)).getDouble("getdouble2", 0.2);
    verify(mockConfiguration, times(1)).getDouble("getdouble3", Double.valueOf(0.2));
    verify(mockConfiguration, times(1)).getFloat("getfloat1");
    verify(mockConfiguration, times(1)).getFloat("getfloat2", 0f);
    verify(mockConfiguration, times(1)).getFloat("getfloat3", Float.valueOf(0f));
    verify(mockConfiguration, times(1)).getInt("getint1");
    verify(mockConfiguration, times(1)).getInt("getint2", 0);
    verify(mockConfiguration, times(1)).getInteger("getint3", Integer.valueOf(0));
    verify(mockConfiguration, times(1)).getLong("getlong1");
    verify(mockConfiguration, times(1)).getLong("getlong2", 0L);
    verify(mockConfiguration, times(1)).getLong("getlong3", Long.valueOf(0L));
    verify(mockConfiguration, times(1)).getShort("getshort1");
    verify(mockConfiguration, times(1)).getShort("getshort2", (short) 0);
    verify(mockConfiguration, times(1)).getShort("getshort3", Short.valueOf((short) 0));
    verify(mockConfiguration, times(1)).getBigDecimal("getbigd1");
    verify(mockConfiguration, times(1)).getBigDecimal("getbigd2", BigDecimal.valueOf(0.4));
    verify(mockConfiguration, times(1)).getBigInteger("getbigi1");
    verify(mockConfiguration, times(1)).getBigInteger("getbigi2", BigInteger.valueOf(2L));
    verify(mockConfiguration, times(1)).getString("getstring1");
    verify(mockConfiguration, times(1)).getString("getstring2", "def");
    verify(mockConfiguration, times(1)).getStringArray("stringarray");
    verify(mockConfiguration, times(1)).getList("getlist1");
    verify(mockConfiguration, times(1)).getList("getlist2", Arrays.asList("a", "b"));
}

From source file:org.mobicents.servlet.restcomm.sms.smpp.SmppService.java

private void initializeSmppConnections() {
    Configuration smppConfiguration = this.configuration.subset("smpp");

    List<Object> smppConnections = smppConfiguration.getList("connections.connection.name");

    int smppConnecsSize = smppConnections.size();
    if (smppConnecsSize == 0) {
        logger.warning("No SMPP Connections defined!");
        return;//ww  w.  ja  v a  2s. c o  m
    }

    for (int count = 0; count < smppConnecsSize; count++) {
        String name = smppConfiguration.getString("connections.connection(" + count + ").name");
        String systemId = smppConfiguration.getString("connections.connection(" + count + ").systemid");
        String peerIp = smppConfiguration.getString("connections.connection(" + count + ").peerip");
        int peerPort = smppConfiguration.getInt("connections.connection(" + count + ").peerport");
        SmppBindType bindtype = SmppBindType
                .valueOf(smppConfiguration.getString("connections.connection(" + count + ").bindtype"));

        if (bindtype == null) {
            logger.warning("Bindtype for SMPP name=" + name + " is not specified. Using default TRANSCEIVER");
        }

        String password = smppConfiguration.getString("connections.connection(" + count + ").password");
        String systemType = smppConfiguration.getString("connections.connection(" + count + ").systemtype");

        byte interfaceVersion = smppConfiguration
                .getByte("connections.connection(" + count + ").interfaceversion");

        byte ton = smppConfiguration.getByte("connections.connection(" + count + ").ton");
        byte npi = smppConfiguration.getByte("connections.connection(" + count + ").npi");
        String range = smppConfiguration.getString("connections.connection(" + count + ").range");

        Address address = null;
        if (ton != -1 && npi != -1 && range != null) {
            address = new Address(ton, npi, range);
        }

        int windowSize = smppConfiguration.getInt("connections.connection(" + count + ").windowsize");

        long windowWaitTimeout = smppConfiguration
                .getLong("connections.connection(" + count + ").windowwaittimeout");

        long connectTimeout = smppConfiguration.getLong("connections.connection(" + count + ").connecttimeout");
        long requestExpiryTimeout = smppConfiguration
                .getLong("connections.connection(" + count + ").requestexpirytimeout");
        long windowMonitorInterval = smppConfiguration
                .getLong("connections.connection(" + count + ").windowmonitorinterval");
        boolean logBytes = smppConfiguration.getBoolean("connections.connection(" + count + ").logbytes");
        boolean countersEnabled = smppConfiguration
                .getBoolean("connections.connection(" + count + ").countersenabled");

        long enquireLinkDelay = smppConfiguration
                .getLong("connections.connection(" + count + ").enquirelinkdelay");

        Smpp smpp = new Smpp(name, systemId, peerIp, peerPort, bindtype, password, systemType, interfaceVersion,
                address, connectTimeout, windowSize, windowWaitTimeout, requestExpiryTimeout,
                windowMonitorInterval, countersEnabled, logBytes, enquireLinkDelay);

        this.smppList.add(smpp);

        if (logger.isInfoEnabled()) {
            logger.info("creating new SMPP connection " + smpp);
        }

    }

    // for monitoring thread use, it's preferable to create your own
    // instance of an executor and cast it to a ThreadPoolExecutor from
    // Executors.newCachedThreadPool() this permits exposing thinks like
    // executor.getActiveCount() via JMX possible no point renaming the
    // threads in a factory since underlying Netty framework does not easily
    // allow you to customize your thread names
    this.executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();

    // to enable automatic expiration of requests, a second scheduled
    // executor is required which is what a monitor task will be executed
    // with - this is probably a thread pool that can be shared with between
    // all client bootstraps
    this.monitorExecutor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1,
            new ThreadFactory() {
                private AtomicInteger sequence = new AtomicInteger(0);

                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName("SmppServer-SessionWindowMonitorPool-" + sequence.getAndIncrement());
                    return t;
                }
            });

    // a single instance of a client bootstrap can technically be shared
    // between any sessions that are created (a session can go to any
    // different number of SMSCs) - each session created under a client
    // bootstrap will use the executor and monitorExecutor set in its
    // constructor - just be *very* careful with the "expectedSessions"
    // value to make sure it matches the actual number of total concurrent
    // open sessions you plan on handling - the underlying netty library
    // used for NIO sockets essentially uses this value as the max number of
    // threads it will ever use, despite the "max pool size", etc. set on
    // the executor passed in here

    // Setting expected session to be 25. May be this should be
    // configurable?
    this.clientBootstrap = new DefaultSmppClient(this.executor, 25, monitorExecutor);

    this.smppClientOpsThread = new SmppClientOpsThread(this.clientBootstrap, outboundInterface("udp").getPort(),
            smppMessageHandler);

    (new Thread(this.smppClientOpsThread)).start();

    for (Smpp smpp : this.smppList) {
        this.smppClientOpsThread.scheduleConnect(smpp);
    }

    if (logger.isInfoEnabled()) {
        logger.info("SMPP Service started");
    }
}