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

📄 agateway.java

📁 java平台 smslib 短 信 开 发 包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// 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.Collection;
import java.util.Comparator;
import java.util.concurrent.PriorityBlockingQueue;
import org.smslib.InboundMessage.MessageClasses;
import org.smslib.OutboundMessage.FailureCauses;
import org.smslib.OutboundMessage.MessageStatuses;
import org.smslib.StatusReportMessage.DeliveryStatuses;

/**
 * Abstract class representing a Gateway, i.e. an interface capable of sending
 * and/or receiving SMS messages.
 */
public abstract class AGateway
{
	/**
	 * Enumeration representing the operation protocols of a GSM modem.
	 */
	public enum Protocols
	{
		/**
		 * PDU protocol.
		 */
		PDU,
		/**
		 * TEXT protocol. <b>Warning</b>: the TEXT protocol is not yet fully
		 * supported.
		 */
		TEXT
	}

	public enum GatewayStatuses
	{
		STOPPED, RUNNING, FAILURE, RESTART
	}

	public enum AsyncEvents
	{
		DELETE, NOTHING, INBOUNDMESSAGE, INBOUNDSTATUSREPORTMESSAGE, INBOUNDCALL
	}

	public static class GatewayAttributes
	{
		public static final int SEND = 0x0001;

		public static final int RECEIVE = 0x0002;

		public static final int CUSTOMFROM = 0x0004;

		public static final int BIGMESSAGES = 0x0008;

		public static final int WAPSI = 0x0010;

		public static final int PORTADDRESSING = 0x0020;

		public static final int FLASHSMS = 0x0040;

		public static final int DELIVERYREPORTS = 0x0080;
	}

	private String gatewayId;

	private int attributes;

	private boolean inbound;

	private boolean outbound;

	private Service srv;

	private Protocols protocol;

	private IInboundMessageNotification inboundNotification;

	private IOutboundMessageNotification outboundNotification;

	private ICallNotification callNotification;

	private IGatewayStatusNotification statusNotification;

	private Statistics statistics;

	private String from;

	private int deliveryErrorCode;

	private Thread queueManagerThread;

	protected PriorityBlockingQueue<OutboundMessage> messageQueue;

	private GatewayStatuses status;

	private int restartCount;

	public AGateway(String id)
	{
		this.gatewayId = id;
		this.srv = null;
		this.inbound = false;
		this.outbound = false;
		this.attributes = 0;
		this.protocol = Protocols.PDU;
		this.inboundNotification = null;
		this.outboundNotification = null;
		this.callNotification = null;
		this.statusNotification = null;
		this.from = "";
		this.statistics = new Statistics();
		this.from = "";
		this.deliveryErrorCode = -1;
		this.status = GatewayStatuses.STOPPED;
		this.restartCount = 0;
		this.messageQueue = new PriorityBlockingQueue<OutboundMessage>(50, new Comparator<OutboundMessage>()
		{
			public int compare(OutboundMessage x, OutboundMessage y)
			{
				int comp = y.getPriority() - x.getPriority();
				if (comp == 0) comp = x.getDate().compareTo(y.getDate());
				return comp;
			}
		});
	}

	public void setAttributes(int myAttributes)
	{
		this.attributes = myAttributes;
	}

	public int getAttributes()
	{
		return this.attributes;
	}

	public Service getService()
	{
		return this.srv;
	}

	public void setService(Service mySrv)
	{
		this.srv = mySrv;
	}

	/**
	 * Returns true if the the gateway is set for inbound messaging.
	 * 
	 * @return True if this gateway is set for inbound messaging.
	 */
	public boolean isInbound()
	{
		return this.inbound;
	}

	/**
	 * Enables or disables the gateway for inbound messaging. The command is
	 * accepted only if the gateway supports inbound messaging.
	 * 
	 * @param value
	 *            True to enable the gateway for inbound messaging.
	 */
	public void setInbound(boolean value)
	{
		if ((this.attributes & GatewayAttributes.RECEIVE) != 0) this.inbound = value;
	}

	/**
	 * Returns true if the the gateway is set for outbound messaging.
	 * 
	 * @return True if this gateway is set for outbound messaging.
	 */
	public boolean isOutbound()
	{
		return this.outbound;
	}

	/**
	 * Enables or disables the gateway for outbound messaging. The command is
	 * accepted only if the gateway supports outbound messaging.
	 * 
	 * @param value
	 *            True to enable the gateway for outbound messaging.
	 */
	public void setOutbound(boolean value)
	{
		if ((this.attributes & GatewayAttributes.SEND) != 0) this.outbound = value;
	}

