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

📄 pushservice.java

📁 wap push功能程序 WAP开发网 : http://www.wapkf.com
💻 JAVA
字号:
package push;import members.Members;import java.util.Vector;import java.util.StringTokenizer;/** * Handling of user selected push services * * @version 1.0 * @since 1.0 * @see Runnable */public final class PushService implements Runnable {    private final PushInitiator pusher;    private final String serviceContextPath;    /**     * interval in hours between Push message submissions     */    private final int interval;    private final String addressType;    public static final String SI_CONTENT_TYPE = "text/vnd.wap.si";    /**     * Creates a new <code>PushService</code> instance.     *     * @param pusher a <code>PushInitiator</code> value     * @param serviceContextPath a <code>String</code> value     * @param interval an <code>int</code> value; in hours     */    public PushService(PushInitiator pusher, String serviceContextPath, String addressType, int interval) {	this.pusher = pusher;	this.serviceContextPath = serviceContextPath;	this.interval = interval; 	this.addressType = addressType;    }    /**     * A push service checker thread sends push messages related to ordered services     */    public void run() {	while(true){	    try {		Vector users = User.getUsersOnline();		for(int i=0; i<users.size(); i++) {		    User user = (User)users.get(i);		    String name = user.getName();		    String pushServices = user.getPushServices();		    /* Check if the user has selected push services. If so, then generate 		       and send (if not yet sent within a time interval) a push message! */		    if (pushServices != null){			StringTokenizer st = new StringTokenizer(pushServices, ";");			while (st.hasMoreTokens()){			    int serviceId = Integer.parseInt(st.nextToken());			    Object pushService = Members.getPushService(serviceId);			    String serviceName =  ((String[])pushService)[0];			    String serviceUrl =  ((String[])pushService)[1];			    Object serviceObject = user.getProperty(serviceName); 			    if(serviceObject != null) {				if((System.currentTimeMillis() - ((Long)serviceObject).longValue()) > 				   interval*1000*60*60)				    /* If there are more hours than specified by the interval variable 				       from the previous submission, the service message is ready to				       be sent again.*/				    serviceObject = null;			    }			    if (serviceObject == null) {				String url = serviceContextPath + serviceUrl;				String message = PushInitiator.createSiMessage(url, null, null, null,									       null, serviceName);				String address = user.getAddress(addressType);				System.out.println(message);				System.out.println("client Address = " + address);				if(address != null && !address.trim().equals("")) {				    try {				   					pusher.sendPushMessage(address, addressType, message, SI_CONTENT_TYPE);					user.setProperty(serviceName, new Long(System.currentTimeMillis()));				    }				    catch(Exception ee) {					System.err.println("Error in sending push message!");				    }				}			    }			}		    }		}	    }	    catch(Exception e) { e.printStackTrace(); }	    try {		Thread.sleep(10000); // 10 s	    } catch(InterruptedException e){}	}    }}

⌨️ 快捷键说明

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