diff src/alice/topology/manager/keeparive/PingScheduler.java @ 309:797267843126

Refactor
author sugi
date Tue, 26 Nov 2013 15:33:29 +0900
parents a8255a831ade
children f1cd920ea913
line wrap: on
line diff
--- a/src/alice/topology/manager/keeparive/PingScheduler.java	Tue Nov 19 17:39:44 2013 +0900
+++ b/src/alice/topology/manager/keeparive/PingScheduler.java	Tue Nov 26 15:33:29 2013 +0900
@@ -1,18 +1,47 @@
 package alice.topology.manager.keeparive;
 
-import java.util.LinkedList;
 import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
 
 public class PingScheduler extends CodeSegment{
-	public PingSchedList plist = new PingSchedList(); 
+	static class SingletonHolder {
+		private static PingScheduler Instance = new PingScheduler();		
+	}
+	public static PingScheduler getInstance(){
+		return SingletonHolder.Instance;
+	}
+	private Receiver info = ids.create(CommandType.TAKE);
+
+	public void setKey(){
+		info.setKey("_WAITINGLIST");
+	}
+	
 	private TaskInfo nowTask;
-
 	private boolean interruptFlag = false;
 
-	private long INTERVAL = 60 * 1000;
 	private long time = 0;
 	private long postponeTime = 0;
-
+	@Override
+	public synchronized void run() {
+		WaitingList list = info.asClass(WaitingList.class);
+		try {
+			nowTask = list.getTaskList().pollFirst();
+			ods.update("_WAITINGLIST", list);
+			time = System.currentTimeMillis();
+			if (nowTask.getSleepTime()!=0)
+				this.wait(nowTask.getSleepTime());
+			if (interruptFlag){				
+				interruptFlag = false;
+			} else {
+				ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey());
+			}
+		} catch (InterruptedException e) {		
+		}
+		PingScheduler.getInstance().setKey();
+	}
+	/*
+	 * 	private long INTERVAL = 60 * 1000;
 	public synchronized void postpone(String name){
 		long elapsedTime = System.currentTimeMillis() - time;
 		postponeTime = nowTask.getSleepTime() - elapsedTime;
@@ -43,27 +72,8 @@
 		}
 		interruptFlag = true;
 		notify();
-	}	
+	}
+	 */
 
-	@Override
-	public synchronized void run() {
-		LinkedList<TaskInfo> list = plist.getTaskList();
-		try {
-			while(true){
-				nowTask = list.poll();
-				System.out.print("TaskName "+nowTask.getManagerKey());
-				System.out.println(" sleepTime "+nowTask.getSleepTime());
-				time = System.currentTimeMillis();
-				if (nowTask.getSleepTime()!=0)
-					this.wait(nowTask.getSleepTime());
-				if (interruptFlag){				
-					interruptFlag = false;				
-				} else {
-					ods.put("_SENDPING", nowTask.getManagerKey());
-				}
-			}
-		} catch (InterruptedException e) {
-		}
-	}
 }