Exemplo n.º 1
0
 @NbBundle.Messages({
   "# {0} - project name",
   "InternalWebServer.stopping=Stopping PHP built-in web server for project {0}..."
 })
 @SuppressWarnings("SleepWhileHoldingLock")
 private static boolean ensureServerStopped(InternalWebServer instance) {
   assert !EventQueue.isDispatchThread();
   ProgressHandle progressHandle =
       ProgressHandleFactory.createHandle(
           Bundle.InternalWebServer_stopping(instance.project.getName()));
   try {
     progressHandle.start();
     // stop server
     instance.stop();
     // wait for shutdown
     RunConfigInternal runConfig = RunConfigInternal.forProject(instance.project);
     String host = runConfig.getHostname();
     int port = Integer.valueOf(runConfig.getPort());
     for (int i = 0; i < 20; ++i) {
       try {
         Socket socket = new Socket(host, port);
         socket.close();
         Thread.sleep(200);
       } catch (InterruptedException ex) {
         Thread.currentThread().interrupt();
       } catch (UnknownHostException ex) {
         return true;
       } catch (IOException ex) {
         return true;
       }
     }
     return false;
   } finally {
     progressHandle.finish();
   }
 }