Winner.java
资源名称:WAPpush.zip [点击查看]
上传用户:weisa_1
上传日期:2007-10-14
资源大小:287k
文件大小:2k
源码类别:
手机WAP编程
开发平台:
Java
- package push;
- import feedback.Feedback;
- import java.io.*;
- import java.util.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- /**
- * Selects winner
- *
- * @version 1.0
- * @since 1.0
- * @see Runnable
- */
- public final class Winner implements Runnable {
- private final PushInitiator pusher;
- private final String winnerUrl;
- private final String addressType;
- /**
- * Creates a new <code>Winner</code> instance.
- *
- * @param pusher a <code>PushInitiator</code> value
- * @param winnerUrl a <code>String</code> value
- */
- public Winner(PushInitiator pusher, String winnerUrl, String addressType) {
- this.pusher = pusher;
- this.winnerUrl = winnerUrl;
- this.addressType = addressType;
- }
- /**
- * A checker thread selects a winner from the users that has returned feedback. A winner (if any) is selected
- * during every cycle (of the while loop).
- */
- public void run() {
- String message = PushInitiator.createSiMessage(winnerUrl, null, null, null,
- null, "You are lucky! Check the message");
- 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();
- if (Feedback.winner().equals(name)) {
- String address = user.getAddress(addressType);
- if(address != null && !address.trim().equals("")) {
- try {
- pusher.sendPushMessage(address, addressType, message, PushService.SI_CONTENT_TYPE);
- } catch(Exception ee) {}
- }
- }
- }
- }
- catch(Exception e) { System.err.println(e); }
- try {
- Thread.sleep(120000); // 2 min
- }
- catch(InterruptedException e){}
- }
- }
- }