Author: toad
Date: 2008-02-16 19:00:30 +0000 (Sat, 16 Feb 2008)
New Revision: 18010

Modified:
   trunk/freenet/src/freenet/io/comm/UdpSocketHandler.java
Log:
Make UdpSocketHandler a PrioRunnable not a NativeThread. Hence allow it to be 
started from any thread.

Modified: trunk/freenet/src/freenet/io/comm/UdpSocketHandler.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/UdpSocketHandler.java     2008-02-16 
18:58:26 UTC (rev 18009)
+++ trunk/freenet/src/freenet/io/comm/UdpSocketHandler.java     2008-02-16 
19:00:30 UTC (rev 18010)
@@ -22,7 +22,7 @@
 import freenet.support.OOMHandler;
 import freenet.support.io.NativeThread;

-public class UdpSocketHandler extends NativeThread implements 
PacketSocketHandler, PortForwardSensitiveSocketHandler {
+public class UdpSocketHandler implements PrioRunnable, PacketSocketHandler, 
PortForwardSensitiveSocketHandler {

        private final DatagramSocket _sock;
        private final InetAddress _bindTo;
@@ -47,7 +47,6 @@
        private Thread _thread;

        public UdpSocketHandler(int listenPort, InetAddress bindto, Node node, 
long startupTime, String title) throws SocketException {
-               super("UDP packet receiver for "+title, 
NativeThread.MAX_PRIORITY, false);
                this.node = node;
                this.title = title;
                _bindTo = bindto;
@@ -90,7 +89,6 @@
        }

        public void run() { // Listen for packets
-               super.run();
                synchronized(this) {
                        _thread = Thread.currentThread();
                }
@@ -300,12 +298,11 @@

        public void start(boolean disableHangChecker) {
                lastTimeInSeconds = (int) (System.currentTimeMillis() / 1000);
-               setDaemon(true);
                synchronized(this) {
                        if(!_active) return;
                        _started = true;
                }
-               super.start();
+               node.executor.execute(this, "UdpSocketHandler for port 
"+listenPort);
                if(!disableHangChecker) {
                        node.executor.execute(new USMChecker(), 
"UdpSockerHandler watchdog", false);
                }
@@ -447,4 +444,8 @@
                return tracker.getPortForwardStatus();
        }

+       public int getPriority() {
+               return NativeThread.MAX_PRIORITY;
+       }
+
 }


Reply via email to