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

📄 agateway.java

📁 发送短信 接收短信 多种接口com/net/modem 开发库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @return The originator string.
	 * @see #setFrom(String)
	 */
	public String getFrom()
	{
		return this.from;
	}

	/**
	 * Sets the string that will appear on recipient's phone as the originator.
	 * Not all gateways support this.
	 * 
	 * @param myFrom
	 *            The originator string.
	 * @see #getFrom()
	 */
	public void setFrom(String myFrom)
	{
		this.from = myFrom;
	}

	public void startGateway() throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		setStatus(GatewayStatuses.STARTING);
		this.queueManager = new QueueManager("QueueManager [" + this.gatewayId + "]", getService());
		getService().getScheduler().scheduleWithFixedDelay(this.queueManager, getQueueSchedulingInterval(), getQueueSchedulingInterval(), TimeUnit.MILLISECONDS);
		this.queueManager.enable();
		this.restartCount++;
		setStatus(GatewayStatuses.STARTED);
	}

	public void stopGateway() throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		setStatus(GatewayStatuses.STOPPING);
		if (this.queueManager != null)
		{
			getService().getScheduler().remove(this.queueManager);
			this.queueManager = null;
		}
		setStatus(GatewayStatuses.STOPPED);
	}

	public void readMessages(Collection<InboundMessage> msgList, MessageClasses msgClass) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		throw new GatewayException("Feature not supported.");
	}

	public InboundMessage readMessage(String memLoc, int memIndex) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		throw new GatewayException("Feature not supported.");
	}

	public boolean sendMessage(OutboundMessage msg) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		throw new GatewayException("Feature not supported.");
	}

	public int sendMessages(Collection<OutboundMessage> msgList) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		int cnt = 0;
		for (OutboundMessage msg : msgList)
			if (sendMessage(msg)) cnt++;
		return cnt;
	}

	public boolean deleteMessage(InboundMessage msg) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		throw new GatewayException("Feature not supported.");
	}

	/**
	 * Queries the gateway for remaining credit.
	 * 
	 * @return Remaining credit.
	 * @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.
	 */
	public float queryBalance() throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		throw new GatewayException("Feature not supported.");
	}

	/**
	 * Queries the gateway to see if a specific message and its recipient are
	 * covered. The given message is not sent out - it is just tested.
	 * 
	 * @param msg
	 *            The message to test.
	 * @return True is the recipient is covered by the network.
	 * @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.
	 */
	public boolean queryCoverage(OutboundMessage msg) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		throw new GatewayException("Feature not supported.");
	}

	/**
	 * Query the gateway for message delivery status.
	 * 
	 * @param msg
	 *            The OutboundMessage object to be checked.
	 * @return The delivery status. This is interpreted and mapped to the
	 *         standard SMSLib status codes. For detailed information, check
	 *         method getDeliveryErrorCode().
	 * @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 DeliveryStatuses
	 * @see #getDeliveryErrorCode()
	 */
	public DeliveryStatuses queryMessage(OutboundMessage msg) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		return queryMessage(msg.getRefNo());
	}

	/**
	 * Query the gateway for message delivery status.
	 * 
	 * @param refNo
	 *            The reference number of a previously sent message to be
	 *            checked.
	 * @return The delivery status. This is interpreted and mapped to the
	 *         standard SMSLib status codes. For detailed information, check
	 *         method getDeliveryErrorCode().
	 * @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 DeliveryStatuses
	 * @see #getDeliveryErrorCode()
	 */
	public DeliveryStatuses queryMessage(String refNo) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		throw new GatewayException("Feature not supported.");
	}

	public int readPhonebook(Phonebook phonebook) throws TimeoutException, GatewayException, IOException, InterruptedException
	{
		throw new GatewayException("Feature not supported.");
	}

	/**
	 * Returns the gateway-specific error code from the last queryMessage()
	 * call. Note that each call to queryMessage() resets this error.
	 * 
	 * @return The error code - actual values depend on gateway used.
	 * @see #queryMessage(OutboundMessage)
	 */
	public int getDeliveryErrorCode()
	{
		return this.deliveryErrorCode;
	}

	public void setDeliveryErrorCode(int error)
	{
		this.deliveryErrorCode = error;
	}

	boolean isCapableOf(int att)
	{
		return ((att & this.attributes) == att);
	}

	boolean conformsTo(int attrib, boolean required)
	{
		if (required && !isCapableOf(attrib)) return false;
		return true;
	}

	static class Statistics
	{
		public int inbound;

		public int outbound;

		public Statistics()
		{
			this.inbound = 0;
			this.outbound = 0;
		}
	}

	public int getRestartCount()
	{
		return this.restartCount;
	}

	private class QueueManager extends ASchedulerTask
	{
		public QueueManager(String myName, Service myService)
		{
			super(myName, myService);
		}

		public void process()
		{
			OutboundMessage msg = null;
			try
			{
				if (getStatus() == GatewayStatuses.STARTED)
				{
					msg = getService().getQueueManager().getGatewayQueue(getGatewayId()).poll();
					if (msg != null)
					{
						if (getService().getQueueSendingNotification() != null) getService().getQueueSendingNotification().process(getGatewayId(), msg);
						if (!sendMessage(msg))
						{
							if (msg.getRetryCount() < getService().getSettings().QUEUE_RETRIES)
							{
								getService().getLogger().logInfo("Reinserting message to queue.", null, getGatewayId());
								msg.incrementRetryCount();
								getService().getQueueManager().queueMessage(msg);
							}
							else
							{
								getService().getLogger().logWarn("Maximum number of queue retries exceeded, message lost.", null, getGatewayId());
								msg.setFailureCause(FailureCauses.UNKNOWN);
								if (getService().getOutboundNotification() != null) getService().getOutboundNotification().process(getGatewayId(), msg);
							}
						}
						else
						{
							if (getService().getOutboundNotification() != null) getService().getOutboundNotification().process(getGatewayId(), msg);
						}
					}
				}
			}
			catch (InterruptedException e)
			{
				if ((msg != null) && (msg.getMessageStatus() != MessageStatuses.SENT)) getService().getQueueManager().queueMessage(msg);
				getService().getLogger().logInfo("QueueManager interrupted.", e, getGatewayId());
			}
			catch (Exception e)
			{
				getService().getLogger().logWarn("Queue exception, marking gateway for reset.", e, getGatewayId());
				setStatus(GatewayStatuses.RESTART);
				try
				{
					if ((msg != null) && (msg.getMessageStatus() != MessageStatuses.SENT)) getService().getQueueManager().queueMessage(msg);
				}
				catch (Exception e1)
				{
					getService().getLogger().logError("Fatal error during restart of the queue.", e1, getGatewayId());
				}
			}
		}
	}

	/**
	 * Returns the Gateway Queue sending internal (in milliseconds). Should be
	 * defined in every actual Gateway implementation.
	 * 
	 * @return The scheduling interval (in milliseconds).
	 */
	public abstract int getQueueSchedulingInterval();
}

⌨️ 快捷键说明

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