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
public class ReadyReminderClientMokapotWithReminders { | |
public static void main(String[] args) throws Exception { | |
DistributedCommunicator communicator | |
= new DistributedCommunicator("test2.p12", | |
"testpassword1".toCharArray()); | |
communicator.startCommunication(); | |
CommunicationAddress serverAddress | |
= communicator.lookupAddress(InetAddress.getLoopbackAddress(), 15238); |
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
public class ReadyReminderClientLocalWithReminders { | |
public static void main(String[] args) throws Exception { | |
ReadyReminderServer<String> server = new ReadyReminderServer<>(); | |
final PrintStream out = System.out; | |
server.submitEventWithReminder("two seconds", Instant.now().plusSeconds(2), | |
() -> out.println("reminder for two-second event")); | |
server.submitEvent("one second", Instant.now().plusSeconds(1)); | |
server.submitEventWithReminder("four seconds", Instant.now().plusSeconds(4), |
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
@FunctionalInterface | |
public interface XWWWFormUrlencodedHTTPHandler extends HttpHandler { | |
/** | |
* Handles an HTTP request encoded as <code>x-www-form-urlencoded</code>. | |
* This format takes a set of key-value pairs as its input. This method does | |
* not place requirements on what format is used for the output. | |
* | |
* @param params The parameters given in the request, a set of key/value | |
* pairs. |
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
public class ReadyReminderServerHTTP { | |
public static void main(String[] args) throws Exception { | |
ReadyReminderServer<String> list = new ReadyReminderServer<>(); | |
HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 15230), 4); | |
server.createContext("/ReadyReminder", (XWWWFormUrlencodedHTTPHandler) (params, method) -> { | |
if (!method.equals("POST")) { | |
return stringResponse("request method " + method + " is inapplicable\n", 405); | |
} |
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
public final class XWWWFormUrlencodedHTTPRequest extends HashMap<String, String> { | |
private static final long serialVersionUID = 0xe673f874cf17d539L; | |
public XWWWFormUrlencodedHTTPRequest(URL url, Object... params) | |
throws IOException, IllegalArgumentException { | |
this(url, evenLengthListToMap(params)); | |
} | |
@SuppressWarnings("LeakingThisInConstructor") |
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
public class ReadyReminderClientHTTP { | |
private static void submitEvent(URL url, String event, Instant readyAt) | |
throws IOException { | |
new XWWWFormUrlencodedHTTPRequest(url, "command", "submitEvent", | |
"event", event, "readyAt", readyAt); | |
} | |
private static String extractReadyEvent(URL url) throws IOException { | |
return new XWWWFormUrlencodedHTTPRequest(url, "command", "extractReadyEvent") |
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
public class ReadyReminderClientMokapot { | |
public static void main(String[] args) throws Exception { | |
// create and start the communicator | |
DistributedCommunicator communicator = | |
new DistributedCommunicator("test2.p12", | |
"testpassword1".toCharArray()); | |
communicator.startCommunication(); | |
// retrieve communicator address | |
CommunicationAddress serverAddress = |
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
ReadyReminderServer<String> server = | |
communicator.runRemotely | |
(ReadyReminderServer<String>::new, serverAddress); |
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
public class ReadyReminderClientLocal | |
{ | |
public static void main(String[] args) throws Exception { | |
ReadyReminderServer<String> server = new ReadyReminderServer<>(); | |
server.submitEvent("two seconds", Instant.now().plusSeconds(2)); | |
server.submitEvent("one second", Instant.now().plusSeconds(1)); | |
server.submitEvent("three seconds", Instant.now().plusSeconds(3)); | |
System.out.println(Objects.toString(server.extractReadyEvent())); |
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
public class ReadyReminderServer<T> { | |
private final PriorityQueue<Entry> queue = new PriorityQueue<>(); | |
public void submitEvent(T event, Instant readyAt) { | |
queue.add(new Entry(event, readyAt)); | |
System.err.println("# submitEvent(" + event + ", " + readyAt + ")"); | |
} | |
public T extractReadyEvent() { |
NewerOlder