⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apiconfig.java

📁 SMPP(点到点短消息协议)的java实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package ie.omk.smpp.util;import java.io.IOException;import java.io.PrintWriter;import java.io.StringWriter;import java.net.URL;import java.util.Properties;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * Internal API configuration. This class holds the configuration for * the smppapi. On initialisation, it searches for a file named * "smppapi.properties". This file needs to be locatable in the classpath in one * of the following locations: /, /ie, /ie/omk, /ie/omk/smpp or the default * classloader for this class must be able to find it. * <p> * Most applications can probably accept the default settings of the API. If, * however, you're trying to eke maximum performance out of your application, * tweaking these settings may help. * </p> * <p> * Supported API properties are: <table cols="3" border="1" width="100%"> * <tr> * <th width="25%">Property name</th> * <th width="25%">Type</th> * <th width="50%">Description</th> * </tr> *  * <tr> * <td><code>smppapi.net.buffersize_in</code></td> * <td>Integer</td> * <td>Sets the size of the buffer used on the incoming stream connection from * the SMSC. A plain value specified the number of bytes. A suffix of 'k' after * the number will be interpreted as kilobytes and a suffix of 'm' will be * interpreted as megabytes. For example, 4k will allocate a buffer size of 4096 * bytes.</td> * </tr> *  * <tr> * <td><code>smppapi.net.buffersize_out</code></td> * <td>Integer</td> * <td>Sets the size of the buffer used on the outgoing stream connection to * the SMSC. A plain value specified the number of bytes. A suffix of 'k' after * the number will be interpreted as kilobytes and a suffix of 'm' will be * interpreted as megabytes. For example, 4k will allocate a buffer size of 4096 * bytes.</td> * </tr> *  * <tr> * <td><code>smppapi.net.autoflush</code></td> * <td>Boolean</td> * <td>By default, the {@link ie.omk.smpp.net.SmscLink}class automatically * flushes the output stream after every packet written to the output stream. In * high-load environments, it may be better to turn this off and manually flush * the output stream only when required (after a short period of inactivity, for * example).</td> * </tr> *  * <tr> * <td><code>smppapi.net.autoclose_snoop</code></td> * <td>Boolean</td> * <td>If snoop streams are set on the SMSC link object and this value is true * (the default), the snoop streams will be closed when the link is closed. If * false, the snoop streams will be flushed and left open when the link is * closed.</td> * </tr> *  * <tr> * <td><code>smppapi.net.link_timeout</code></td> * <td>Long</td> * <td>Sets the timeout in milliseconds for network links. This value affects * how long network reads should block for but its exact interpretation is * link-implementation specific. For <code>TcpLink</code>, this value represents * the <code>SO_TIMEOUT</code> setting on the TCP/IP socket.</td> * </tr> *  * <tr> * <td><code>smppapi.connection.bind_timeout</code></td> * <td>Long</td> * <td>The length of time, in milliseconds, to wait for a bind response packet * after sending a bind request. If a packet is not received within this time * period, the network connection is closed. A negative value or zero means wait * indefinitely.</td> * </tr> *  * <tr> * <td><code>smppapi.connection.rcv_daemon.ioex_count</code></td> * <td>Integer</td> * <td>The number of I/O exceptions the receiver daemon will accept occurring * before exiting.</td> * </tr> *  * <tr> * <td><code>smppapi.event.dispatcher</code></td> * <td>String</td> * <td>The name of a class which implements the * {@link ie.omk.smpp.event.EventDispatcher}which will be used as the default * event dispatcher for <code>Connection</code> objects.</td> * </tr> *  * <tr> * <td><code>smppapi.event.threaded_dispatcher.pool_size</code></td> * <td>Integer</td> * <td>The size of the thread pool used by the * {@link ie.omk.smpp.event.ThreadedEventDispatcher}class.</td> * </tr> *  * <tr> * <td><code>smppapi.event.threaded_dispatcher.queue_size</code></td> * <td>Integer</td> * <td>The size of the event FIFO queue used in the * <code>ie.omk.smpp.event.ThreadedEventDispatcher</code> class.</td> * </tr> *  * </table> *   */public final class APIConfig extends Properties {    private static final String BAD_PROPERTY_VALUE = "Bad property value";    static final long serialVersionUID = 3668742926704484281L;        /**     * See class description for documentation on the properties.     *      * @deprecated use LINK_TIMEOUT     */    public static final String TCP_SOCKET_TIMEOUT = "smppapi.net.tcp.so_timeout";    /**     * See class description for documentation on the properties.     */    public static final String LINK_BUFFERSIZE_IN = "smppapi.net.buffersize_in";    /**     * See class description for documentation on the properties.     */    public static final String LINK_BUFFERSIZE_OUT = "smppapi.net.buffersize_out";    /**     * See class description for documentation on the properties.     */    public static final String LINK_AUTO_FLUSH = "smppapi.net.autoflush";    /**     * See class description for documentation on the properties.     */    public static final String LINK_AUTOCLOSE_SNOOP = "smppapi.net.autoclose_snoop";    /**     * See class description for documentation on the properties.     */    public static final String LINK_TIMEOUT = "smppapi.net.link_timeout";    /**     * See class description for documentation on the properties.     */    public static final String TOO_MANY_IO_EXCEPTIONS = "smppapi.connection.rcv_daemon.ioex_count";    /**     * See class description for documentation on the properties.     */    public static final String EVENT_DISPATCHER_CLASS = "smppapi.event.dispatcher";    /**     * See class description for documentation on the properties.     */    public static final String EVENT_THREAD_POOL_SIZE = "smppapi.event.threaded_dispatcher.pool_size";    /**     * See class description for documentation on the properties.     */    public static final String EVENT_THREAD_FIFO_QUEUE_SIZE = "smppapi.event.threaded_dispatcher.queue_size";    /**     * See class description for documentation on the properties.     */    public static final String BIND_TIMEOUT = "smppapi.connection.bind_timeout";    private static final Log LOGGER = LogFactory.getLog(APIConfig.class);    /**     * Paths to search for the API properties file. These should always end in     * the '/' character except for the last entry which should be a blank     * string.     */    private static final String[] SEARCH_PATH = {"/", "/ie/", "/ie/omk/",            "/ie/omk/smpp/", "", };    /**     * Name of the resource to load properties from.     */    private static final String PROPS_RESOURCE = "smppapi.properties";    /**     * The singleton instance of the API configuration.     */    private static APIConfig instance;    /**     * The URL that API properties are loaded from (including path info).     */    private URL propsURL;    /**     * Construct a new APIConfig object which reads properties from the     * default properties resource.     */    public APIConfig() {        this.propsURL = getDefaultPropertiesResource();    }        /**     * Construct a new APIConfig object which reads properties from the     * specified URL.     * @param propertiesURL The URL to read properties from.     */    public APIConfig(URL propertiesURL) {        this.propsURL = propertiesURL;    }    /**     * Cause the API properties to be reloaded. The properties will be re-read     * from the same location as they were initially loaded from. If the     * resource has disappeared or is no longer accessible, the properties will     * not be loaded and <code>false</code> will be returned to the caller.     *      * @return true if the properties were successfully reloaded, false     *         otherwise.     */    public boolean reloadAPIConfig() {        LOGGER.debug("Reloading API config properties.");        try {            loadAPIProperties();        } catch (IOException x) {            LOGGER.warn("Could not reload API properties.", x);            return false;        }        return true;    }    /**     * Get the <code>APIConfig</code> instance. If the     * <code>APIConfig</code> instance has not yet been initialised then     * this method will cause the configuration to be read from the default     * properties resource. The default resource will be searched for at     * the following locations in the classpath:     * /smppapi.properties     * /ie/smppapi.properties     * /ie/omk/smppapi.properties     * /ie/omk/smpp/smppapi.properties     * smppapi.properties     * @return An initialised instance of <code>APIConfig</code>.     */    public static APIConfig getInstance() {        if (instance == null) {            try {                instance = new APIConfig();                instance.loadAPIProperties();            } catch (IOException x) {                LOGGER.error("Could not load API properties from default resource", x);            }        }        return instance;    }    /**     * Set the URL which <code>APIConfig</code> reads its properties from     * and load them.     * @param properties     */    public static void configure(URL properties) {        try {            if (instance == null) {                instance = new APIConfig(properties);            } else {                instance.propsURL = properties;            }            instance.loadAPIProperties();        } catch (IOException x) {            LOGGER.error("Could not load API config from " + properties, x);        }    }        /**     * Get the value for a property.     *      * @param property     *            the name of the property to retrieve.     * @return The value for <code>property</code>.     * @throws ie.omk.smpp.util.PropertyNotFoundException     *             if <code>property</code> is not found in the configuration.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -