// SMSLib for Java v3
// A Java API library for sending and receiving SMS via a GSM modem
// or other supported gateways.
// Web Site: http://www.smslib.org
//
// Copyright (C) 2002-2008, Thanasis Delenikas, Athens/GREECE.
// SMSLib is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.smslib;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;
/**
* This is main library class. Your primary interface with SMSLib is via methods
* defined in this class.
*/
public class Service
{
private static final String LOG4J_CONF = "smslib-log4j.properties";
private static final String LOG4J_CONF_XML = "smslib-log4j.xml";
private Logger logger;
private List gtwList;
private Router router;
private LoadBalancer loadBalancer;
private WatchDog watchDog;
/**
* Configuration settings.
*
* @see Settings
*/
public Settings S;
/**
* Default Service constructor. Will set SMSLib to use its own logger.
*/
public Service()
{
S = new Settings();
try
{
logger = Logger.getLogger("org.smslib");
logger.setLevel(S.DEBUG ? Level.ALL : Level.WARN);
Properties p = new Properties();
p = loadLoggerProps(LOG4J_CONF);
if (p != null) PropertyConfigurator.configure(p);
else
{
if (new File(LOG4J_CONF).exists()) PropertyConfigurator.configure(LOG4J_CONF);
else if (new File(LOG4J_CONF_XML).exists()) DOMConfigurator.configure(LOG4J_CONF_XML);
else BasicConfigurator.configure();
}
logger.info(Library.getLibraryDescription());
logger.info("Version: " + Library.getLibraryVersion());
logger.info("JRE Version: " + System.getProperty("java.version"));
logger.info("JRE Impl Version: " + System.getProperty("java.vm.version"));
logger.info("O/S: " + System.getProperty("os.name") + " / " + System.getProperty("os.arch") + " / " + System.getProperty("os.version"));
gtwList = new ArrayList();
setRouter(new Router(this));
setLoadBalancer(new RoundRobinLoadBalancer(this));
}
catch (Exception e)
{
logger.fatal(e);
}
}
/**
* Service constructor. Will set SMSLib to use the provided log4j logger.
*
* @param logger
* A ready log4j logger to use.
*/
public Service(Logger logger)
{
S = new Settings();
this.logger = logger;
logger.setLevel(S.DEBUG ? Level.ALL : Level.WARN);
logger.info(Library.getLibraryDescription());
logger.info("Version: " + Library.getLibraryVersion());
logger.info("JRE Version: " + System.getProperty("java.version"));
logger.info("JRE Impl Version: " + System.getProperty("java.vm.version"));
logger.info("O/S: " + System.getProperty("os.name") + " / " + System.getProperty("os.arch") + " / " + System.getProperty("os.version"));
gtwList = new ArrayList();
setRouter(new Router(this));
setLoadBalancer(new RoundRobinLoadBalancer(this));
}
private Properties loadLoggerProps(String filename)
{
Properties props = new Properties();
try
{
props.load(getClass().getResourceAsStream(filename));
}
catch (Exception ex)
{
return null;
}
Enumeration keys = props.keys();
while (keys.hasMoreElements())
{
String prop = (String) keys.nextElement();
String val = props.getProperty(prop);
props.setProperty(prop, val);
}
return props;
}
/**
* Returns the logger used by SMSLib.
*
* @return The logger in use.
*/
public Logger getLogger()
{
return logger;
}
/**
* Adds a gateway to the list of gateways managed by the Service class.
*
* @param gtw
* The gateway to be added.
* @see #getGatewayList()
*/
public void addGateway(AGateway gtw)
{
synchronized (gtwList)
{
gtw.setService(this);
gtwList.add(gtw);
}
}
/**
* Initializes all gateways. This should be the first call before you use
* the Service class for sending/receiving messages. The call will try to
* start all defined gateways.
*
* @throws SMSLibException
* No Gateways are defined.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
* @see #stopService()
*/
public synchronized void startService() throws SMSLibException, TimeoutException, GatewayException, IOException, InterruptedException
{
watchDog = new WatchDog();
synchronized (gtwList)
{
if (gtwList.size() == 0) throw new SMSLibException("No gateways are defined.");
for (int i = 0, n = gtwList.size(); i < n; i++)
((AGateway) gtwList.get(i)).startGateway();
}
}
/**
* Stops all gateways - does not remove them from Service's internal list.
* Once stopped, all SMSLib operations will fail. You need to start the
* gateways again before proceeding.
*
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
* @see #startService()
*/
public synchronized void stopService() throws TimeoutException, GatewayException, IOException, InterruptedException
{
if (watchDog != null)
{
watchDog.interrupt();
watchDog.join();
}
synchronized (gtwList)
{
for (int i = 0, n = gtwList.size(); i < n; i++)
((AGateway) gtwList.get(i)).stopGateway();
}
}
/**
* Reads inbound messages from ALL gateways with the Inbound attribute set.
* When successful, the message list will contain all messages read.
*
* @param msgList
* A (probably empty) list that will be populated with Inbound
* messages read.
* @param msgClass
* Filtering: Class of messages that need to be read.
* @return The number of messages read.
* @throws TimeoutException
* The gateway did not respond in a timely manner.
* @throws GatewayException
* A Gateway error occurred.
* @throws IOException
* An IO error occurred.
* @throws InterruptedException
* The call was interrupted.
* @see MessageClasses
*/
public int readMessages(List msgList, MessageClasses msgClass) throws TimeoutException, GatewayException, IOException, InterruptedException
{
synchronized (gtwList)
{
for (int i = 0, n = gtwList.size(); i < n; i++)
{
AGateway gtw = (AGateway) gtwList.get(i);
if (gtw.isInbound())
{
try
{
readMessages(msgList, msgClass, gtw);
}
catch (TimeoutException e)
{
logWarn("readMessages(): Gateway " + gtw.getGatewayId() + " does not respond, marking for restart.");
gtw.setGatewayStatus(GatewayStatuses.RESTART);
}
catch (IOException e)
{
logWar
没有合适的资源?快使用搜索试试~ 我知道了~
smslib-v3[1].2.2
共106个文件
java:77个
html:11个
sql:5个
2星 需积分: 9 7 下载量 140 浏览量
2008-05-08
18:21:03
上传
评论
收藏 178KB ZIP 举报
温馨提示
不错的发送短信的jar包
资源推荐
资源详情
资源评论
收起资源包目录
smslib-v3[1].2.2 (106个子文件)
CHANGELOG 16KB
SMSServer.conf 2KB
SMSSvr.conf 2KB
SerialModemDriver.diff 1017B
CommTest.diff 463B
package.html 378B
package.html 243B
package.html 154B
package.html 150B
package.html 121B
Introduction.html 71B
package.html 67B
package.html 64B
package.html 63B
package.html 51B
package.html 38B
Service.java 29KB
ModemGateway.java 26KB
AModemDriver.java 21KB
Xml.java 21KB
AGateway.java 18KB
OutboundMessage.java 17KB
SMSSvr.java 17KB
ClickatellHTTPGateway.java 14KB
GSMAlphabet.java 14KB
ATHandler.java 13KB
InboundMessage.java 10KB
SMSServer.java 10KB
Database.java 8KB
AInterface.java 8KB
Email.java 8KB
Jmx.java 8KB
BulkSmsHTTPGateway.java 8KB
Settings.java 7KB
SerialModemDriver.java 6KB
AATHandler.java 6KB
Message.java 6KB
CNMIDetector.java 6KB
ComVisionHTTPGateway.java 6KB
ReadMessages.java 6KB
TestGateway.java 5KB
StatusReportMessage.java 5KB
OutboundWapSIMessage.java 5KB
HTTPGateway.java 4KB
IPModemDriver.java 4KB
Router.java 4KB
GSMServiceHTTPGateway.java 4KB
TestXml.java 3KB
SendMessage.java 3KB
SendMessage.java 3KB
SerialModem.java 3KB
IPModem.java 3KB
CommTest.java 3KB
ATHandler_Ubinetics_GDC201.java 2KB
SimpleInboundFileLogger.java 2KB
FailureCauses.java 2KB
UnknownMessage.java 2KB
ClickatellHttp.java 2KB
NumberPoolRouter.java 2KB
MessageTypes.java 2KB
IOutboundMessageNotification.java 2KB
MessageEncodings.java 2KB
SerialModemGateway.java 2KB
Library.java 2KB
SendMessage.java 2KB
IInboundMessageNotification.java 2KB
DeliveryStatuses.java 2KB
ATHandler_SonyEricsson.java 2KB
IPModemGateway.java 2KB
LoadBalancer.java 2KB
BulkSmsRegions.java 2KB
RoundRobinLoadBalancer.java 2KB
AGateway.java 2KB
ATHandler_Wavecom.java 2KB
InterfaceTypes.java 1KB
Test.java 1KB
MessageStatuses.java 1KB
MessagePriorities.java 1KB
ATHandler_MultiTech.java 1KB
WapSISignals.java 1KB
AsyncEvents.java 1KB
MessageClasses.java 1KB
ModemTypes.java 1KB
MessageProtocols.java 1KB
ICallNotification.java 1KB
Queue.java 1KB
ATHandler_Siemens_MC35i.java 1KB
GatewayStatuses.java 1KB
SMSLibException.java 1KB
GatewayException.java 1KB
TimeoutException.java 1KB
ATHandler_Siemens_M55.java 1KB
ATHandler_Siemens_S55.java 1KB
LICENSE 10KB
SMSLib.mf 159B
smslib-log4j.properties 552B
build.properties 285B
smssvr_out.mssql.sql 4KB
smssvr_in.mssql.sql 2KB
smssvr_out.mysql.sql 730B
共 106 条
- 1
- 2
资源评论
- acd10242012-02-23运行错误,runtime error
wangpengdemon
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功