// 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.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import org.smslib.AGateway.GatewayStatuses;
import org.smslib.InboundMessage.MessageClasses;
import org.smslib.OutboundMessage.FailureCauses;
import org.smslib.OutboundMessage.MessageStatuses;
import org.smslib.balancing.LoadBalancer;
import org.smslib.balancing.RoundRobinLoadBalancer;
import org.smslib.helper.Logger;
import org.smslib.routing.Router;
/**
* This is main library class. Your primary interface with SMSLib is via methods
* defined in this class.
*/
public class Service
{
private Logger logger;
private List<AGateway> gatewayList;
private Router router;
private LoadBalancer loadBalancer;
private WatchDog watchDog;
private IInboundMessageNotification inboundNotification;
private IOutboundMessageNotification outboundNotification;
private ICallNotification callNotification;
private IGatewayStatusNotification gatewayStatusNotification;
private Queue<OutboundMessage> reorderMessageQueue;
/**
* Configuration settings.
*
* @see Settings
*/
public Settings S;
/**
* Default Service constructor. Will set SMSLib to use its own logger.
*/
public Service()
{
this.S = new Settings();
this.logger = new Logger(this.S);
listSystemInformation();
this.gatewayList = new ArrayList<AGateway>();
this.reorderMessageQueue = new PriorityQueue<OutboundMessage>(50, new Comparator<OutboundMessage>()
{
public int compare(OutboundMessage x, OutboundMessage y)
{
int comp = x.getPriority() - y.getPriority();
if (comp == 0) comp = x.getDate().compareTo(y.getDate());
return comp;
}
});
setRouter(new Router(this));
setLoadBalancer(new RoundRobinLoadBalancer(this));
}
/**
* Service constructor. Will set SMSLib to use the provided log4j logger.
*
* @param myLogger
* A ready log4j logger to use.
*/
public Service(Logger myLogger)
{
this.S = new Settings();
this.logger = new Logger(this.S);
listSystemInformation();
this.gatewayList = new ArrayList<AGateway>();
this.reorderMessageQueue = new PriorityQueue<OutboundMessage>(50, new Comparator<OutboundMessage>()
{
public int compare(OutboundMessage x, OutboundMessage y)
{
int comp = x.getPriority() - y.getPriority();
if (comp == 0) comp = x.getDate().compareTo(y.getDate());
return comp;
}
});
setRouter(new Router(this));
setLoadBalancer(new RoundRobinLoadBalancer(this));
}
private void listSystemInformation()
{
getLogger().logInfo(Library.getLibraryDescription(), null, null);
getLogger().logInfo("Version: " + Library.getLibraryVersion(), null, null);
getLogger().logInfo("JRE Version: " + System.getProperty("java.version"), null, null);
getLogger().logInfo("JRE Impl Version: " + System.getProperty("java.vm.version"), null, null);
getLogger().logInfo("O/S: " + System.getProperty("os.name") + " / " + System.getProperty("os.arch") + " / " + System.getProperty("os.version"), null, null);
}
/**
* Returns the logger used by SMSLib.
*
* @return The logger in use.
*/
public Logger getLogger()
{
return this.logger;
}
/**
* Adds a gateway to the list of gateways managed by the Service class.
*
* @param gateway
* The gateway to be added.
* @see #getGateways()
*/
public void addGateway(AGateway gateway)
{
synchronized (getGateways())
{
gateway.setService(this);
getGateways().add(gateway);
}
}
/**
* 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
{
startService(true);
}
/**
* 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 or some of the defined gateways, depending on the parameter.
*
* @param startAll
* True if it is imperative that all defined gateways start
* without errors. False if some gateways are allowed to fail
* during startup.
* @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(boolean startAll) throws SMSLibException, TimeoutException, GatewayException, IOException, InterruptedException
{
class ExceptionPair
{
public Throwable e;
public AGateway src;
}
class Starter extends Thread
{
AGateway gateway;
List<ExceptionPair> eList;
List<AGateway> gList;
public Starter(AGateway myGateway, List<ExceptionPair> myEList, List<AGateway> myGList)
{
this.gateway = myGateway;
this.eList = myEList;
this.gList = myGList;
}
@Override
public void run()
{
try
{
this.gateway.startGateway();
this.gList.add(this.gateway);
}
catch (Exception e)
{
ExceptionPair exc = new ExceptionPair();
exc.e = e;
exc.src = this.gateway;
this.eList.add(exc);
}
}
}
this.watchDog = new WatchDog();
if (this.S.CONCURRENT_GATEWAY_START)
{
List<ExceptionPair> eList;
List<AGateway> gList;
eList = new LinkedList<ExceptionPair>();
gList = new LinkedList<AGateway>();
synchronized (getGateways())
{
if (getGateways().size() == 0) throw new SMSLibException("No gateways are defined.");
for (AGateway gateway : getGateways())
new Starter(gateway, eList, gList).start();
while ((gList.size() != getGateways().size()) && (eList.size() == 0))
Thread.sleep(1000);
for (ExceptionPair e : eList)
e.src.setGatewayStatus(GatewayStatuses.RESTART);
if (startAll)
{
if (eList.size() != 0)
{
ExceptionPair e = eList.get(0);
if (e.e instanceof TimeoutException) throw (TimeoutException) e.e;
if (e.e instanceof GatewayException) throw (GatewayException) e.e;
没有合适的资源?快使用搜索试试~ 我知道了~
comm(所需的smslib包)
共497个文件
html:235个
class:141个
java:106个
需积分: 10 33 下载量 105 浏览量
2008-10-04
16:32:37
上传
评论
收藏 1.15MB ZIP 举报
温馨提示
这是必须的,否则无法运行您的程序 这是有关java开发发短信程序所需的东东
资源推荐
资源详情
资源评论
收起资源包目录
comm(所需的smslib包) (497个子文件)
CHANGELOG 23KB
ModemGateway.class 18KB
Xml.class 16KB
Service.class 16KB
PduUtils.class 14KB
SMSServer.class 13KB
AModemDriver.class 12KB
Pdu.class 12KB
ClickatellHTTPGateway.class 12KB
PduGenerator.class 12KB
ATHandler.class 11KB
OutboundMessage.class 11KB
Database.class 10KB
AGateway.class 10KB
Email.class 9KB
InboundMessage.class 7KB
BulkSmsHTTPGateway.class 7KB
Http.class 7KB
PduParser.class 7KB
SerialPort.class 6KB
SerialModemDriver.class 6KB
AModemDriver$AsyncNotifier.class 5KB
HTTPGateway.class 5KB
GSMAlphabet.class 5KB
AATHandler.class 5KB
ATHandler_Wavecom_WISMOQCDMA.class 5KB
Jmx.class 5KB
WapSiUserDataGenerator.class 5KB
CNMIDetector.class 5KB
OutboundWapSIMessage.class 5KB
TestGateway.class 5KB
IPModemDriver.class 4KB
ReadMessages.class 4KB
CommTest.class 4KB
AModemDriver$CharQueue.class 4KB
AInterface.class 4KB
CommPortIdentifier.class 4KB
Service$WatchDog.class 4KB
ConcatInformationElement.class 4KB
AModemDriver$AsyncMessageProcessor.class 4KB
SerialPortEvent.class 4KB
AGateway$QueueManager.class 3KB
Message.class 3KB
Router.class 3KB
SmsSubmitPdu.class 3KB
WapSiPdu.class 3KB
WapPushUtils.class 3KB
SendMessage.class 3KB
StatusReportMessage.class 3KB
SimpleInboundFileLogger.class 3KB
SmsStatusReportPdu.class 3KB
SendMessage.class 3KB
ReflectionHelper.class 3KB
Settings.class 3KB
SerialModem.class 3KB
IPModem.class 2KB
AModemDriver$ModemReader.class 2KB
Jmx$SMSServerMethods.class 2KB
SmsDeliveryPdu.class 2KB
Logger.class 2KB
AModemDriver$KeepAlive.class 2KB
SMSServer$InboundNotification.class 2KB
InboundBinaryMessage.class 2KB
PduFactory.class 2KB
SendMessage.class 2KB
PortInformationElement.class 2KB
OutboundBinaryMessage.class 2KB
ATHandler_Siemens_MC35i.class 2KB
SerialModemDriver$ThreadReader.class 2KB
NumberPoolRouter.class 2KB
ClickatellHttp.class 2KB
TestGateway$1.class 2KB
IPModemDriver$Peeker.class 2KB
Xml$3.class 2KB
UnknownMessage.class 2KB
Database$1.class 2KB
SMSServer$OutboundNotification.class 2KB
SMSServer$Shutdown.class 2KB
ClickatellHTTPGateway$KeepAlive.class 2KB
SMSServer$OutboundPollingThread.class 2KB
InformationElementFactory.class 2KB
SMSServer$InboundPollingThread.class 2KB
Service$1Starter.class 2KB
InformationElement.class 2KB
SMSServer$CallNotification.class 2KB
ATHandler_SonyEricsson_GC89.class 1KB
AGateway.class 1KB
ReadMessages$InboundNotification.class 1KB
OutboundMessage$FailureCauses.class 1KB
ReadMessages$GatewayStatusNotification.class 1KB
BulkSmsHTTPGateway$Regions.class 1KB
ExtStringBuilder.class 1KB
ATHandler_Wavecom.class 1KB
LeastLoadLoadBalancer.class 1KB
OutboundWapSIMessage$WapSISignals.class 1KB
StatusReportMessage$DeliveryStatuses.class 1KB
SerialPort$SerialPortEventListenerHandler.class 1KB
ATHandler_Ubinetics_GDC201.class 1KB
AGateway$AsyncEvents.class 1KB
AModemDriver$AsyncNotifier$Event.class 1KB
共 497 条
- 1
- 2
- 3
- 4
- 5
资源评论
yywusuowei
- 粉丝: 2
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 5G网络基础培训课件.zip
- 2024-spring-HIT-CS-大作业
- yolo目标检测项目实验
- downloadFile-1.hc
- C++课程设计:基于Qt的航班信息管理系统
- ADS7822UVerilog驱动,前面传的有点问题
- 基于python的高性能爬虫程序,使用了多线程+缓存+xpath实现的,这里以彼-岸图库为例,实现,仅用于学习交流
- 中分辨率成像光谱仪(MODIS)烧毁面积产品信息MODIS-C6-BA-User-Guide-1.2.pdf
- Screenshot_20240427_172613_com.huawei.browser.jpg
- 关于学习Python的相关资源网站链接及相关介绍.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功