jdk/test/sun/security/krb5/auto/KDC.java
changeset 30038 632939157af2
parent 28670 bb9afe681988
child 30959 14e1b420cdd6
equal deleted inserted replaced
30037:3e785fad2c3b 30038:632939157af2
     1 /*
     1 /*
     2  * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   147     private Map<Option,Object> options = new HashMap<>();
   147     private Map<Option,Object> options = new HashMap<>();
   148     // Realm-specific krb5.conf settings
   148     // Realm-specific krb5.conf settings
   149     private List<String> conf = new ArrayList<>();
   149     private List<String> conf = new ArrayList<>();
   150 
   150 
   151     private Thread thread1, thread2, thread3;
   151     private Thread thread1, thread2, thread3;
       
   152     private volatile boolean udpConsumerReady = false;
       
   153     private volatile boolean tcpConsumerReady = false;
       
   154     private volatile boolean dispatcherReady = false;
   152     DatagramSocket u1 = null;
   155     DatagramSocket u1 = null;
   153     ServerSocket t1 = null;
   156     ServerSocket t1 = null;
   154 
   157 
   155     /**
   158     /**
   156      * Option names, to be expanded forever.
   159      * Option names, to be expanded forever.
  1226         this.port = port;
  1229         this.port = port;
  1227 
  1230 
  1228         // The UDP consumer
  1231         // The UDP consumer
  1229         thread1 = new Thread() {
  1232         thread1 = new Thread() {
  1230             public void run() {
  1233             public void run() {
       
  1234                 udpConsumerReady = true;
  1231                 while (true) {
  1235                 while (true) {
  1232                     try {
  1236                     try {
  1233                         byte[] inbuf = new byte[8192];
  1237                         byte[] inbuf = new byte[8192];
  1234                         DatagramPacket p = new DatagramPacket(inbuf, inbuf.length);
  1238                         DatagramPacket p = new DatagramPacket(inbuf, inbuf.length);
  1235                         udp.receive(p);
  1239                         udp.receive(p);
  1246         thread1.start();
  1250         thread1.start();
  1247 
  1251 
  1248         // The TCP consumer
  1252         // The TCP consumer
  1249         thread2 = new Thread() {
  1253         thread2 = new Thread() {
  1250             public void run() {
  1254             public void run() {
       
  1255                 tcpConsumerReady = true;
  1251                 while (true) {
  1256                 while (true) {
  1252                     try {
  1257                     try {
  1253                         Socket socket = tcp.accept();
  1258                         Socket socket = tcp.accept();
  1254                         System.out.println("-----------------------------------------------");
  1259                         System.out.println("-----------------------------------------------");
  1255                         System.out.println(">>>>> TCP connection established");
  1260                         System.out.println(">>>>> TCP connection established");
  1268         thread2.start();
  1273         thread2.start();
  1269 
  1274 
  1270         // The dispatcher
  1275         // The dispatcher
  1271         thread3 = new Thread() {
  1276         thread3 = new Thread() {
  1272             public void run() {
  1277             public void run() {
       
  1278                 dispatcherReady = true;
  1273                 while (true) {
  1279                 while (true) {
  1274                     try {
  1280                     try {
  1275                         q.take().send();
  1281                         q.take().send();
  1276                     } catch (Exception e) {
  1282                     } catch (Exception e) {
  1277                     }
  1283                     }
  1278                 }
  1284                 }
  1279             }
  1285             }
  1280         };
  1286         };
  1281         thread3.setDaemon(true);
  1287         thread3.setDaemon(true);
  1282         thread3.start();
  1288         thread3.start();
       
  1289 
       
  1290         // wait for the KDC is ready
       
  1291         try {
       
  1292             while (!isReady()) {
       
  1293                 Thread.sleep(100);
       
  1294             }
       
  1295         } catch(InterruptedException e) {
       
  1296             throw new IOException(e);
       
  1297         }
       
  1298     }
       
  1299 
       
  1300     boolean isReady() {
       
  1301         return udpConsumerReady && tcpConsumerReady && dispatcherReady;
  1283     }
  1302     }
  1284 
  1303 
  1285     public void terminate() {
  1304     public void terminate() {
  1286         try {
  1305         try {
  1287             thread1.stop();
  1306             thread1.stop();