/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/util/APIConfig.java

http://mobicents.googlecode.com/ · Java · 390 lines · 32 code · 30 blank · 328 comment · 0 complexity · d14ba9139e35229d5b713984cc299cdc MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.smpp.util;
  23. /**
  24. * Interface for internal API configuration implementations.
  25. * Implementation of this class hold the configuration for
  26. * the smppapi. The API configuration is loaded by the
  27. * {@link APIConfigFactory} class.
  28. * <p>
  29. * Implementations <strong>must</strong> supply a no-argument constructor
  30. * so that <tt>APIConfigFactory</tt> can instantiate it.
  31. * </p>
  32. * <p>
  33. * Most applications can probably accept the default settings of the API. If,
  34. * however, you're trying to eke maximum performance out of your application,
  35. * tweaking these settings may help.
  36. * </p>
  37. * <p>
  38. * Supported API properties are:
  39. * </p>
  40. * <table cols="3" border="1" width="100%">
  41. * <tr>
  42. * <th width="25%">Property name</th>
  43. * <th width="25%">Type</th>
  44. * <th width="50%">Description</th>
  45. * </tr>
  46. *
  47. * <tr>
  48. * <td><code>smppapi.default_version</code></td>
  49. * <td>String</td>
  50. * <td>Set the default version that will be used for new Connections</td>
  51. * </tr>
  52. *
  53. * <tr>
  54. * <td><code>smppapi.default_alphabet</code></td>
  55. * <td>String</td>
  56. * <td>The class name of the default alphabet encoding to use. Must be
  57. * an implementation of <tt>org.mobicents.smpp.util.AlphabetEncoding</tt></td>
  58. * </tr>
  59. *
  60. * <tr>
  61. * <td><code>smppapi.lax_versions</code></td>
  62. * <td>Boolean</td>
  63. * <td>
  64. * Enable or disable interpreting interface_version values of
  65. * 0x00 thru 0x32 (inclusive) as SMPP version 3.3. The specification
  66. * is not entirely clear in its statement on whether this is allowed
  67. * or not.
  68. * </td>
  69. * </tr>
  70. *
  71. * <tr>
  72. * <td><code>smppapi.net.buffersize_in</code></td>
  73. * <td>Integer</td>
  74. * <td>Sets the size of the buffer, in bytes, used on the incoming
  75. * stream connection from the SMSC.</td>
  76. * </tr>
  77. *
  78. * <tr>
  79. * <td><code>smppapi.net.buffersize_out</code></td>
  80. * <td>Integer</td>
  81. * <td>Sets the size of the buffer, in bytes, used on the outgoing stream
  82. * connection to the SMSC.</td>
  83. * </tr>
  84. *
  85. * <tr>
  86. * <td><code>smppapi.net.autoflush</code></td>
  87. * <td>Boolean</td>
  88. * <td>By default, the {@link org.mobicents.protocols.smpp.net.SmscLink} class automatically
  89. * flushes the output stream after every packet written to the output stream. In
  90. * high-load environments, it may be better to turn this off and manually flush
  91. * the output stream only when required (after a short period of inactivity, for
  92. * example).</td>
  93. * </tr>
  94. *
  95. * <tr>
  96. * <td><code>smppapi.net.autoclose_snoop</code></td>
  97. * <td>Boolean</td>
  98. * <td>If snoop streams are set on the SMSC link object and this value is true
  99. * (the default), the snoop streams will be closed when the link is closed. If
  100. * false, the snoop streams will be flushed and left open when the link is
  101. * closed.</td>
  102. * </tr>
  103. *
  104. * <tr>
  105. * <td><code>smppapi.net.link_timeout</code></td>
  106. * <td>Long</td>
  107. * <td>Sets the timeout in milliseconds for network links. This value affects
  108. * how long network reads should block for but its exact interpretation is
  109. * link-implementation specific. For <code>TcpLink</code>, this value represents
  110. * the <code>SO_TIMEOUT</code> setting on the TCP/IP socket.</td>
  111. * </tr>
  112. *
  113. * <tr>
  114. * <td><code>smppapi.connection.bind_timeout</code></td>
  115. * <td>Long</td>
  116. * <td>The length of time, in milliseconds, to wait for a bind response packet
  117. * after sending a bind request. If a packet is not received within this time
  118. * period, the network connection is closed. A negative value or zero means wait
  119. * indefinitely.</td>
  120. * </tr>
  121. *
  122. * <tr>
  123. * <td><code>smppapi.connection.rcv_daemon.ioex_count</code></td>
  124. * <td>Integer</td>
  125. * <td>The number of I/O exceptions the receiver daemon will accept occurring
  126. * before exiting.</td>
  127. * </tr>
  128. *
  129. * <tr>
  130. * <td><code>smppapi.event.dispatcher</code></td>
  131. * <td>String</td>
  132. * <td>The name of a class, which implements
  133. * {@link org.mobicents.protocols.smpp.event.EventDispatcher}, which will be used as the default
  134. * event dispatcher for <code>Connection</code> objects.</td>
  135. * </tr>
  136. *
  137. * <tr>
  138. * <td><code>smppapi.event.threaded_dispatcher.pool_size</code></td>
  139. * <td>Integer</td>
  140. * <td>The size of the thread pool used by the
  141. * {@link org.mobicents.protocols.smpp.event.TaskExecutorEventDispatcher} class.</td>
  142. * </tr>
  143. *
  144. * <tr>
  145. * <td><code>smppapi.message.segment_size</code></td>
  146. * <td>Integer</td>
  147. * <td>The default segment size to use for concatenated short messages
  148. * using optional parameters.</td>
  149. * </tr>
  150. * </table>
  151. * @version $Id: APIConfig.java 477 2009-07-12 18:00:20Z orank $
  152. * @see APIConfigFactory
  153. * @see PropertiesAPIConfig
  154. */
  155. public interface APIConfig {
  156. /**
  157. * @see APIConfig
  158. */
  159. String DEFAULT_VERSION = "smppapi.default_version";
  160. /**
  161. * @see APIConfig
  162. */
  163. String DEFAULT_ALPHABET = "smppapi.default_alphabet";
  164. /**
  165. * @see APIConfig
  166. */
  167. String LAX_VERSIONS = "smppapi.lax_versions";
  168. /**
  169. * @see APIConfig
  170. */
  171. String LINK_BUFFERSIZE_IN = "smppapi.net.buffersize_in";
  172. /**
  173. * @see APIConfig
  174. */
  175. String LINK_BUFFERSIZE_OUT = "smppapi.net.buffersize_out";
  176. /**
  177. * @see APIConfig
  178. */
  179. String LINK_AUTO_FLUSH = "smppapi.net.autoflush";
  180. /**
  181. * @see APIConfig
  182. */
  183. String LINK_AUTOCLOSE_SNOOP = "smppapi.net.autoclose_snoop";
  184. /**
  185. * @see APIConfig
  186. */
  187. String LINK_TIMEOUT = "smppapi.net.link_timeout";
  188. /**
  189. * @see APIConfig
  190. */
  191. String TOO_MANY_IO_EXCEPTIONS = "smppapi.connection.rcv_daemon.ioex_count";
  192. /**
  193. * @see APIConfig
  194. */
  195. String EVENT_DISPATCHER_CLASS = "smppapi.event.dispatcher";
  196. /**
  197. * @see APIConfig
  198. */
  199. String EVENT_THREAD_POOL_SIZE =
  200. "smppapi.event.threaded_dispatcher.pool_size";
  201. /**
  202. * @see APIConfig
  203. */
  204. String BIND_TIMEOUT ="smppapi.connection.bind_timeout";
  205. /**
  206. * @see APIConfig
  207. */
  208. String SEGMENT_SIZE = "smppapi.message.segment_size";
  209. /**
  210. * Initialise this properties instance. The {@link APIConfigFactory}
  211. * will call this method once after it has instantiated the
  212. * configuration implementation so that any implementation-specific
  213. * actions can be carried out.
  214. */
  215. void initialise();
  216. /**
  217. * Cause the API properties to be reloaded. The properties will be re-read
  218. * from the same location as they were initially loaded from. If the
  219. * resource has disappeared or is no longer accessible, the properties will
  220. * not be loaded and <code>false</code> will be returned to the caller.
  221. * @return <tt>true</tt> if the properties were successfully reloaded,
  222. * <tt>false</tt> otherwise.
  223. */
  224. boolean reloadAPIConfig();
  225. /**
  226. * Get the value for a property.
  227. * @param property The name of the property to retrieve.
  228. * @return The value for <code>property</code>.
  229. * @throws PropertyNotFoundException if <code>property</code> is
  230. * not found in the configuration.
  231. */
  232. String getProperty(String property) throws PropertyNotFoundException;
  233. /**
  234. * Get the value for a property or return a default value if it is not set.
  235. * @param property The name of the property to retrieve.
  236. * @param defaultValue The value to return if <code>property</code> is not
  237. * set.
  238. * @return The value for <code>property</code>.
  239. */
  240. String getProperty(String property, String defaultValue);
  241. /**
  242. * Get the value of a property, parsed as a <code>short</code>. If the
  243. * property is not set, the default value is returned.
  244. * @param property The name of the property to retrieve the value for.
  245. * @param defaultValue The default value to return if the property is
  246. * not set.
  247. * @return The value for <code>property</code>.
  248. * @throws InvalidConfigurationException If the value cannot be parsed as
  249. * a <code>short</code>.
  250. */
  251. short getShort(String property, short defaultValue) throws InvalidConfigurationException;
  252. /**
  253. * Get the value for a property, parsed as a Java <code>short</code>.
  254. * @param property the name of the property to retrive.
  255. * @return The value of <tt>property</tt>.
  256. * @throws PropertyNotFoundException if <code>property</code> is not
  257. * found in the configuration.
  258. * @throws InvalidConfigurationException if the value is not a valid short.
  259. */
  260. short getShort(String property) throws InvalidConfigurationException, PropertyNotFoundException;
  261. /**
  262. * Get the value for a property, parsed as a Java <code>int</code>. If
  263. * the property is not found, the default value is returned.
  264. * @param property the name of the property to retrive.
  265. * @param defaultValue the value to return if the property does not exist.
  266. * @return The value of <tt>property</tt>.
  267. * @throws InvalidConfigurationException if the value is not a valid
  268. * integer.
  269. */
  270. int getInt(String property, int defaultValue) throws InvalidConfigurationException;
  271. /**
  272. * Get the value for a property, parsed as a Java <code>int</code>.
  273. * @param property the name of the property to retrive.
  274. * @return The value of <tt>property</tt>.
  275. * @throws PropertyNotFoundException if
  276. * <code>property</code> is not found in the configuration.
  277. * @throws InvalidConfigurationException if the value is not a valid
  278. * integer.
  279. */
  280. int getInt(String property) throws InvalidConfigurationException, PropertyNotFoundException;
  281. /**
  282. * Get the value for a property, parsed as a Java <code>long</code>. If
  283. * the property is not found, the default value is returned.
  284. * @param property the name of the property to retrieve.
  285. * @param defaultValue the value to return if the property does not exist.
  286. * @return The value of <tt>property</tt>.
  287. * @throws InvalidConfigurationException if the value is not a valid long.
  288. */
  289. long getLong(String property, long defaultValue) throws InvalidConfigurationException;
  290. /**
  291. * Get the value for a property, parsed as a Java <code>long</code>.
  292. * @param property the name of the property to retrive.
  293. * @return The value of <tt>property</tt>.
  294. * @throws PropertyNotFoundException if <code>property</code> is not
  295. * found in the configuration.
  296. * @throws InvalidConfigurationException if the value is not a valid long.
  297. */
  298. long getLong(String property) throws InvalidConfigurationException, PropertyNotFoundException;
  299. /**
  300. * Get a property as a boolean value. Any of 'on', 'yes' or 'true'
  301. * (irrelevant of case) will evaluate to <code>true</code>. Any of 'off',
  302. * 'no' or 'false' will evaluate to <code>false</code>. Boolean
  303. * parameters may also be specified as a number, where zero will equate to
  304. * <code>false</code> while non-zero will equate to <code>true</code>.
  305. * All other words will result in an InvalidConfigurationException being
  306. * thrown.
  307. * @param property the name of the property to look up.
  308. * @param defaultValue the value to return if the property does not exist.
  309. * @return The value of <tt>property</tt>.
  310. * @throws InvalidConfigurationException if the property has a
  311. * value that cannot be parsed or interpreted as boolean.
  312. */
  313. boolean getBoolean(String property, boolean defaultValue) throws InvalidConfigurationException;
  314. /**
  315. * Get a property as a boolean value. See the description of
  316. * {@link #getBoolean(String, boolean)} for details of how a boolean
  317. * value can be specified.
  318. * @param property The name of the property to retrieve.
  319. * @return The value of <tt>property</tt>.
  320. * @throws PropertyNotFoundException if <code>property</code> is not
  321. * found in the configuration.
  322. * @throws InvalidConfigurationException if the property has a value
  323. * that cannot be parsed or interpreted as boolean.
  324. */
  325. boolean getBoolean(String property) throws InvalidConfigurationException, PropertyNotFoundException;
  326. /**
  327. * Instantiate a new instance of a class whose class name is specified
  328. * in <tt>property</tt>.
  329. * @param <T> The expected type of the instantiated class.
  330. * @param property The name of a property whose value is the fully
  331. * qualified name of a class to instantiate.
  332. * @param type The expected type of the instantiated class. This may
  333. * specify a super-class or interface of the actually instantiated
  334. * class.
  335. * @return The new object instance.
  336. * @throws PropertyNotFoundException If <tt>property</tt> is not
  337. * found in the configuration.
  338. */
  339. <T> T getClassInstance(String property, Class<T> type);
  340. /**
  341. * Instantiate a new instance of a class whose class name is specified
  342. * in <tt>property</tt>, returning a default value if the property
  343. * is not set.
  344. * @param <T> The expected type of the instantiated class.
  345. * @param property The name of a property whose value is the fully
  346. * qualified name of a class to instantiate.
  347. * @param type The expected type of the instantiated class. This may
  348. * specify a super-class or interface of the actually instantiated
  349. * class.
  350. * @return The new object instance, or <tt>defaultValue</tt> if
  351. * <tt>property</tt> is not set.
  352. */
  353. <T> T getClassInstance(String property, Class<T> type, T defaultValue);
  354. /**
  355. * Determine if a property is set in the configuration.
  356. * @param property The name of the property to test.
  357. * @return <tt>true</tt> if the property is set, <tt>false</tt> if not.
  358. */
  359. boolean isSet(String property);
  360. }