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

📄 service.java

📁 发送短信 接收短信 多种接口com/net/modem 开发库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	public int getOutboundMessageCount(AGateway gateway)
	{
		return (gateway != null ? gateway.getOutboundMessageCount() : -1);
	}

	/**
	 * Returns the total number of messages received by all gateways.
	 * 
	 * @return The number of received messages.
	 */
	public int getInboundMessageCount()
	{
		int total = 0;
		for (AGateway gateway : getGateways())
			total += gateway.getInboundMessageCount();
		return total;
	}

	/**
	 * Returns the total number of messages sent via all gateways.
	 * 
	 * @return The number of sent messages.
	 */
	public int getOutboundMessageCount()
	{
		int total = 0;
		for (AGateway gateway : getGateways())
			total += gateway.getOutboundMessageCount();
		return total;
	}

	/**
	 * Find and return a gateway by its ID.
	 * 
	 * @param gatewayId
	 *            The ID of gateway to find.
	 * @return Gateway object bearing given name, or NULL if not found.
	 */
	public AGateway findGateway(String gatewayId)
	{
		for (AGateway gateway : getGateways())
			if (gateway.getGatewayId().equals(gatewayId)) return gateway;
		return null;
	}

	/**
	 * Returns the list of defined gateways.
	 * 
	 * @return The list of gateways.
	 */
	public Collection<AGateway> getGateways()
	{
		return gatewayList;
	}

	/**
	 * .NET bridge method.
	 */
	public AGateway[] getGatewaysNET()
	{
		return getGateways().toArray(new AGateway[0]);
	}

	/**
	 * Returns the active Load Balancer class.
	 * 
	 * @return The active LoadBalancer class.
	 * @see LoadBalancer
	 */
	public LoadBalancer getLoadBalancer()
	{
		return loadBalancer;
	}

	/**
	 * Sets a new Load Balancer.
	 * 
	 * @param loadBalancer
	 *            The Load Balancer that will take effect.
	 * @see LoadBalancer
	 */
	public void setLoadBalancer(LoadBalancer loadBalancer)
	{
		this.loadBalancer = loadBalancer;
	}

	/**
	 * Returns the active Router class.
	 * 
	 * @return The active Router class.
	 * @see Router
	 */
	public Router getRouter()
	{
		return router;
	}

	/**
	 * Sets a new Router.
	 * 
	 * @param router
	 *            The Router that will take effect.
	 * @see Router
	 */
	public void setRouter(Router router)
	{
		this.router = router;
	}

	/**
	 * Find best suitable gateway to send specific message through Router and
	 * Load Balancer.
	 * 
	 * @param msg
	 *            Message to be routed
	 * @return Reference to gateway or <code>null</code> if no suitable gateway
	 *         is found.
	 */
	synchronized AGateway routeMessage(OutboundMessage msg)
	{
		return getRouter().route(msg);
	}

	/**
	 * Returns the notification method set for inbound messages. Returns null if
	 * no such method is set.
	 * 
	 * @return The notification method.
	 * @see #setInboundNotification(IInboundMessageNotification)
	 */
	public IInboundMessageNotification getInboundNotification()
	{
		return 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.
	 * 
	 * @param inboundNotification
	 *            The method to be called.
	 * @see #getInboundNotification()
	 * @see IInboundMessageNotification
	 */
	public void setInboundNotification(IInboundMessageNotification inboundNotification)
	{
		this.inboundNotification = inboundNotification;
	}

	/**
	 * Returns the notification method set for outbound messages. Returns null
	 * if no such method is set.
	 * 
	 * @return The notification method.
	 * @see #setOutboundNotification(IOutboundMessageNotification)
	 */
	public IOutboundMessageNotification getOutboundNotification()
	{
		return 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.
	 * 
	 * @param outboundNotification
	 * @see #getOutboundNotification()
	 * @see IOutboundMessageNotification
	 */
	public void setOutboundNotification(IOutboundMessageNotification outboundNotification)
	{
		this.outboundNotification = outboundNotification;
	}

	/**
	 * Returns the call notification method. Returns null if no such method is
	 * set.
	 * 
	 * @return The notification method.
	 * @see #setCallNotification(ICallNotification)
	 */
	public ICallNotification getCallNotification()
	{
		return 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.
	 * 
	 * @param callNotification
	 * @see #getCallNotification()
	 * @see ICallNotification
	 */
	public void setCallNotification(ICallNotification callNotification)
	{
		this.callNotification = callNotification;
	}

	/**
	 * Returns the gateway status notification method. Returns null if no such
	 * method has been set.
	 * 
	 * @return The notification method.
	 * @see #setGatewayStatusNotification(IGatewayStatusNotification)
	 */
	public IGatewayStatusNotification getGatewayStatusNotification()
	{
		return gatewayStatusNotification;
	}

	/**
	 * 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.
	 * 
	 * @param gatewayStatusNotification
	 * @see #getGatewayStatusNotification()
	 * @see IGatewayStatusNotification
	 */
	public void setGatewayStatusNotification(IGatewayStatusNotification gatewayStatusNotification)
	{
		this.gatewayStatusNotification = gatewayStatusNotification;
	}

	/**
	 * Returns the notification method set for Queue sending operation. Returns
	 * null if no such method is set.
	 * 
	 * @return The notification method.
	 * @see #setQueueSendingNotification(IQueueSendingNotification)
	 */
	public IQueueSendingNotification getQueueSendingNotification()
	{
		return queueSendingNotification;
	}

	/**
	 * Sets the Queue sending notification method. The method must adhere to the
	 * IQueueSendingNotification interface. If set, SMSLib will call this
	 * method upon dispatch of a message through the queueing (asyncronous)
	 * calls.
	 * 
	 * @param queueSendingNotification
	 * @see #getQueueSendingNotification()
	 * @see IQueueSendingNotification
	 */
	public void setQueueSendingNotification(IQueueSendingNotification queueSendingNotification)
	{
		this.queueSendingNotification = queueSendingNotification;
	}

	public long getStartMillis()
	{
		return startMillis;
	}

	public Scheduler getScheduler()
	{
		return scheduler;
	}

	void setSettings(Settings settings)
	{
		this.S = settings;
	}

	public ServiceStatus getServiceStatus()
	{
		return serviceStatus;
	}

	void setServiceStatus(ServiceStatus serviceStatus)
	{
		this.serviceStatus = serviceStatus;
	}

	/**
	 * Returns the Settings object, holding SMSLib run-time values.
	 * 
	 * @return The Settings object.
	 * @see Settings
	 */
	public Settings getSettings()
	{
		return S;
	}

	/**
	 * Creates a destination group. A group can hold an unlimited number of
	 * recipients. Sending a message to a predefined group expands and sends the
	 * message to all numbers defined by the group. A group is valid for as long
	 * as this instance of SMSLib is active.
	 * 
	 * @param groupName
	 *            The group name.
	 * @return True if the group creation succeded.
	 * @see #removeGroup(String)
	 */
	public boolean createGroup(String groupName)
	{
		groups.add(new Group(groupName));
		return true;
	}

	/**
	 * Removes a group.
	 * 
	 * @param groupName
	 *            The name of the group to be removed.
	 * @return True if the removal was a success.
	 * @see #createGroup(String)
	 */
	public boolean removeGroup(String groupName)
	{
		for (Group a : groups)
		{
			if (a.getName().equalsIgnoreCase(groupName))
			{
				a.clear();
				groups.remove(a);
				return true;
			}
		}
		return false;
	}

	/**
	 * Expands a group to its recipient numbers.
	 * 
	 * @param groupName
	 *            The group name to be expanded.
	 * @return A list of the numbers that this group represents. If the group is
	 *         not defined, an empty list is returned.
	 * @see #addToGroup(String, String)
	 * @see #removeFromGroup(String, String)
	 */
	public ArrayList<String> expandGroup(String groupName)
	{
		for (Group a : groups)
		{
			if (a.getName().equalsIgnoreCase(groupName)) { return new ArrayList<String>(a.getNumbers()); }
		}
		return new ArrayList<String>();
	}

	/**
	 * Adds a number to the specified group.
	 * 
	 * @param groupName
	 *            The group to which the number is to be added.
	 * @param number
	 *            The number to add.
	 * @return True if the number is added. False if the group is not found.
	 * @see #createGroup(String)
	 * @see #removeFromGroup(String, String)
	 */
	public boolean addToGroup(String groupName, String number)
	{
		for (Group a : groups)
		{
			if (a.getName().equalsIgnoreCase(groupName))
			{
				a.addNumber(number);
				return true;
			}
		}
		return false;
	}

	/**
	 * Removes a number from the specified group.
	 * 
	 * @param groupName
	 *            The group from which the number is to be removed.
	 * @param number
	 *            The number to remove.
	 * @return True if the number was removed. False if the group or the number
	 *         is not found.
	 * @see #removeGroup(String)
	 * @see #addToGroup(String, String)
	 */
	public boolean removeFromGroup(String groupName, String number)
	{
		for (Group a : groups)
		{
			if (a.getName().equalsIgnoreCase(groupName)) { return a.removeNumber(number); }
		}
		return false;
	}

	void setQueueManager(QueueManager queueManager)
	{
		this.queueManager = queueManager;
	}

	public QueueManager getQueueManager()
	{
		return queueManager;
	}

	public KeyManager getKeyManager()
	{
		return keyManager;
	}

	WatchDog getWatchDog()
	{
		return watchDog;
	}

	void setWatchDog(WatchDog watchDog)
	{
		this.watchDog = watchDog;
	}

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

		public void process()
		{
			if (getServiceStatus() == ServiceStatus.STOPPED) return;
			try
			{
				for (AGateway gateway : getGateways())
				{
					if (gateway.getStatus() == GatewayStatuses.RESTART)
					{
						getLogger().logWarn("WatchDog: Gateway: " + gateway.getGatewayId() + " restarting.", null, null);
						try
						{
							gateway.stopGateway();
							gateway.setStatus(GatewayStatuses.RESTART);
						}
						catch (Exception e)
						{
							getLogger().logWarn("WatchDog: error while shutting down Gateway: " + gateway.getGatewayId(), e, null);
						}
						try
						{
							gateway.startGateway();
						}
						catch (Exception e)
						{
							getLogger().logError("WatchDog: error while starting Gateway: " + gateway.getGatewayId(), e, null);
						}
					}
				}
			}
			catch (Exception e)
			{
				getLogger().logError("WatchDog error. ", e, null);
			}
		}
	}

	public static void main(String[] args)
	{
		System.out.println(Library.getLibraryDescription());
		System.out.println("\nSMSLib API Version: " + Library.getLibraryVersion());
	}
}

⌨️ 快捷键说明

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