	/**
	 * Sets the communication protocol of the gateway. The call is applicable
	 * only for modem gateways, in other cases it is ignored.
	 * 
	 * @param myProtocoll
	 *            The protocol to be used.
	 * @see Protocols
	 * @see #getProtocol
	 */
	public void setProtocol(Protocols myProtocoll)
	{
		this.protocol = myProtocoll;
	}

	/**
	 * Returns the communication protocol current in use by the gateway.
	 * 
	 * @return The communication protocol.
	 * @see Protocols
	 * @see #setProtocol(Protocols)
	 */
	public Protocols getProtocol()
	{
		return this.protocol;
	}

	/**
	 * Returns the gateway id assigned to this gateway during initialization.
	 * 
	 * @return The gateway id.
	 */
	public String getGatewayId()
	{
		return this.gatewayId;
	}

	/**
	 * Returns the gateway status.
	 * 
	 * @return The gateway status
	 * @see GatewayStatuses
	 */
	public GatewayStatuses getStatus()
	{
		return this.status;
	}

	/**
	 * Sets the gateway status to a new value.
	 * 
	 * @param myStatus
	 *            The new gateway status.
	 * @see GatewayStatuses
	 */
	public void setStatus(GatewayStatuses myStatus)
	{
		if (getStatusNotification() != null) getStatusNotification().process(getGatewayId(), getStatus(), myStatus);
		if (getService().getGatewayStatusNotification() != null) getService().getGatewayStatusNotification().process(getGatewayId(), getStatus(), myStatus);
		this.status = myStatus;
	}

	/**
	 * Returns the notification method set for inbound messages. Returns null if
	 * no such method is set.
	 * 
	 * @deprecated As of release 3.3.0B4, replaced by {@link Service#getInboundNotification()}
	 */
	@Deprecated
	public IInboundMessageNotification getInboundNotification()
	{
		return this.inboundNotification;
	}

	/**
	 * Sets the inbound message notification method. The method must adhere to
	 * the IInboundMessageNotification interface. If set, SMSLib will call this
	 * method upon arrival of a new inbound message.
	 * 
	 * @deprecated As of release 3.3.0B4, replaced by {@link Service#setInboundNotification(IInboundMessageNotification)}
	 */
	@Deprecated
	public void setInboundNotification(IInboundMessageNotification myInboundNotification)
	{
		this.inboundNotification = myInboundNotification;
	}

	/**
	 * Returns the notification method set for outbound messages. Returns null
	 * if no such method is set.
	 * 
	 * @deprecated As of release 3.3.0B4, replaced by {@link Service#getOutboundNotification()}
	 */
	@Deprecated
	public IOutboundMessageNotification getOutboundNotification()
	{
		return this.outboundNotification;
	}

	/**
	 * Sets the outbound notification method. The method must adhere to the
	 * IOutboundMessageNotification interface. If set, SMSLib will call this
	 * method upon dispatch of a message through the queueing (asyncronous)
	 * calls.
	 * 
	 * @deprecated As of release 3.3.0B4, replaced by {@link Service#setOutboundNotification(IOutboundMessageNotification)}
	 */
	@Deprecated
	public void setOutboundNotification(IOutboundMessageNotification myOutboundNotification)
	{
		this.outboundNotification = myOutboundNotification;
	}

	/**
	 * Returns the call notification method. Returns null if no such method is
	 * set.
	 * 
	 * @deprecated As of release 3.3.0B4, replaced by {@link Service#getCallNotification()}
	 */
	@Deprecated
	public ICallNotification getCallNotification()
	{
		return this.callNotification;
	}

	/**
	 * Sets the call notification method. The method must adhere to the
	 * ICallNotification interface. If set, SMSLib will call this method upon
	 * detection of an inbound call.
	 * 
	 * @deprecated As of release 3.3.0B4, replaced by {@link Service#setCallNotification(ICallNotification)}
	 */
	@Deprecated
	public void setCallNotification(ICallNotification myCallNotification)
	{
		this.callNotification = myCallNotification;
	}

	/**
	 * Returns the gateway status notification method. Returns null if no such
	 * method has been set.
	 * 
	 * @deprecated As of release 3.3.0B4, replaced by {@link Service#getGatewayStatusNotification()}
	 */
	@Deprecated
	public IGatewayStatusNotification getStatusNotification()
	{
		return this.statusNotification;
	}

	/**
	 * Sets the gateway status notification method. The method must adhere to
	 * the IGatewayStatusNotification interface. If set, SMSLib will call this
	 * method upon every gateway status change.
	 * 
	 * @deprecated As of release 3.3.0B4, replaced by {@link Service#setGatewayStatusNotification(IGatewayStatusNotification)}
	 */

⌨️ 快捷键说明

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