# HG changeset patch # User sugi # Date 1383538154 -32400 # Node ID 48de3510fb00c2a52f46a904387d8ec301097bfb # Parent 4fe924c9f504d993ea921f4e186bd7aae3814035 Scheduler has bug diff -r 4fe924c9f504 -r 48de3510fb00 .classpath --- a/.classpath Tue Oct 22 20:02:15 2013 +0900 +++ b/.classpath Mon Nov 04 13:09:14 2013 +0900 @@ -5,9 +5,11 @@ + + - - - + + + diff -r 4fe924c9f504 -r 48de3510fb00 src/alice/daemon/Connection.java --- a/src/alice/daemon/Connection.java Tue Oct 22 20:02:15 2013 +0900 +++ b/src/alice/daemon/Connection.java Mon Nov 04 13:09:14 2013 +0900 @@ -7,12 +7,13 @@ import alice.codesegment.SingletonMessage; import alice.datasegment.Command; +import alice.topology.manager.keeparive.States; public class Connection { public Socket socket; public LinkedBlockingQueue sendQueue = new LinkedBlockingQueue(); - + public Connection(Socket socket) { this.socket = socket; } @@ -45,4 +46,7 @@ } } + public States closeAndRetry(){ + return null; + } } diff -r 4fe924c9f504 -r 48de3510fb00 src/alice/datasegment/RemoteDataSegmentManager.java --- a/src/alice/datasegment/RemoteDataSegmentManager.java Tue Oct 22 20:02:15 2013 +0900 +++ b/src/alice/datasegment/RemoteDataSegmentManager.java Mon Nov 04 13:09:14 2013 +0900 @@ -34,7 +34,6 @@ logger.info("Connect to " + connection.getInfoString()); } catch (IOException e) { try { - System.out.println("WAITING"); Thread.sleep(50); } catch (InterruptedException e1) { e1.printStackTrace(); @@ -45,7 +44,6 @@ new OutboundTcpConnection(connection).start(); // if connection failed need to stop these thread if (connect){ - System.out.println("send error"); new SendError(new HostMessage(hostName, port)).execute(); } } diff -r 4fe924c9f504 -r 48de3510fb00 src/alice/topology/manager/keeparive/PingScheduler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/topology/manager/keeparive/PingScheduler.java Mon Nov 04 13:09:14 2013 +0900 @@ -0,0 +1,80 @@ +package alice.topology.manager.keeparive; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import alice.codesegment.CodeSegment; + +public class PingScheduler extends CodeSegment{ + private LinkedList list = new LinkedList(); + private ArrayList regist = new ArrayList(); + public boolean updateFlag = false; + public long time = 0; + public int taskNum = 0; + public TaskInfo nowTask; + + public List nameList(){ + return regist; + } + + public List getTaskList(){ + return list; + } + + public synchronized void wake(){ + long t = System.currentTimeMillis(); + long addTime = nowTask.getTime() - (t - time); + TaskInfo ti = list.get(0); + ti.setTime(ti.getTime() + addTime); + this.notify(); + } + + public synchronized void addTask(TaskInfo newInfo){ + boolean newTaskFlag = true; + for (TaskInfo t : regist){ + if(newInfo.getName().equals(t.getName())){ + newInfo.setTaskNum(t.getTaskNum()); + newTaskFlag = false; + break; + } + } + if (newTaskFlag){ + taskNum +=10; + newInfo.setTaskNum(taskNum); + } + boolean addFlag = true; + for (int i = 0;i< list.size(); i++){ + TaskInfo info = list.get(i); + Long t = info.getTime(); + if (newInfo.getTime() > t ){ + newInfo.setTime(newInfo.getTime() -t); + } else { + list.add(i, newInfo); + if (i != list.size() -1 ){ + TaskInfo nextInfo = list.get(i+1); + newInfo.setTime(nextInfo.getTime() - newInfo.getTime()); + } + addFlag = false; + break; + } + } + if (addFlag) + list.add(newInfo); + + this.updateFlag = true; + } + + @Override + public synchronized void run() { + try { + while(true){ + if(list.size()== 0)System.exit(0); + nowTask = list.poll(); + time = System.currentTimeMillis(); + this.wait(nowTask.getTime()); + } + } catch (InterruptedException e) { + } + } +} diff -r 4fe924c9f504 -r 48de3510fb00 src/alice/topology/manager/keeparive/SchedulerViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/topology/manager/keeparive/SchedulerViewer.java Mon Nov 04 13:09:14 2013 +0900 @@ -0,0 +1,158 @@ +package alice.topology.manager.keeparive; + +/** + * Copyright (c) 2008, 2012 Oracle and/or its affiliates. + * All rights reserved. Use is subject to license terms. + */ +import javafx.application.Application; +import javafx.scene.Group; +import javafx.scene.Scene; +import javafx.stage.Stage; +import javafx.animation.Animation; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.chart.LineChart; +import javafx.scene.chart.NumberAxis; +import javafx.scene.chart.XYChart; +import javafx.util.Duration; + +/** + * A simulated stock line chart. + * + * @see javafx.scene.chart.Chart + * @see javafx.scene.chart.LineChart + * @see javafx.scene.chart.NumberAxis + * @see javafx.scene.chart.XYChart + */ +public class SchedulerViewer extends Application { + private PingScheduler ps; + private XYChart.Series hourDataSeries; + private NumberAxis xAxis; + private Timeline animation; + + private double hours = 0; + private double minutes = 0; + private double timeInHours = 0; + + + private void init(Stage primaryStage) { + Group root = new Group(); + primaryStage.setScene(new Scene(root)); + root.getChildren().add(createChart()); + // create timeline to add new data every 60th of second + animation = new Timeline(); + animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000/60), new EventHandler() { + @Override public void handle(ActionEvent actionEvent) { + // 6 minutes data per frame + for(int count=0; count < 6; count++) { + nextTime(); + plotTime(); + } + } + })); + animation.setCycleCount(Animation.INDEFINITE); + } + + protected LineChart createChart() { + xAxis = new NumberAxis(0,100,10); + final NumberAxis yAxis = new NumberAxis(0,100,10); + final LineChart lc = new LineChart(xAxis,yAxis); + // setup chart + lc.setId("lineStockDemo"); + lc.setCreateSymbols(false); + lc.setAnimated(false); + lc.setLegendVisible(false); + lc.setTitle("Task Viewer"); + xAxis.setLabel("Time"); + xAxis.setForceZeroInRange(false); + yAxis.setLabel("Task Name"); + yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null)); + // add starting data + hourDataSeries = new XYChart.Series(); + for (double m=0; m<(60); m++) { + nextTime(); + plotTime(); + plotGraph(); + } + lc.getData().add(hourDataSeries); + return lc; + } + + private void plotGraph() { + if (ps.updateFlag){ + if(!hourDataSeries.getData().isEmpty()) + hourDataSeries.getData().clear(); + int count = 0; + hourDataSeries.getData().add(new XYChart.Data(count, ps.nowTask.getTaskNum())); + count += ps.nowTask.getTime()/1000; + hourDataSeries.getData().add(new XYChart.Data(count, ps.nowTask.getTaskNum())); + + for (TaskInfo info : ps.getTaskList()){ + hourDataSeries.getData().add(new XYChart.Data(count, info.getTaskNum())); + count += info.getTime()/1000; + hourDataSeries.getData().add(new XYChart.Data(count, info.getTaskNum())); + } + ps.updateFlag = false; + } + + + } + + private void nextTime() { + if (minutes == 59) { + hours ++; + minutes = 0; + } else { + minutes ++; + } + timeInHours = hours + ((1d/60d)*minutes); + } + + private void plotTime() { + if ((timeInHours % 1) == 0) { + xAxis.setLowerBound(xAxis.getLowerBound()+1); + xAxis.setUpperBound(xAxis.getUpperBound()+1); + + } + } + + public void StartScheduler(){ + ps = new PingScheduler(); + TaskInfo a = new TaskInfo("a", 10 * 1000); + + + TaskInfo d = new TaskInfo("d", 100 * 1000); + TaskInfo c = new TaskInfo("c", 40 * 1000); + TaskInfo b = new TaskInfo("b", 20 * 1000); + + + ps.addTask(a); + ps.addTask(b); + ps.addTask(c); + + ps.addTask(d); + + for (TaskInfo info :ps.getTaskList()){ + System.out.println(info.getTime()); + } + ps.execute(); + } + + public void play() { + animation.play(); + } + + @Override public void stop() { + animation.pause(); + } + + @Override public void start(Stage primaryStage) throws Exception { + StartScheduler(); + init(primaryStage); + primaryStage.show(); + play(); + } + +} diff -r 4fe924c9f504 -r 48de3510fb00 src/alice/topology/manager/keeparive/StartViewer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/topology/manager/keeparive/StartViewer.java Mon Nov 04 13:09:14 2013 +0900 @@ -0,0 +1,10 @@ +package alice.topology.manager.keeparive; + +import javafx.application.Application; + +public class StartViewer { + public static void main(String[] args) { + Application.launch(SchedulerViewer.class, args); + + } +} diff -r 4fe924c9f504 -r 48de3510fb00 src/alice/topology/manager/keeparive/TaskInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/topology/manager/keeparive/TaskInfo.java Mon Nov 04 13:09:14 2013 +0900 @@ -0,0 +1,32 @@ +package alice.topology.manager.keeparive; + +public class TaskInfo { + private long nextPingTime; + private String taskName; + private int taskNum = 0; + + public TaskInfo(String n, long t){ + nextPingTime = t; + taskName = n; + } + + public long getTime(){ + return nextPingTime; + } + + public String getName(){ + return taskName; + } + + public void setTime(long time){ + nextPingTime = time; + } + + public int getTaskNum(){ + return taskNum; + } + + public void setTaskNum(int num){ + taskNum = num; + } +}