// 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;
private long startMillis;
/**
* 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);
initializeService();
}
/**
* Service constructor. Will set SMSLib to use the provided log4j logger.
*
* @param myLogger
* A ready Apache log4j object to use.
*/
public Service(org.apache.log4j.Logger myLogger)
{
this.S = new Settings();
this.logger = new Logger(myLogger);
initializeService();
}
protected void initializeService()
{
this.startMillis = System.currentTimeMillis();
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.setStatus(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;
if (e.e instanceof SMSLibException) throw (SMSLibException) e.e;
if (e.e instanceof IOException) throw (IOException) e.e;
if (e.e instanceof InterruptedException) throw (InterruptedException) e.e;
}
else
{
eList.clear();
gList.clear();
没有合适的资源?快使用搜索试试~ 我知道了~
smslib-v3.3.1-bin.zip_SMSLIB_smslib-3.3.0b2.jar_smslib-v3.3.0_sm
共502个文件
html:239个
class:141个
java:106个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 161 浏览量
2022-09-22
17:58:35
上传
评论
收藏 1.22MB ZIP 举报
温馨提示
java平台 smslib 短 信 开 发 包
资源推荐
资源详情
资源评论
收起资源包目录
smslib-v3.3.1-bin.zip_SMSLIB_smslib-3.3.0b2.jar_smslib-v3.3.0_sm (502个子文件)
CHANGELOG 25KB
ModemGateway.class 21KB
AModemDriver.class 17KB
Service.class 17KB
Xml.class 17KB
PduUtils.class 15KB
SMSServer.class 14KB
ClickatellHTTPGateway.class 13KB
Pdu.class 12KB
PduGenerator.class 12KB
ATHandler.class 12KB
Database.class 11KB
OutboundMessage.class 11KB
AGateway.class 11KB
Email.class 9KB
Http.class 8KB
InboundMessage.class 8KB
SerialModemDriver.class 8KB
BulkSmsHTTPGateway.class 7KB
PduParser.class 7KB
SerialPort.class 7KB
AModemDriver$AsyncNotifier.class 6KB
GSMAlphabet.class 6KB
HTTPGateway.class 6KB
AATHandler.class 5KB
ATHandler_Wavecom_WISMOQCDMA.class 5KB
Interface.class 5KB
Jmx.class 5KB
WapSiUserDataGenerator.class 5KB
CNMIDetector.class 5KB
OutboundWapSIMessage.class 5KB
TestGateway.class 5KB
ReadMessages.class 5KB
IPModemDriver.class 4KB
CommTest.class 4KB
AModemDriver$CharQueue.class 4KB
Service$WatchDog.class 4KB
AModemDriver$CNMIEmulatorProcessor.class 4KB
AModemDriver$AsyncMessageProcessor.class 4KB
CommPortIdentifier.class 4KB
ConcatInformationElement.class 4KB
SerialPortEvent.class 4KB
AGateway$QueueManager.class 3KB
Message.class 3KB
Logger.class 3KB
SmsSubmitPdu.class 3KB
WapSiPdu.class 3KB
Router.class 3KB
SendMessage.class 3KB
WapPushUtils.class 3KB
StatusReportMessage.class 3KB
SmsStatusReportPdu.class 3KB
AModemDriver$ModemReader.class 3KB
SendMessage.class 3KB
ReflectionHelper.class 3KB
Settings.class 3KB
SerialModem.class 3KB
AModemDriver$KeepAlive.class 3KB
IPModem.class 3KB
Jmx$SMSServerMethods.class 3KB
SimpleInboundFileLogger.class 3KB
SmsDeliveryPdu.class 2KB
SMSServer$InboundNotification.class 2KB
PduFactory.class 2KB
InboundBinaryMessage.class 2KB
SendMessage.class 2KB
PortInformationElement.class 2KB
OutboundBinaryMessage.class 2KB
ATHandler_Siemens_MC35i.class 2KB
SerialModemDriver$ThreadReader.class 2KB
ClickatellHttp.class 2KB
NumberPoolRouter.class 2KB
TestGateway$1.class 2KB
Xml$3.class 2KB
Database$1.class 2KB
IPModemDriver$Peeker.class 2KB
UnknownMessage.class 2KB
SMSServer$OutboundNotification.class 2KB
ClickatellHTTPGateway$KeepAlive.class 2KB
SMSServer$Shutdown.class 2KB
SMSServer$OutboundPollingThread.class 2KB
SMSServer$InboundPollingThread.class 2KB
SMSServer$CallNotification.class 2KB
InformationElementFactory.class 2KB
Service$1Starter.class 2KB
InformationElement.class 2KB
ATHandler_SonyEricsson_GC89.class 2KB
AGateway.class 2KB
ReadMessages$InboundNotification.class 2KB
OutboundMessage$FailureCauses.class 1KB
ReadMessages$GatewayStatusNotification.class 1KB
ExtStringBuilder.class 1KB
BulkSmsHTTPGateway$Regions.class 1KB
LeastLoadLoadBalancer.class 1KB
ATHandler_Wavecom.class 1KB
OutboundWapSIMessage$WapSISignals.class 1KB
StatusReportMessage$DeliveryStatuses.class 1KB
Interface$InterfaceTypes.class 1KB
SerialPort$SerialPortEventListenerHandler.class 1KB
ATHandler_Ubinetics_GDC201.class 1KB
共 502 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
Kinonoyomeo
- 粉丝: 74
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功