reactor.public class Dispatcher
public Dispatcher()
Dispatcher with no Handlers.public void handleEvents() throws InterruptedException
InterruptedException.public void addHandler(EventHandler h)
h.public void removeHandler(EventHandler h)
h.public interface EventHandler
Handle.public Handle getHandle()
Handle from which the EventHandler receives events.public void handleEvent(Object s)
s, as received from the Handle.public interface Handle
public void write(Object s)
s as a message on the channel. Note that Handles
are not required to send or receive arbitrary objects; the supported
types are determined by the needs of the application and the Handle implementation.public Object read()
Handle implementations may also return objects
representing error conditions where applicable. public void close()
Handle and EventHandler
interfaces are intended to be implemented by the application that uses the
Reactor pattern. In other words, your Reactor implementation should not
contain any implementations of these interfaces; instead it should behave as
specified above when any Handle and EventHandler
implementations compliant with the above specification (such as those in your
Hangman implementation) are used with your code.System.in and System.out) for its user interface. When a client starts, it must connect to the server and print a line of the form:-").-------e--- 9
o
o -o-----e--- 9 Bob
n -on----en-- 9 Alice
r -on--rren-- 9 Alice
y
y -on--rren-y 9 Bob
i
i -on--rren-y 8 Bob
c conc-rrency 8 Alice
u
u concurrency 8 Bob
java hangman.HangmanServer <word to guess> <number of failed attempts>java hangman.HangmanClient <server host name> <player name>Server runningjava.lang, not java.util.concurrent). Inefficient solutions, such as polling and busy-waiting, will be
rejected. Use of unsafe methods such as java.lang.Thread.destroy() will also lead to rejection.EventHandlers of errors in a Handle.
Instead, the handle can send, for example, different types of objects
as events to differentiate between normal events and errors.
Handles will be
wrappers for java.net.Sockets and
java.net.ServerSockets. To send text through a
Socket, create a java.io.BufferedReader and
java.io.PrintStream using something like:
PrintStream out;
BufferedReader in;
try {
in=new BufferedReader(new InputStreamReader(
socket.getInputStream()));
out=new PrintStream(socket.getOutputStream());
} catch(Exception e) {
throw new RuntimeException("Internal socket error");
}
Actually sending the text is left as an exercise for the student.
telnet and netcat can be used as generic clients for TCP-based
servers. This can be useful for debugging the Hangman server if your
communication protocol is human-readable.
reactor/ |
The Java source
code (version 1.4 or earlier) of your Reactor implementation (the directory corresponds to the reactor
package), including the predefined EventHandler and Handle interfaces. |
hangman/ |
The Java source
code (version 1.4 or earlier) of your Hangman implementation (the directory corresponds to the hangman
package).
|
description.pdf |
A PDF containing
the
documentation for your solution. |
@students.hut.fi.