equal
deleted
inserted
replaced
139 // The request/response job queue |
139 // The request/response job queue |
140 private BlockingQueue<Job> q = new ArrayBlockingQueue<Job>(100); |
140 private BlockingQueue<Job> q = new ArrayBlockingQueue<Job>(100); |
141 // Options |
141 // Options |
142 private Map<Option,Object> options = new HashMap<Option,Object>(); |
142 private Map<Option,Object> options = new HashMap<Option,Object>(); |
143 |
143 |
|
144 private Thread thread1, thread2, thread3; |
|
145 DatagramSocket u1 = null; |
|
146 ServerSocket t1 = null; |
|
147 |
144 /** |
148 /** |
145 * Option names, to be expanded forever. |
149 * Option names, to be expanded forever. |
146 */ |
150 */ |
147 public static enum Option { |
151 public static enum Option { |
148 /** |
152 /** |
938 * port no less than 8000 will be chosen and used. |
942 * port no less than 8000 will be chosen and used. |
939 * @param asDaemon true if the KDC threads should be daemons |
943 * @param asDaemon true if the KDC threads should be daemons |
940 * @throws java.io.IOException for any communication error |
944 * @throws java.io.IOException for any communication error |
941 */ |
945 */ |
942 protected void startServer(int port, boolean asDaemon) throws IOException { |
946 protected void startServer(int port, boolean asDaemon) throws IOException { |
943 DatagramSocket u1 = null; |
|
944 ServerSocket t1 = null; |
|
945 if (port > 0) { |
947 if (port > 0) { |
946 u1 = new DatagramSocket(port, InetAddress.getByName("127.0.0.1")); |
948 u1 = new DatagramSocket(port, InetAddress.getByName("127.0.0.1")); |
947 t1 = new ServerSocket(port); |
949 t1 = new ServerSocket(port); |
948 } else { |
950 } else { |
949 while (true) { |
951 while (true) { |
964 System.out.println("Start KDC on " + port); |
966 System.out.println("Start KDC on " + port); |
965 |
967 |
966 this.port = port; |
968 this.port = port; |
967 |
969 |
968 // The UDP consumer |
970 // The UDP consumer |
969 Thread thread = new Thread() { |
971 thread1 = new Thread() { |
970 public void run() { |
972 public void run() { |
971 while (true) { |
973 while (true) { |
972 try { |
974 try { |
973 byte[] inbuf = new byte[8192]; |
975 byte[] inbuf = new byte[8192]; |
974 DatagramPacket p = new DatagramPacket(inbuf, inbuf.length); |
976 DatagramPacket p = new DatagramPacket(inbuf, inbuf.length); |
980 e.printStackTrace(); |
982 e.printStackTrace(); |
981 } |
983 } |
982 } |
984 } |
983 } |
985 } |
984 }; |
986 }; |
985 thread.setDaemon(asDaemon); |
987 thread1.setDaemon(asDaemon); |
986 thread.start(); |
988 thread1.start(); |
987 |
989 |
988 // The TCP consumer |
990 // The TCP consumer |
989 thread = new Thread() { |
991 thread2 = new Thread() { |
990 public void run() { |
992 public void run() { |
991 while (true) { |
993 while (true) { |
992 try { |
994 try { |
993 Socket socket = tcp.accept(); |
995 Socket socket = tcp.accept(); |
994 System.out.println("-----------------------------------------------"); |
996 System.out.println("-----------------------------------------------"); |
1002 e.printStackTrace(); |
1004 e.printStackTrace(); |
1003 } |
1005 } |
1004 } |
1006 } |
1005 } |
1007 } |
1006 }; |
1008 }; |
1007 thread.setDaemon(asDaemon); |
1009 thread2.setDaemon(asDaemon); |
1008 thread.start(); |
1010 thread2.start(); |
1009 |
1011 |
1010 // The dispatcher |
1012 // The dispatcher |
1011 thread = new Thread() { |
1013 thread3 = new Thread() { |
1012 public void run() { |
1014 public void run() { |
1013 while (true) { |
1015 while (true) { |
1014 try { |
1016 try { |
1015 q.take().send(); |
1017 q.take().send(); |
1016 } catch (Exception e) { |
1018 } catch (Exception e) { |
1017 } |
1019 } |
1018 } |
1020 } |
1019 } |
1021 } |
1020 }; |
1022 }; |
1021 thread.setDaemon(true); |
1023 thread3.setDaemon(true); |
1022 thread.start(); |
1024 thread3.start(); |
1023 } |
1025 } |
1024 |
1026 |
|
1027 public void terminate() { |
|
1028 try { |
|
1029 thread1.stop(); |
|
1030 thread2.stop(); |
|
1031 thread3.stop(); |
|
1032 u1.close(); |
|
1033 t1.close(); |
|
1034 } catch (Exception e) { |
|
1035 // OK |
|
1036 } |
|
1037 } |
1025 /** |
1038 /** |
1026 * Helper class to encapsulate a job in a KDC. |
1039 * Helper class to encapsulate a job in a KDC. |
1027 */ |
1040 */ |
1028 private static class Job { |
1041 private static class Job { |
1029 byte[] token; // The received request at creation time and |
1042 byte[] token; // The received request at creation time and |