jTracer  1.03
Stack trace visualization tool
void org.libcsdbg.jtracer.MainFrame.run ( )

Server thread implementation.

Definition at line 239 of file MainFrame.java.

References org.libcsdbg.jtracer.Registry.get(), org.libcsdbg.jtracer.MainFrame.listener, org.libcsdbg.jtracer.MainFrame.server, and org.libcsdbg.jtracer.MainFrame.shutdown().

240  {
241  try {
242  Registry conf = Registry.getCurrent();
243  Enumeration keys = conf.getSectionKeys("server");
244  if (keys == null)
245  throw new Exception("No server configuration found");
246 
247  /* Create the listener socket unbound */
248  listener = new ServerSocket();
249  listener.setReuseAddress(true);
250 
251  /* Bind to one or more interfaces */
252  InetSocketAddress iface = null;
253  while (keys.hasMoreElements()) {
254  String key = (String) keys.nextElement();
255 
256  iface = (InetSocketAddress) conf.get("server", key);
257  listener.bind(iface);
258 
259  InetAddress addr = iface.getAddress();
260  String msg = "Accepting connections @";
261  msg += addr.getHostAddress() + ":" + iface.getPort();
262 
263  if (addr.isAnyLocalAddress())
264  msg += " (all local)";
265 
266  else if (addr.isMulticastAddress())
267  msg += " (multicast)";
268 
269  else
270  msg += " (" + addr.getCanonicalHostName() + ")";
271 
272  log.appendln(msg, "status");
273  }
274 
275  if (iface == null || !listener.isBound())
276  throw new Exception("No server configuration found");
277 
278  firePropertyChange("isServing", null, true);
279  status.startUptimeTimer();
280 
281  /* Listen for incoming connections */
282  while (server == Thread.currentThread()) {
283  status.setMessage("Waiting for connections", true);
284 
285  try {
286  Socket peer = listener.accept();
287 
288  String addr = peer.getInetAddress().getHostAddress();
289  int port = peer.getPort();
290  log.appendln("Connected peer @" + addr + ":" + port, "status");
291 
292  desktop.register(peer);
293  }
294 
295  catch (Throwable t) {
296  log.appendln(t.toString(), "alert");
297  if (!(t instanceof IOException))
298  Registry.debug(t);
299  }
300  }
301 
302  status.stopUptimeTimer();
303  status.setMessage("Service complete", true);
304  firePropertyChange("isServing", null, false);
305  }
306 
307  catch (Throwable t) {
308  Registry.debug(t);
309  getToolkit().beep();
310  shutdown();
311 
312  log.appendln("Failed to start server (" + t.toString() + ")", "error");
313  status.setMessage("Server failed", false);
314  }
315  }
Thread server
Server thread.
Definition: MainFrame.java:79
void shutdown()
Close the listening server socket and shutdown the server.
Definition: MainFrame.java:184
ServerSocket listener
Listener socket.
Definition: MainFrame.java:82

+ Here is the call graph for this function: