| | |
| | | import java.awt.Toolkit; |
| | | import java.awt.Window; |
| | | import java.io.BufferedOutputStream; |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.FileWriter; |
| | |
| | | import java.io.InputStream; |
| | | import java.io.PrintWriter; |
| | | import java.io.RandomAccessFile; |
| | | import java.io.Writer; |
| | | import java.net.ConnectException; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.ServerSocket; |
| | | import java.net.Socket; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.HashSet; |
| | |
| | | } |
| | | serverSocket.bind(socketAddress); |
| | | canUseAsPort = true; |
| | | |
| | | serverSocket.close(); |
| | | |
| | | /* Try to create a socket because sometimes even if we can create a server |
| | | * socket there is already someone listening to the port (is the case |
| | | * of products as Sun DS 6.0). |
| | | */ |
| | | try |
| | | { |
| | | new Socket("localhost", port); |
| | | canUseAsPort = false; |
| | | |
| | | } catch (IOException ioe) |
| | | { |
| | | } |
| | | |
| | | } catch (IOException ex) |
| | | { |
| | | canUseAsPort = false; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns if the server is running on the given path. |
| | | * @param serverPath the installation path of the server. |
| | | * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE> |
| | | * otherwise. |
| | | */ |
| | | public static boolean isServerRunning(String serverPath) |
| | | { |
| | | boolean isServerRunning; |
| | | if (isWindows()) |
| | | { |
| | | String testPath = serverPath+File.separator+ |
| | | "locks"+File.separator+"server.lock"; |
| | | File testFile = new File(testPath); |
| | | |
| | | boolean canWriteFile = false; |
| | | Writer output = null; |
| | | try { |
| | | //use buffering |
| | | //FileWriter always assumes default encoding is OK! |
| | | output = new BufferedWriter( new FileWriter(testFile) ); |
| | | output.write("test"); |
| | | output.close(); |
| | | output = new BufferedWriter( new FileWriter(testFile) ); |
| | | output.write(""); |
| | | output.close(); |
| | | |
| | | canWriteFile = true; |
| | | |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | finally |
| | | { |
| | | if (output != null) |
| | | { |
| | | try |
| | | { |
| | | output.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | } |
| | | isServerRunning = !canWriteFile; |
| | | } |
| | | else |
| | | { |
| | | isServerRunning = fileExists(serverPath+File.separator+ |
| | | "logs"+File.separator+"server.pid"); |
| | | } |
| | | return isServerRunning; |
| | | } |
| | | |
| | | /** |
| | | * This is just a commodity method used to try to get an InitialLdapContext. |
| | | * @param t the Thread to be used to create the InitialLdapContext. |
| | | * @param pair an Object[] array that contains the InitialLdapContext and the |