aboutsummaryrefslogtreecommitdiff
path: root/src/org/gnunet/util/Server.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/gnunet/util/Server.java')
-rw-r--r--src/org/gnunet/util/Server.java35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/org/gnunet/util/Server.java b/src/org/gnunet/util/Server.java
index d6a4290..8aa7c60 100644
--- a/src/org/gnunet/util/Server.java
+++ b/src/org/gnunet/util/Server.java
@@ -30,17 +30,17 @@ import java.nio.channels.ServerSocketChannel;
30import java.nio.channels.SocketChannel; 30import java.nio.channels.SocketChannel;
31import java.util.ArrayList; 31import java.util.ArrayList;
32import java.util.HashMap; 32import java.util.HashMap;
33import java.util.LinkedList;
33import java.util.List; 34import java.util.List;
34 35
35public class Server { 36public class Server {
36
37
38 private final RelativeTime idleTimeout; 37 private final RelativeTime idleTimeout;
39 private final boolean requireFound; 38 private final boolean requireFound;
40 private List<ServerSocketChannel> listenSockets; 39 private List<ServerSocketChannel> listenSockets;
41 private List<ClientHandle> clients; 40 private List<ClientHandle> clients;
42 41
43 private HashMap<Class, MessageRunabout> handlers; 42 private HashMap<Class, MessageRunabout> handlers;
43 private List<DisconnectHandler> disconnectHandlers = new LinkedList<DisconnectHandler>();
44 44
45 45
46 public class ClientHandle { 46 public class ClientHandle {
@@ -62,9 +62,9 @@ public class Server {
62 * Notify us when the server has enough space to transmit 62 * Notify us when the server has enough space to transmit
63 * a message of the given size to the given client. 63 * a message of the given size to the given client.
64 * 64 *
65 * @param size requested amount of buffer space 65 * @param size requested amount of buffer space
66 * @param timeout after how long should we give up (and call 66 * @param timeout after how long should we give up (and call
67 * notify with buf NULL and size 0)? 67 * notify with buf NULL and size 0)?
68 * @param transmitter callback 68 * @param transmitter callback
69 * @return a handle to cancel the notification 69 * @return a handle to cancel the notification
70 */ 70 */
@@ -76,7 +76,7 @@ public class Server {
76 * Resume receiving from this client, we are done processing the 76 * Resume receiving from this client, we are done processing the
77 * current request. This function must be called from within each 77 * current request. This function must be called from within each
78 * message handler (or its respective continuations). 78 * message handler (or its respective continuations).
79 * 79 * <p/>
80 * The server does not automatically continue to receive messages to 80 * The server does not automatically continue to receive messages to
81 * support flow control. 81 * support flow control.
82 * 82 *
@@ -144,9 +144,8 @@ public class Server {
144 * @param srv ... 144 * @param srv ...
145 */ 145 */
146 private void doAccept(final ServerSocketChannel srv) { 146 private void doAccept(final ServerSocketChannel srv) {
147 /* 147 Scheduler.TaskConfiguration b = new Scheduler.TaskConfiguration(RelativeTime.FOREVER,
148 Scheduler.TaskBuilder b = new Scheduler.TaskBuilder(); 148 new Scheduler.Task() {
149 b.withTask(new Scheduler.Task() {
150 @Override 149 @Override
151 public void run(Scheduler.RunContext ctx) { 150 public void run(Scheduler.RunContext ctx) {
152 try { 151 try {
@@ -159,9 +158,8 @@ public class Server {
159 doAccept(srv); 158 doAccept(srv);
160 } 159 }
161 }); 160 });
162 b.withSelectAccept(srv); 161 b.selectAccept(srv);
163 Scheduler.add(b); 162 b.schedule();
164 */
165 } 163 }
166 164
167 165
@@ -214,13 +212,16 @@ public class Server {
214 void onDisconnect(ClientHandle clientHandle); 212 void onDisconnect(ClientHandle clientHandle);
215 } 213 }
216 214
217 public Cancelable notifyDisconnect(DisconnectHandler disconnectHandler) { 215 public Cancelable notifyDisconnect(final DisconnectHandler disconnectHandler) {
218 return null; 216 this.disconnectHandlers.add(disconnectHandler);
217 return new Cancelable() {
218 @Override
219 public void cancel() {
220 Server.this.disconnectHandlers.remove(disconnectHandler);
221 }
222 };
219 } 223 }
220 224
221 /**
222 * Free resources held by this server.
223 */
224 public void destroy() { 225 public void destroy() {
225 226
226 } 227 }