/** * Gets information on the locator. * * @param directory the locator's directory * @return information string. * @throws UncreatedSystemException if the locator <code>directory</code> does not exist or is not * a directory. * @throws GemFireIOException if the manager info exists but could not be read. This probably * means that the info file is corrupt. */ public String locatorInfo(File directory) { int statusCode = ManagerInfo.getLocatorStatusCode(directory); String statusString = ManagerInfo.statusToString(statusCode); try { ManagerInfo mi = ManagerInfo.loadLocatorInfo(directory); if (statusCode == ManagerInfo.KILLED_STATUS_CODE) { return String.format("Locator in %s was killed while it was %s. Locator process id was %s.", directory, ManagerInfo.statusToString(mi.getManagerStatus()), Integer.valueOf(mi.getManagerProcessId())); } else { return String.format("Locator in %s is %s. Locator process id is %s.", directory, statusString, Integer.valueOf(mi.getManagerProcessId())); } } catch (UnstartedSystemException ex) { return String.format("Locator in %s is stopped.", directory); } catch (GemFireIOException ex) { return String.format("Locator in %s is starting.", directory); } }
/** * Gets the status of a locator. * * @param directory the locator's directory * @return the status string. Will be one of the following: "running", "killed", "stopped", * "stopping", or "starting". * @throws UncreatedSystemException if the locator <code>directory</code> does not exist or is not * a directory. * @throws GemFireIOException if the manager info exists but could not be read. This probably * means that the info file is corrupt. */ public String locatorStatus(File directory) { return ManagerInfo.getLocatorStatusCodeString(directory); }
public static File setLocatorStarting(File directory, int port, InetAddress bindAddress) { if (ManagerInfo.isManagerRunning(directory, true)) { throw new SystemIsRunningException(String.format("%s %s is already running.", new Object[] {"Locator", directory.getPath()})); } File result = getManagerInfoFile(directory, true); ManagerInfo.saveManagerInfo(OSProcess.getId(), STARTING_STATUS_CODE, directory, port, bindAddress); return result; }
public static String getLocatorStatusCodeString(File directory) { return statusToString(getLocatorStatusCode(directory)); }
private static int getManagerStatusCode(File directory, boolean locator) { boolean interrupted = false; try { ManagerInfo mi = ManagerInfo.loadManagerInfo(directory, locator); if (!PureJavaMode.isPure() && !OSProcess.exists(mi.getManagerProcessId())) { return KILLED_STATUS_CODE; } else { return mi.getManagerStatus(); ManagerInfo.loadManagerInfo(directory, locator); return getManagerStatusCode(directory, locator); } catch (UnstartedSystemException ignore) { return STOPPED_STATUS_CODE;
int pid = 0; try { ManagerInfo info = ManagerInfo.loadLocatorInfo(directory); pid = info.getManagerProcessId(); if (portOption == null || portOption.trim().length() == 0) { port = info.getManagerPort(); addr = info.getManagerAddress();
private static boolean isManagerStarted(File directory, boolean locator) { try { ManagerInfo mi = loadManagerInfo(directory, locator); int status = mi.getManagerStatus(); if (status != STARTED_STATUS_CODE) { return false; } // Check to see if manager process exists, assume it is for PureJava if (PureJavaMode.isPure() || OSProcess.exists(mi.getManagerProcessId())) { return true; } return false; } catch (UnstartedSystemException ignore) { return false; } catch (GemFireIOException ex) { Throwable cause = ex.getCause(); if (cause == null) { // this happens when the file was zero size return false; } else if (cause instanceof InvalidClassException) { // This happens when we have a serialVersionUID mismatch. // We don't want to hide this so throw the exception throw ex; } else { return false; } } }
/** * Cleans up any artifacts left by a killed locator. Namely the info file is deleted. */ private static void cleanupAfterKilledLocator(File directory) { try { if (ManagerInfo.getLocatorStatusCode(directory) == ManagerInfo.KILLED_STATUS_CODE) { File infoFile = ManagerInfo.getLocatorInfoFile(directory); if (infoFile.exists()) { if (!infoFile.delete() && infoFile.exists()) { System.out.println("WARNING: unable to delete " + infoFile.getAbsolutePath()); } if (!quiet) { System.out.println( "Cleaned up artifacts left by the previous killed locator."); } } } } catch (GemFireException ignore) { } }
/** * Saves the manager information to the info file in the given <code>directory</code>. * * @param pid the process id of the manager VM. * @param status the status of the manager * @param directory the manager's directory. * @param port the tcp/ip port for the locator * @param bindAddress the tcp/ip address for the locator * @throws GemFireIOException if the file could not be written. */ private static void saveManagerInfo(int pid, int status, File directory, int port, InetAddress bindAddress) { ManagerInfo info = new ManagerInfo(pid, status, port, bindAddress); File infoFile = getManagerInfoFile(directory, true); try { FileOutputStream ostream = new FileOutputStream(infoFile); DataOutputStream dos = new DataOutputStream(ostream); DataSerializer.writeObject(info, dos); ostream.close(); } catch (IOException io) { throw new GemFireIOException( String.format("Could not write file %s.", infoFile), io); } }
private static boolean isManagerStopped(File directory, boolean locator) { try { ManagerInfo mi = loadManagerInfo(directory, locator); if (!OSProcess.exists(mi.getManagerProcessId())) { return true; } return false; } catch (UnstartedSystemException ignore) { return true; } catch (GemFireIOException ex) { Throwable cause = ex.getCause(); if (cause == null) { // this happens when the file was zero size return false; } else if (cause instanceof InvalidClassException) { // This happens when we have a serialVersionUID mismatch. // We don't want to hide this so throw the exception throw ex; } else { return false; } } }
public static File getLocatorInfoFile(File directory) { return getManagerInfoFile(directory, true); }
public static int getLocatorStatusCode(File directory) { return getManagerStatusCode(directory, true); }
private static boolean isManagerRunning(File directory, boolean locator) { try { ManagerInfo mi = loadManagerInfo(directory, locator); int status = mi.getManagerStatus(); if (status != STARTED_STATUS_CODE && status != STARTING_STATUS_CODE && status != STOPPING_STATUS_CODE) { if (!PureJavaMode.isPure() && !OSProcess.exists(mi.getManagerProcessId())) { return false;
directory.getPath())); File infoFile = getManagerInfoFile(directory, locator); if (!infoFile.exists()) { throw new UnstartedSystemException(String.format("The info file %s does not exist.",