-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desktop: Extract Clock and Handler implementations to new classes
- Loading branch information
1 parent
ce1b124
commit 24cd3bb
Showing
5 changed files
with
49 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.droidplanner.desktop.logic; | ||
|
||
public class Clock implements org.droidplanner.core.drone.DroneInterfaces.Clock { | ||
@Override | ||
public long elapsedRealtime() { | ||
return System.currentTimeMillis(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.droidplanner.desktop.logic; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class Handler implements | ||
org.droidplanner.core.drone.DroneInterfaces.Handler { | ||
|
||
private final ScheduledExecutorService scheduler = Executors | ||
.newSingleThreadScheduledExecutor(); | ||
private final Map<Runnable, ScheduledFuture<?>> futureThreads = new HashMap<Runnable, ScheduledFuture<?>>(); | ||
|
||
@Override | ||
public void removeCallbacks(Runnable thread) { | ||
if (futureThreads.containsKey(thread)) { | ||
boolean mayInterruptIfRunning = false; | ||
futureThreads.get(thread).cancel(mayInterruptIfRunning); | ||
} | ||
} | ||
|
||
@Override | ||
public void post(Runnable thread) { | ||
scheduler.execute(thread); | ||
} | ||
|
||
@Override | ||
public void postDelayed(Runnable thread, long timeout) { | ||
ScheduledFuture<?> future = scheduler.schedule(thread, timeout, | ||
TimeUnit.MILLISECONDS); | ||
futureThreads.put(thread, future); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters