diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/util')
12 files changed, 557 insertions, 524 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/util/Assert.java b/pki/base/common/src/com/netscape/cmscore/util/Assert.java index 24659929..afc38f49 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/Assert.java +++ b/pki/base/common/src/com/netscape/cmscore/util/Assert.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + public class Assert { public static final boolean ON = true; diff --git a/pki/base/common/src/com/netscape/cmscore/util/AssertionException.java b/pki/base/common/src/com/netscape/cmscore/util/AssertionException.java index d2f3708d..6a0d8e66 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/AssertionException.java +++ b/pki/base/common/src/com/netscape/cmscore/util/AssertionException.java @@ -17,9 +17,10 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + /** - * Assertion exceptions are thrown when assertion code is invoked and fails to - * operate properly. + * Assertion exceptions are thrown when assertion code is invoked + * and fails to operate properly. */ public class AssertionException extends Error { /** diff --git a/pki/base/common/src/com/netscape/cmscore/util/Debug.java b/pki/base/common/src/com/netscape/cmscore/util/Debug.java index 89eecb61..417f3159 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/Debug.java +++ b/pki/base/common/src/com/netscape/cmscore/util/Debug.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.io.FileOutputStream; import java.io.OutputStream; import java.io.PrintStream; @@ -29,27 +30,29 @@ import com.netscape.certsrv.base.IConfigStore; import com.netscape.certsrv.base.ISubsystem; import com.netscape.cmsutil.util.Utils; -public class Debug implements ISubsystem { + +public class Debug + implements ISubsystem { private static Debug mInstance = new Debug(); private static boolean mShowCaller = false; - /* - * This dateformatter is used to put the date on each debug line. But the - * DateFormatter is not thread safe, so I create a thread-local - * DateFormatter for each thread - */ + + /* This dateformatter is used to put the date on each + debug line. But the DateFormatter is not thread safe, + so I create a thread-local DateFormatter for each thread + */ private static String DATE_PATTERN = "dd/MMM/yyyy:HH:mm:ss"; private static ThreadLocal mFormatObject = new ThreadLocal() { - protected synchronized Object initialValue() { - return new SimpleDateFormat(DATE_PATTERN); - } - }; + protected synchronized Object initialValue() { + return new SimpleDateFormat(DATE_PATTERN); + } + }; - /* the dateformatter should be accessed with this function */ - private static SimpleDateFormat getDateFormatter() { - return ((SimpleDateFormat) (mFormatObject.get())); - } + /* the dateformatter should be accessed with this function */ + private static SimpleDateFormat getDateFormatter() { + return ((SimpleDateFormat)(mFormatObject.get())); + } public static final boolean ON = false; public static final int OBNOXIOUS = 10; @@ -59,10 +62,10 @@ public class Debug implements ISubsystem { // the difference between this and 'ON' is that this is always // guaranteed to log to 'mOut', whereas other parts of the server // may do: - // if (Debug.ON) { - // System.out.println(".."); - // } - // I want to make sure that any Debug.trace() is not logged to + // if (Debug.ON) { + // System.out.println(".."); + // } + // I want to make sure that any Debug.trace() is not logged to // System.out if the server is running under watchdog private static boolean TRACE_ON = false; @@ -70,7 +73,7 @@ public class Debug implements ISubsystem { private static int mDebugLevel = VERBOSE; private static PrintStream mOut = null; - private static Hashtable mHK = null; + private static Hashtable mHK = null; static { if (TRACE_ON == true) { @@ -85,112 +88,98 @@ public class Debug implements ISubsystem { /** * Output a debug message at the output stream sepcified in the init() * method. This method is very lightweight if debugging is turned off, since - * it will return immediately. However, the caller should be aware that if - * the argument to Debug.trace() is an object whose toString() is expensive, - * that this toString() will still be called in any case. In such a case, it - * is wise to wrap the Debug.trace like this: - * - * <pre> - * if (Debug.on()) { - * Debug.trace("obj is: " + obj); - * } - * </pre> - * + * it will return immediately. However, the caller should be aware that + * if the argument to Debug.trace() is an object whose toString() is + * expensive, that this toString() will still be called in any case. + * In such a case, it is wise to wrap the Debug.trace like this: <pre> + * if (Debug.on()) { Debug.trace("obj is: "+obj); } + * </pre> * @param level the message level. If this is >= than the currently set - * level (set with setLevel() ), the message is printed + * level (set with setLevel() ), the message is printed * @param t the message to print - * @param ignoreStack when walking the stack to determine the location of - * the method that called the trace() method, ignore any classes - * with this string in. Can be null - * @param printCaller if true, (and if static mShowCaller is true) dump - * caller information in this format: (source-file:line) - * methodname(): + * @param ignoreStack when walking the stack to determine the + * location of the method that called the trace() method, + * ignore any classes with this string in. Can be null + * @param printCaller if true, (and if static mShowCaller is true) + * dump caller information in this format: + * (source-file:line) methodname(): */ - public static void trace(int level, String t, String ignoreStack, - boolean printCaller) { - String callerinfo = ""; - if (!TRACE_ON) - return; + public static void trace(int level, String t, String ignoreStack, boolean printCaller) { + String callerinfo = ""; + if (!TRACE_ON) return; if (level >= mDebugLevel) { if (mShowCaller && printCaller) { String method = ""; String fileAndLine = ""; try { - Throwable tr = new Throwable(); - StackTraceElement ste[] = tr.getStackTrace(); - int i = 0; - while ((i < ste.length) - && (ste[i].getMethodName().toLowerCase() - .indexOf("debug") > -1) - || (ste[i].getMethodName().toLowerCase() - .indexOf("hashkey") > -1) - || (ste[i].getClassName().toLowerCase() - .indexOf("propconfigstore") > -1) - || (ste[i].getClassName().toLowerCase() - .indexOf("argblock") > -1) - || (ste[i].getClassName().toLowerCase() - .indexOf("debug") > -1) - || (ste[i].getMethodName().toLowerCase() - .indexOf("trace") > -1)) - i++; - - if (i < ste.length) { - fileAndLine = ste[i].getFileName() + ":" - + ste[i].getLineNumber(); - method = ste[i].getMethodName() + "()"; - } - - callerinfo = fileAndLine + ":" + method + " "; + Throwable tr = new Throwable(); + StackTraceElement ste[] = tr.getStackTrace(); + int i=0; + while ((i < ste.length) && + (ste[i].getMethodName().toLowerCase().indexOf("debug") >-1) || + (ste[i].getMethodName().toLowerCase().indexOf("hashkey") >-1) || + (ste[i].getClassName().toLowerCase().indexOf("propconfigstore") >-1) || + (ste[i].getClassName().toLowerCase().indexOf("argblock") >-1) || + (ste[i].getClassName().toLowerCase().indexOf("debug") >-1) || + (ste[i].getMethodName().toLowerCase().indexOf("trace") >-1)) i++; + + if (i < ste.length) { + fileAndLine = ste[i].getFileName()+":"+ + ste[i].getLineNumber(); + method = ste[i].getMethodName()+"()"; + } + + callerinfo = fileAndLine +":"+ method + " "; } catch (Exception f) { } } - - outputTraceMessage(callerinfo + t); + + outputTraceMessage(callerinfo + t); } } - - private static void outputTraceMessage(String t) { - if (!TRACE_ON) - return; - SimpleDateFormat d = getDateFormatter(); + + private static void outputTraceMessage(String t) + { + if (!TRACE_ON) return; + SimpleDateFormat d = getDateFormatter(); if (mOut != null && d != null) { - mOut.println("[" + d.format(new Date()) + "][" - + Thread.currentThread().getName() + "]: " + t); + mOut.println("[" + d.format(new Date()) + "][" + Thread.currentThread().getName() + "]: " + t); mOut.flush(); - } - } + } + } - private static boolean hkdotype(String type) { - if (mHK != null && mHK.get(type) != null) { - return true; - } else { - return false; - } - } + private static boolean hkdotype(String type) + { + if (mHK!= null && mHK.get(type) != null) { + return true; + } else { + return false; + } + } public static void traceHashKey(String type, String key) { - if (hkdotype(type)) { - trace("GET r=" + type + ",k=" + key); + if (hkdotype(type)) { + trace("GET r=" + type+ ",k=" + key); } } public static void traceHashKey(String type, String key, String val) { - if (hkdotype(type)) { - trace("GET r=" + type + ",k=" + key + ",v=" + val); + if (hkdotype(type)) { + trace("GET r=" + type+ ",k=" + key + ",v=" + val); } } - public static void traceHashKey(String type, String key, String val, - String def) { - if (hkdotype(type)) { - trace("GET r=" + type + ",k=" + key + ",v=" + val + ",d=" + def); + public static void traceHashKey(String type, String key, String val, String def) { + if (hkdotype(type)) { + trace("GET r=" + type+ ",k=" + + key + ",v=" + val +",d="+def); } - } + } public static void putHashKey(String type, String key, String value) { - if (hkdotype(type)) { - outputTraceMessage("PUT r=" + type + ",k=" + key + ",v=" + value); + if (hkdotype(type)) { + outputTraceMessage("PUT r=" + type+ ",k=" + key + ",v=" + value); } } @@ -199,8 +188,7 @@ public class Debug implements ISubsystem { } public static void print(int level, String t) { - if (!TRACE_ON) - return; + if (!TRACE_ON) return; if (mOut != null) { if (level >= mDebugLevel) mOut.print(t); @@ -212,30 +200,24 @@ public class Debug implements ISubsystem { } private static void printNybble(byte b) { - if (mOut == null) - return; - if (b < 10) - mOut.write('0' + b); - else - mOut.write('a' + b - 10); + if (mOut == null) return; + if (b < 10) mOut.write('0' + b); + else mOut.write('a' + b - 10); } /** - * If tracing enabled, dump a byte array to debugging printstream as hex, - * colon-seperated bytes, 16 bytes to a line + * If tracing enabled, dump a byte array to debugging printstream + * as hex, colon-seperated bytes, 16 bytes to a line */ public static void print(byte[] b) { - if (!TRACE_ON) - return; - if (mOut == null) - return; + if (!TRACE_ON) return; + if (mOut == null) return; for (int i = 0; i < b.length; i++) { printNybble((byte) ((b[i] & 0xf0) >> 4)); printNybble((byte) (b[i] & 0x0f)); mOut.print(" "); - if (((i % 16) == 15) && i != b.length) - mOut.println(""); + if (((i % 16) == 15) && i != b.length) mOut.println(""); } mOut.println(""); mOut.flush(); @@ -245,35 +227,29 @@ public class Debug implements ISubsystem { * Print the current stack trace to the debug printstream */ public static void printStackTrace() { - if (!TRACE_ON) - return; + if (!TRACE_ON) return; Exception e = new Exception("Debug"); printStackTrace(e); } /** - * Print the stack trace of the named exception to the debug printstream + * Print the stack trace of the named exception + * to the debug printstream */ public static void printStackTrace(Throwable e) { - if (!TRACE_ON) - return; - if (mOut == null) - return; + if (!TRACE_ON) return; + if (mOut == null) return; e.printStackTrace(mOut); } /** - * Set the current debugging level. You can use: - * - * <pre> + * Set the current debugging level. You can use: <pre> * OBNOXIOUS = 10 * VERBOSE = 5 * INFORM = 1 - * </pre> - * - * Or another value + * </pre> Or another value */ public static void setLevel(int level) { @@ -287,15 +263,15 @@ public class Debug implements ISubsystem { /** * Test if debugging is on. Do NOT write to System.out in your debug code */ - public static boolean on() { + public static boolean on() { return TRACE_ON; } - /* ISubsystem methods: */ + /* ISubsystem methods: */ public static String ID = "debug"; private static IConfigStore mConfig = null; - + public String getId() { return ID; } @@ -312,10 +288,8 @@ public class Debug implements ISubsystem { private static final String PROP_APPEND = "append"; /** - * Debug subsystem initialization. This subsystem is usually given the - * following parameters: - * - * <pre> + * Debug subsystem initialization. This subsystem is usually + * given the following parameters: <pre> * debug.enabled : (true|false) default false * debug.filename : can be a pathname, or STDOUT * debug.hashkeytypes: comma-separated list of hashkey types @@ -327,7 +301,7 @@ public class Debug implements ISubsystem { mConfig = config; String filename = null; String hashkeytypes = null; - boolean append = true; + boolean append=true; try { TRACE_ON = mConfig.getBoolean(PROP_ENABLED, false); @@ -344,32 +318,32 @@ public class Debug implements ISubsystem { if (filename.equals("STDOUT")) { mOut = System.out; } else { - if (!Utils.isNT()) { + if( !Utils.isNT() ) { // Always insure that a physical file exists! - Utils.exec("touch " + filename); - Utils.exec("chmod 00640 " + filename); + Utils.exec( "touch " + filename ); + Utils.exec( "chmod 00640 " + filename ); } OutputStream os = new FileOutputStream(filename, append); - mOut = new PrintStream(os, true); /* true == autoflush */ + mOut = new PrintStream(os, true); /* true == autoflush */ } if (hashkeytypes != null) { - StringTokenizer st = new StringTokenizer(hashkeytypes, ",", - false); - mHK = new Hashtable(); - while (st.hasMoreElements()) { - String hkr = st.nextToken(); - mHK.put(hkr, "true"); - } + StringTokenizer st = new StringTokenizer(hashkeytypes, + ",", false); + mHK = new Hashtable(); + while (st.hasMoreElements()) { + String hkr = st.nextToken(); + mHK.put(hkr, "true"); + } } } - outputTraceMessage("============================================"); - outputTraceMessage("===== DEBUG SUBSYSTEM INITIALIZED ======="); - outputTraceMessage("============================================"); + outputTraceMessage("============================================"); + outputTraceMessage("===== DEBUG SUBSYSTEM INITIALIZED ======="); + outputTraceMessage("============================================"); int level = mConfig.getInteger(PROP_LEVEL, VERBOSE); setLevel(level); } catch (Exception e) { // Don't do anything. Logging is not set up yet, and - // we can't write to STDOUT. + // we can't write to STDOUT. } } @@ -390,3 +364,4 @@ public class Debug implements ISubsystem { } } + diff --git a/pki/base/common/src/com/netscape/cmscore/util/ExceptionFormatter.java b/pki/base/common/src/com/netscape/cmscore/util/ExceptionFormatter.java index 861f8c68..8479c757 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/ExceptionFormatter.java +++ b/pki/base/common/src/com/netscape/cmscore/util/ExceptionFormatter.java @@ -17,19 +17,21 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.PrintWriter; + public class ExceptionFormatter { /** - * Routines for pretty-printing java exceptions prints okay in a - * single-line. + * Routines for pretty-printing java exceptions + * prints okay in a single-line. */ /* - * Take an exception stacktrace, and reformat it so that is prints okay in a - * single-line. + * Take an exception stacktrace, and reformat it so that is + * prints okay in a single-line. */ public static String getStackTraceAsString(Throwable e) { @@ -37,7 +39,7 @@ public class ExceptionFormatter { try { PipedOutputStream po = new PipedOutputStream(); - PipedInputStream pi = new PipedInputStream(po); + PipedInputStream pi = new PipedInputStream(po); PrintWriter ps = new PrintWriter(po); @@ -46,7 +48,7 @@ public class ExceptionFormatter { int avail = pi.available(); byte[] b = new byte[avail]; - + pi.read(b, 0, avail); returnvalue = new String(b); } catch (Exception ex) { @@ -57,7 +59,8 @@ public class ExceptionFormatter { /* test code below */ - public static void test() throws TestException { + public static void test() + throws TestException { throw new TestException("** testexception **"); } @@ -76,6 +79,7 @@ public class ExceptionFormatter { } + class TestException extends Exception { /** @@ -91,3 +95,4 @@ class TestException extends Exception { } } + diff --git a/pki/base/common/src/com/netscape/cmscore/util/FileAsString.java b/pki/base/common/src/com/netscape/cmscore/util/FileAsString.java index 1446a451..c0ae1faa 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/FileAsString.java +++ b/pki/base/common/src/com/netscape/cmscore/util/FileAsString.java @@ -17,22 +17,25 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; + public class FileAsString { protected String mFilename; protected long mLastRead = 0; - + private String fileContents = null; private Object userObject = null; - + /** - * This class enables you to get treat a file as a string If the file - * changes underneath you, it will automatically be read + * This class enables you to get treat a file as a string + * If the file changes underneath you, it will automatically + * be read */ public FileAsString(String filename) throws IOException { mFilename = filename; @@ -46,7 +49,8 @@ public class FileAsString { return (lastmodified != mLastRead); } - private void readFile() throws IOException { + private void readFile() + throws IOException { BufferedReader br = createBufferedReader(mFilename); StringBuffer buf = new StringBuffer(""); int bytesread = 0; @@ -59,14 +63,15 @@ public class FileAsString { buf.append(cbuf, 0, bytesread); } String s = new String(buf); - } while (bytesread != -1); + } + while (bytesread != -1); br.close(); fileContents = new String(buf); } - - private BufferedReader createBufferedReader(String filename) - throws IOException { + + private BufferedReader createBufferedReader(String filename) + throws IOException { Debug.trace("createBufferedReader(filename=" + filename + ")"); BufferedReader br = null; FileReader fr = null; @@ -79,12 +84,13 @@ public class FileAsString { br = new BufferedReader(fr); mFilename = filename; } catch (IOException e) { - throw e; + throw e; } return br; } - - public String getAsString() throws IOException { + + public String getAsString() + throws IOException { if (fileHasChanged()) { readFile(); } @@ -105,9 +111,9 @@ public class FileAsString { public void setUserObject(Object x) { userObject = x; } - + public String getFilename() { return mFilename; } - + } diff --git a/pki/base/common/src/com/netscape/cmscore/util/FileDialogFilter.java b/pki/base/common/src/com/netscape/cmscore/util/FileDialogFilter.java index 1277a8da..37410533 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/FileDialogFilter.java +++ b/pki/base/common/src/com/netscape/cmscore/util/FileDialogFilter.java @@ -17,18 +17,20 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.io.File; import java.io.FilenameFilter; + /** - * checks the filename and directory with the specified filter checks with - * multiple "*". the filter has to start with a '*' character. this to keep the - * search the same as in the motif version + * checks the filename and directory with the specified filter + * checks with multiple "*". + * the filter has to start with a '*' character. + * this to keep the search the same as in the motif version * <P> - * Copied verbatium from sun.awt.tiny.TinyFileDialogPeer. Used by RollingLogFile - * expiration code + * Copied verbatium from sun.awt.tiny.TinyFileDialogPeer. Used by + * RollingLogFile expiration code * <P> - * * @author mikep * @version $Revision$, $Date$ */ @@ -48,25 +50,25 @@ public class FileDialogFilter implements FilenameFilter { * return true if match */ public boolean accept(File dir, String fileName) { - + File f = new File(dir, fileName); - + if (f.isDirectory()) { return true; } else { return searchPattern(fileName, filter); } } - - /** - * start searching + + /** + * start searching */ boolean searchPattern(String fileName, String filter) { int filterCursor = 0; int fileNameCursor = 0; int filterChar = filter.charAt(filterCursor); - + if (filterCursor == 0 && filterChar != '*') { return false; } @@ -83,17 +85,17 @@ public class FileDialogFilter implements FilenameFilter { int flLen = fileName.length(); char ftChar; char flChar; - int ftCur = 0; - int flCur = 0; + int ftCur = 0; + int flCur = 0; int c = 0; - + if (ftLen == 0) { return true; } while (c < flLen) { - ftChar = filter.charAt(ftCur); - + ftChar = filter.charAt(ftCur); + if (ftChar == '*') { String ls = filter.substring(ftCur + 1); String fs = fileName.substring(flCur); @@ -107,11 +109,11 @@ public class FileDialogFilter implements FilenameFilter { continue; } flChar = fileName.charAt(flCur); - + if (ftChar == flChar) { ftCur++; flCur++; - + if (flCur == flLen && ftCur == ftLen) { return true; } @@ -132,9 +134,9 @@ public class FileDialogFilter implements FilenameFilter { } } } - + for (int i = ftCur; i < ftLen; i++) { - ftChar = filter.charAt(i); + ftChar = filter.charAt(i); if (ftChar != '*') { return false; } @@ -142,3 +144,4 @@ public class FileDialogFilter implements FilenameFilter { return true; } } + diff --git a/pki/base/common/src/com/netscape/cmscore/util/OsSubsystem.java b/pki/base/common/src/com/netscape/cmscore/util/OsSubsystem.java index 3f52bf6d..47bb6280 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/OsSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/util/OsSubsystem.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; @@ -36,12 +37,13 @@ import com.netscape.osutil.Signal; import com.netscape.osutil.SignalListener; import com.netscape.osutil.UserID; + /** - * This object contains the OS independent interfaces. It's currently used for - * Unix signal and user handling, but could eventually be extended for NT - * interfaces. + * This object contains the OS independent interfaces. It's currently + * used for Unix signal and user handling, but could eventually be extended + * for NT interfaces. * <P> - * + * * @author mikep * @version $Revision$, $Date$ */ @@ -81,20 +83,20 @@ public final class OsSubsystem implements ISubsystem { } public void setId(String id) throws EBaseException { - throw new EBaseException( - CMS.getUserMessage("CMS_BASE_INVALID_OPERATION")); + throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_OPERATION")); } /** - * Initializes this subsystem with the given configuration store. + * Initializes this subsystem with the given configuration + * store. * <P> - * + * * @param owner owner of this subsystem * @param config configuration store * @exception EBaseException failed to initialize */ public void init(ISubsystem owner, IConfigStore config) - throws EBaseException { + throws EBaseException { mOwner = owner; mConfig = config; @@ -104,14 +106,13 @@ public final class OsSubsystem implements ISubsystem { // We currently only deal with Unix and NT if (isUnix()) { - // initUnix(); + //initUnix(); } else { initNT(); } try { - // System.out.println(" The dir I'm seeing is " + mInstanceDir); - String pidName = mInstanceDir + File.separator + "config" - + File.separator + "cert-pid"; + //System.out.println(" The dir I'm seeing is " + mInstanceDir); + String pidName = mInstanceDir + File.separator + "config" + File.separator + "cert-pid"; BufferedWriter pidOut = new BufferedWriter(new FileWriter(pidName)); int pid = OsSubsystem.getpid(); @@ -119,8 +120,8 @@ public final class OsSubsystem implements ISubsystem { pidOut.close(); OSUtil.getFileWriteLock(pidName); } catch (Exception e) { - // XX to stderr XXXXXX - // e.printStackTrace(); + //XX to stderr XXXXXX + //e.printStackTrace(); } } @@ -149,22 +150,20 @@ public final class OsSubsystem implements ISubsystem { fos.close(); } catch (IOException e) { - /* - * LogDoc - * + /*LogDoc + * * @phase start OS subsystem - * * @message OS: <exception thrown> */ mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, - ILogger.LL_FAILURE, "OS: " + e.toString()); + ILogger.LL_FAILURE, "OS: " + e.toString()); } } } /** - * Returns the process ID of the Certificate Server process. Works on Unix - * and NT. + * Returns the process ID of the Certificate Server process. Works + * on Unix and NT. */ public static int getpid() { if (isUnix()) { @@ -178,24 +177,24 @@ public final class OsSubsystem implements ISubsystem { * Hooks up unix signals. */ private void initUnix() throws EBaseException { - // Set up signal handling. We pretty much exit on anything - // Signal.watch(Signal.SIGHUP); + // Set up signal handling. We pretty much exit on anything + // Signal.watch(Signal.SIGHUP); // Signal.watch(Signal.SIGTERM); // Signal.watch(Signal.SIGINT); // mSignalThread = new SignalThread(); // mSignalThread.setDaemon(true); // mSignalThread.start(); - Signal.addSignalListener(Signal.SIGHUP, new SIGHUPListener(this)); - Signal.addSignalListener(Signal.SIGTERM, new SIGTERMListener(this)); - Signal.addSignalListener(Signal.SIGINT, new SIGINTListener(this)); + Signal.addSignalListener(Signal.SIGHUP, new SIGHUPListener(this)); + Signal.addSignalListener(Signal.SIGTERM, new SIGTERMListener(this)); + Signal.addSignalListener(Signal.SIGINT, new SIGINTListener(this)); /* Increase the maximum number of file descriptors */ - int i = mConfig.getInteger("maxFiles", + int i = mConfig.getInteger("maxFiles", ResourceLimit.getHardLimit(ResourceLimit.RLIMIT_NOFILE)); - ResourceLimit.setLimits(ResourceLimit.RLIMIT_NOFILE, i, - ResourceLimit.getHardLimit(ResourceLimit.RLIMIT_NOFILE)); + ResourceLimit.setLimits(ResourceLimit.RLIMIT_NOFILE, + i, ResourceLimit.getHardLimit(ResourceLimit.RLIMIT_NOFILE)); // write current pid to specified file String pf = mConfig.getString("pidFile", null); @@ -211,7 +210,7 @@ public final class OsSubsystem implements ISubsystem { } /** - * Used to change the process user id usually called after the appropriate + * Used to change the process user id usually called after the appropriate * network ports have been opened. */ public void setUserId() throws EBaseException { @@ -226,49 +225,42 @@ public final class OsSubsystem implements ISubsystem { // Change the userid to the prefered Unix user if (userid == null) { - /* - * LogDoc - * + /*LogDoc + * * @phase set user id - * * @arg0 default user id */ - mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, ILogger.LL_FAILURE, - "OS: No user id in config file. Running as {0}", id); + mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, + ILogger.LL_FAILURE, + "OS: No user id in config file. Running as {0}", id); } else { - Object[] params = { userid, id }; + Object[] params = {userid, id}; try { UserID.set(userid); } catch (IllegalArgumentException e) { - /* - * LogDoc - * + /*LogDoc + * * @phase set user id - * * @arg0 supplied user id in config - * * @arg1 default user id */ - mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, - ILogger.LL_FAILURE, - "OS: No such user as {0}. Running as {1}", params); + mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, + ILogger.LL_FAILURE, + "OS: No such user as {0}. Running as {1}", params); } catch (SecurityException e) { - /* - * LogDoc - * + /*LogDoc + * * @phase set user id - * * @arg0 supplied user id in config - * * @arg1 default user id */ mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, - ILogger.LL_FAILURE, - "OS: Can't change process uid to {0}. Running as {1}", - params); + ILogger.LL_FAILURE, + "OS: Can't change process uid to {0}. Running as {1}", + params); } } } @@ -277,8 +269,9 @@ public final class OsSubsystem implements ISubsystem { } /** - * Stops the watchdog. You need to call this if you want the server to - * really shutdown, otherwise the watchdog will just restart us. + * Stops the watchdog. You need to call this if you want the + * server to really shutdown, otherwise the watchdog will just + * restart us. * <P> */ public static void stop() { @@ -287,13 +280,13 @@ public final class OsSubsystem implements ISubsystem { Signal.send(LibC.getppid(), Signal.SIGTERM); } else { - /* - * LogDoc - * + /*LogDoc + * * @phase stop watchdog */ CMS.getLogger().log(ILogger.EV_SYSTEM, ILogger.S_OTHER, - ILogger.LL_INFO, "OS: stop the NT watchdog!"); + ILogger.LL_INFO, + "OS: stop the NT watchdog!"); } } @@ -316,16 +309,15 @@ public final class OsSubsystem implements ISubsystem { private static void shutdownUnix() { // Don't accidentally stop this thread - // if (Thread.currentThread() != mSignalThread && mSignalThread != null) - // { - // mSignalThread.stop(); - // mSignalThread = null; - // } - - /* - * Don't release this signals to protect the process - * Signal.release(Signal.SIGHUP); Signal.release(Signal.SIGTERM); - * Signal.release(Signal.SIGINT); + //if (Thread.currentThread() != mSignalThread && mSignalThread != null) { + // mSignalThread.stop(); + // mSignalThread = null; + //} + + /* Don't release this signals to protect the process + Signal.release(Signal.SIGHUP); + Signal.release(Signal.SIGTERM); + Signal.release(Signal.SIGINT); */ } @@ -343,7 +335,11 @@ public final class OsSubsystem implements ISubsystem { public void restart() { /** - * if (isUnix()) { restartUnix(); } else { restartNT(); } + if (isUnix()) { + restartUnix(); + } else { + restartNT(); + } **/ } @@ -368,7 +364,7 @@ public final class OsSubsystem implements ISubsystem { /** * Returns the root configuration storage of this system. * <P> - * + * * @return configuration store of this subsystem */ public IConfigStore getConfigStore() { @@ -376,11 +372,10 @@ public final class OsSubsystem implements ISubsystem { } /** - * A universal routine to decide if we are Unix or something else. This is - * mostly used for signal handling and uids. - * + * A universal routine to decide if we are Unix or something else. + * This is mostly used for signal handling and uids. + * * <P> - * * @return true if these OS the JavaVM is running on is some Unix varient */ public static boolean isUnix() { @@ -389,8 +384,8 @@ public final class OsSubsystem implements ISubsystem { } /** - * Unix signal thread. Sleep for a second and then check on the signals - * we're interested in. If one is set, do the right stuff + * Unix signal thread. Sleep for a second and then check on the + * signals we're interested in. If one is set, do the right stuff */ final class SignalThread extends Thread { @@ -419,16 +414,17 @@ public final class OsSubsystem implements ISubsystem { } // wants us to exit? - if (Signal.caught(Signal.SIGINT) > 0 - || Signal.caught(Signal.SIGTERM) > 0) { + if (Signal.caught(Signal.SIGINT) > 0 || + Signal.caught(Signal.SIGTERM) > 0) { - /* - * LogDoc - * + /*LogDoc + * * @phase watchdog check */ - mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, - ILogger.LL_INFO, "OS: Received shutdown signal"); + mLogger.log(ILogger.EV_SYSTEM, + ILogger.S_OTHER, + ILogger.LL_INFO, + "OS: Received shutdown signal"); SubsystemRegistry.getInstance().get("MAIN").shutdown(); return; } @@ -436,13 +432,14 @@ public final class OsSubsystem implements ISubsystem { // Tell to restart us if (Signal.caught(Signal.SIGHUP) > 0) { - /* - * LogDoc - * + /*LogDoc + * * @phase watchdog check */ - mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, - ILogger.LL_INFO, "OS: Received restart signal"); + mLogger.log(ILogger.EV_SYSTEM, + ILogger.S_OTHER, + ILogger.LL_INFO, + "OS: Received restart signal"); restart(); return; } @@ -453,9 +450,9 @@ public final class OsSubsystem implements ISubsystem { } } + class SIGTERMListener extends SignalListener { private OsSubsystem mOS; - public SIGTERMListener(OsSubsystem os) { mOS = os; } @@ -464,13 +461,13 @@ class SIGTERMListener extends SignalListener { System.out.println("SIGTERMListener process"); // XXX - temp, should call shutdown System.exit(0); - // PKIServer.getPKIServer().shutdown(); + //PKIServer.getPKIServer().shutdown(); } } + class SIGINTListener extends SignalListener { private OsSubsystem mOS; - public SIGINTListener(OsSubsystem os) { mOS = os; } @@ -479,13 +476,13 @@ class SIGINTListener extends SignalListener { System.out.println("SIGINTListener process"); // XXX - temp, should call shutdown System.exit(0); - // PKIServer.getPKIServer().shutdown(); + //PKIServer.getPKIServer().shutdown(); } } + class SIGHUPListener extends SignalListener { private OsSubsystem mOS; - public SIGHUPListener(OsSubsystem os) { mOS = os; } @@ -494,6 +491,6 @@ class SIGHUPListener extends SignalListener { System.out.println("SIGHUPListener process"); // XXX - temp, should call shutdown // System.exit(0); - // PKIServer.getPKIServer().shutdown(); + //PKIServer.getPKIServer().shutdown(); } } diff --git a/pki/base/common/src/com/netscape/cmscore/util/PFXUtils.java b/pki/base/common/src/com/netscape/cmscore/util/PFXUtils.java index 80912d7a..7cde72cc 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/PFXUtils.java +++ b/pki/base/common/src/com/netscape/cmscore/util/PFXUtils.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.io.ByteArrayOutputStream; import java.security.MessageDigest; import java.security.cert.X509Certificate; @@ -39,61 +40,71 @@ import org.mozilla.jss.pkix.primitive.PrivateKeyInfo; import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; + public class PFXUtils { /** * Creates a PKCS12 package. */ - public static byte[] createPFX(String pwd, X509Certificate x509cert, - byte privateKeyInfo[]) throws EBaseException { + public static byte[] createPFX(String pwd, X509Certificate x509cert, + byte privateKeyInfo[]) throws EBaseException { try { // add certificate SEQUENCE encSafeContents = new SEQUENCE(); - ASN1Value cert = new OCTET_STRING(x509cert.getEncoded()); + ASN1Value cert = new OCTET_STRING( + x509cert.getEncoded()); byte localKeyId[] = createLocalKeyId(x509cert); - SET certAttrs = createBagAttrs(x509cert.getSubjectDN().toString(), - localKeyId); + SET certAttrs = createBagAttrs( + x509cert.getSubjectDN().toString(), localKeyId); // attributes: user friendly name, Local Key ID - SafeBag certBag = new SafeBag(SafeBag.CERT_BAG, new CertBag( - CertBag.X509_CERT_TYPE, cert), certAttrs); + SafeBag certBag = new SafeBag(SafeBag.CERT_BAG, + new CertBag(CertBag.X509_CERT_TYPE, cert), + certAttrs); encSafeContents.addElement(certBag); // add key - org.mozilla.jss.util.Password pass = new org.mozilla.jss.util.Password( + org.mozilla.jss.util.Password pass = new + org.mozilla.jss.util.Password( pwd.toCharArray()); SEQUENCE safeContents = new SEQUENCE(); - PasswordConverter passConverter = new PasswordConverter(); + PasswordConverter passConverter = new + PasswordConverter(); // XXX - should generate salt - byte salt[] = { 0x01, 0x01, 0x01, 0x01 }; - PrivateKeyInfo pki = (PrivateKeyInfo) ASN1Util.decode( - PrivateKeyInfo.getTemplate(), privateKeyInfo); + byte salt[] = {0x01, 0x01, 0x01, 0x01}; + PrivateKeyInfo pki = (PrivateKeyInfo) + ASN1Util.decode(PrivateKeyInfo.getTemplate(), + privateKeyInfo); ASN1Value key = EncryptedPrivateKeyInfo.createPBE( - PBEAlgorithm.PBE_SHA1_DES3_CBC, pass, salt, 1, - passConverter, pki); - SET keyAttrs = createBagAttrs(x509cert.getSubjectDN().toString(), + PBEAlgorithm.PBE_SHA1_DES3_CBC, + pass, salt, 1, passConverter, pki); + SET keyAttrs = createBagAttrs( + x509cert.getSubjectDN().toString(), localKeyId); - SafeBag keyBag = new SafeBag(SafeBag.PKCS8_SHROUDED_KEY_BAG, key, + SafeBag keyBag = new SafeBag( + SafeBag.PKCS8_SHROUDED_KEY_BAG, key, keyAttrs); // ?? safeContents.addElement(keyBag); // build contents - AuthenticatedSafes authSafes = new AuthenticatedSafes(); + AuthenticatedSafes authSafes = new + AuthenticatedSafes(); authSafes.addSafeContents(safeContents); authSafes.addSafeContents(encSafeContents); - // authSafes.addEncryptedSafeContents( - // authSafes.DEFAULT_KEY_GEN_ALG, - // pass, null, 1, - // encSafeContents); + // authSafes.addEncryptedSafeContents( + // authSafes.DEFAULT_KEY_GEN_ALG, + // pass, null, 1, + // encSafeContents); PFX pfx = new PFX(authSafes); pfx.computeMacData(pass, null, 5); // ?? - ByteArrayOutputStream fos = new ByteArrayOutputStream(); + ByteArrayOutputStream fos = new + ByteArrayOutputStream(); pfx.encode(fos); pass.clear(); @@ -101,9 +112,9 @@ public class PFXUtils { // put final PKCS12 into volatile request return fos.toByteArray(); } catch (Exception e) { - throw new EBaseException(CMS.getUserMessage( - "CMS_BASE_INTERNAL_ERROR", - "Failed to create PKCS12 - " + e.toString())); + throw new EBaseException( + CMS.getUserMessage("CMS_BASE_INTERNAL_ERROR", + "Failed to create PKCS12 - " + e.toString())); } } @@ -111,7 +122,7 @@ public class PFXUtils { * Creates local key identifier. */ public static byte[] createLocalKeyId(X509Certificate cert) - throws EBaseException { + throws EBaseException { try { byte certDer[] = cert.getEncoded(); MessageDigest md = MessageDigest.getInstance("SHA"); @@ -119,9 +130,9 @@ public class PFXUtils { md.update(certDer); return md.digest(); } catch (Exception e) { - throw new EBaseException(CMS.getUserMessage( - "CMS_BASE_INTERNAL_ERROR", - "Failed to create Key ID - " + e.toString())); + throw new EBaseException( + CMS.getUserMessage("CMS_BASE_INTERNAL_ERROR", + "Failed to create Key ID - " + e.toString())); } } @@ -129,7 +140,7 @@ public class PFXUtils { * Creates bag attributes. */ public static SET createBagAttrs(String nickName, byte localKeyId[]) - throws EBaseException { + throws EBaseException { try { SET attrs = new SET(); SEQUENCE nickNameAttr = new SEQUENCE(); @@ -150,9 +161,9 @@ public class PFXUtils { attrs.addElement(localKeyAttr); return attrs; } catch (Exception e) { - throw new EBaseException(CMS.getUserMessage( - "CMS_BASE_INTERNAL_ERROR", "Failed to create Key Bag - " - + e.toString())); + throw new EBaseException( + CMS.getUserMessage("CMS_BASE_INTERNAL_ERROR", + "Failed to create Key Bag - " + e.toString())); } } } diff --git a/pki/base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java b/pki/base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java index 5a217203..2d8e63c9 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.awt.Frame; import java.awt.TextArea; import java.awt.event.MouseAdapter; @@ -38,9 +39,11 @@ import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IConfigStore; import com.netscape.certsrv.base.ISubsystem; + /** - * A class represents a internal subsystem. This subsystem can be loaded into - * cert server kernel to perform run time system profiling. + * A class represents a internal subsystem. This subsystem + * can be loaded into cert server kernel to perform + * run time system profiling. * <P> * * @author thomask @@ -79,30 +82,35 @@ public class ProfileSubsystem extends Frame implements ISubsystem, Runnable { } /** - * Initializes this subsystem with the given configuration store. It first - * initializes resident subsystems, and it loads and initializes loadable - * subsystem specified in the configuration store. + * Initializes this subsystem with the given + * configuration store. + * It first initializes resident subsystems, + * and it loads and initializes loadable + * subsystem specified in the configuration + * store. * <P> - * Note that individual subsystem should be initialized in a separated - * thread if it has dependency on the initialization of other subsystems. + * Note that individual subsystem should be + * initialized in a separated thread if + * it has dependency on the initialization + * of other subsystems. * <P> - * + * * @param owner owner of this subsystem * @param config configuration store */ public synchronized void init(ISubsystem owner, IConfigStore config) - throws EBaseException { + throws EBaseException { JTabbedPane tabPane = new JTabbedPane(); // general panel JPanel pane = new JPanel(); mTextArea = new TextArea(); - // mTextArea.setSize(500, 180); - // mGC = new JButton("GC"); - // pane.setLayout(new GridLayout(2, 1)); + // mTextArea.setSize(500, 180); + //mGC = new JButton("GC"); + // pane.setLayout(new GridLayout(2, 1)); pane.add(mTextArea); - // pane.add(mGC); + // pane.add(mGC); mTextArea.setEditable(false); tabPane.addTab("General", mTextArea); tabPane.setSelectedIndex(0); @@ -133,8 +141,9 @@ public class ProfileSubsystem extends Frame implements ISubsystem, Runnable { } /* - * Returns the root configuration storage of this system. <P> - * + * Returns the root configuration storage of this system. + * <P> + * * @return configuration store of this subsystem */ public IConfigStore getConfigStore() { @@ -143,16 +152,17 @@ public class ProfileSubsystem extends Frame implements ISubsystem, Runnable { public void updateGeneralPanel() { Runtime.getRuntime().gc(); - String text = "JDK VM Information " - + "\n" - + "Total Memory: " - + Runtime.getRuntime().totalMemory() - + "\n" - + "Used Memory: " - + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime() - .freeMemory()) + "\n" + "Free Memory: " - + Runtime.getRuntime().freeMemory() + "\n" - + "Number of threads: " + Thread.activeCount() + "\n"; + String text = + "JDK VM Information " + "\n" + + "Total Memory: " + + Runtime.getRuntime().totalMemory() + "\n" + + "Used Memory: " + + (Runtime.getRuntime().totalMemory() - + Runtime.getRuntime().freeMemory()) + "\n" + + "Free Memory: " + + Runtime.getRuntime().freeMemory() + "\n" + + "Number of threads: " + + Thread.activeCount() + "\n"; mTextArea.setText(text); } @@ -187,7 +197,7 @@ public class ProfileSubsystem extends Frame implements ISubsystem, Runnable { colNames.addElement("isCurrent"); colNames.addElement("isInterrupted"); colNames.addElement("isDaemon"); - + mThreadModel.setInfo(data, colNames); if (mThreadTable != null) { mThreadTable.setModel(mThreadModel); @@ -209,7 +219,8 @@ public class ProfileSubsystem extends Frame implements ISubsystem, Runnable { } } -class ThreadTableModel extends AbstractTableModel { + +class ThreadTableModel extends AbstractTableModel { /** * */ @@ -225,33 +236,34 @@ class ThreadTableModel extends AbstractTableModel { columnNames = _columnNames; } - public String getColumnName(int column) { - return columnNames.elementAt(column).toString(); - } + public String getColumnName(int column) { + return columnNames.elementAt(column).toString(); + } - public int getRowCount() { - return rowData.size(); - } + public int getRowCount() { + return rowData.size(); + } - public int getColumnCount() { - return columnNames.size(); - } + public int getColumnCount() { + return columnNames.size(); + } - public Object getValueAt(int row, int column) { - return ((Vector) rowData.elementAt(row)).elementAt(column); - } + public Object getValueAt(int row, int column) { + return ((Vector) rowData.elementAt(row)).elementAt(column); + } - public boolean isCellEditable(int row, int column) { - return false; - } + public boolean isCellEditable(int row, int column) { + return false; + } - public void setValueAt(Object value, int row, int column) { - ((Vector) rowData.elementAt(row)).setElementAt(value, column); - fireTableCellUpdated(row, column); + public void setValueAt(Object value, int row, int column) { + ((Vector) rowData.elementAt(row)).setElementAt(value, column); + fireTableCellUpdated(row, column); } } -class ThreadTableEvent extends MouseAdapter { + +class ThreadTableEvent extends MouseAdapter { private JTable mThreadTable = null; @@ -259,8 +271,8 @@ class ThreadTableEvent extends MouseAdapter { mThreadTable = table; } - public void mouseClicked(MouseEvent e) { - if (e.getClickCount() == 2) { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { int row = mThreadTable.getSelectedRow(); if (row != -1) { @@ -271,23 +283,23 @@ class ThreadTableEvent extends MouseAdapter { field.setEditable(false); - // get stack trace + // get stack trace Thread threads[] = new Thread[100]; int numThreads = Thread.enumerate(threads); - ByteArrayOutputStream outArray = new ByteArrayOutputStream(); + ByteArrayOutputStream outArray = new ByteArrayOutputStream(); for (int i = 0; i < numThreads; i++) { if (!threads[i].getName().equals(name)) continue; - PrintStream err = System.err; + PrintStream err = System.err; System.setErr(new PrintStream(outArray)); - // TODO remove. This was being called on the array object - // But you can only dump stack on the current thread - Thread.dumpStack(); - - System.setErr(err); + //TODO remove. This was being called on the array object + //But you can only dump stack on the current thread + Thread.dumpStack(); + + System.setErr(err); } String str = outArray.toString(); @@ -300,7 +312,7 @@ class ThreadTableEvent extends MouseAdapter { dialog.setContentPane(pane); dialog.show(); } - } + } } } diff --git a/pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java b/pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java index 809415ff..4cc393e0 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/util/StatsSubsystem.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.util.Date; import java.util.Hashtable; import java.util.Vector; @@ -29,14 +30,16 @@ import com.netscape.certsrv.util.IStatsSubsystem; import com.netscape.certsrv.util.StatsEvent; /** - * A class represents a internal subsystem. This subsystem can be loaded into - * cert server kernel to perform statistics collection. + * A class represents a internal subsystem. This subsystem + * can be loaded into cert server kernel to perform + * statistics collection. * <P> * * @author thomask * @version $Revision$, $Date$ */ -public class StatsSubsystem implements IStatsSubsystem { +public class StatsSubsystem implements IStatsSubsystem +{ private String mId = null; private StatsEvent mAllTrans = new StatsEvent(null); private Date mStartTime = new Date(); @@ -61,90 +64,101 @@ public class StatsSubsystem implements IStatsSubsystem { } /** - * Initializes this subsystem with the given configuration store. It first - * initializes resident subsystems, and it loads and initializes loadable - * subsystem specified in the configuration store. + * Initializes this subsystem with the given + * configuration store. + * It first initializes resident subsystems, + * and it loads and initializes loadable + * subsystem specified in the configuration + * store. * <P> - * Note that individual subsystem should be initialized in a separated - * thread if it has dependency on the initialization of other subsystems. + * Note that individual subsystem should be + * initialized in a separated thread if + * it has dependency on the initialization + * of other subsystems. * <P> - * + * * @param owner owner of this subsystem * @param config configuration store */ public synchronized void init(ISubsystem owner, IConfigStore config) - throws EBaseException { - } - - public Date getStartTime() { - return mStartTime; - } - - public void startTiming(String id) { - startTiming(id, false /* not the main */); - } - - public void startTiming(String id, boolean mainAction) { - Thread t = Thread.currentThread(); - Vector milestones = null; - if (mHashtable.containsKey(t.toString())) { - milestones = (Vector) mHashtable.get(t.toString()); - } else { - milestones = new Vector(); - mHashtable.put(t.toString(), milestones); - } - long startTime = CMS.getCurrentDate().getTime(); - StatsEvent currentST = null; - for (int i = 0; i < milestones.size(); i++) { - StatsMilestone se = (StatsMilestone) milestones.elementAt(i); - if (currentST == null) { - currentST = mAllTrans.getSubEvent(se.getId()); - } else { - currentST = currentST.getSubEvent(se.getId()); - } - } + throws EBaseException + { + } + + public Date getStartTime() + { + return mStartTime; + } + + public void startTiming(String id) + { + startTiming(id, false /* not the main */); + } + + public void startTiming(String id, boolean mainAction) + { + Thread t = Thread.currentThread(); + Vector milestones = null; + if (mHashtable.containsKey(t.toString())) { + milestones = (Vector)mHashtable.get(t.toString()); + } else { + milestones = new Vector(); + mHashtable.put(t.toString(), milestones); + } + long startTime = CMS.getCurrentDate().getTime(); + StatsEvent currentST = null; + for (int i = 0; i < milestones.size(); i++) { + StatsMilestone se = (StatsMilestone)milestones.elementAt(i); if (currentST == null) { - if (!mainAction) { - return; /* ignore none main action */ - } - currentST = mAllTrans; - } - StatsEvent newST = currentST.getSubEvent(id); - if (newST == null) { - newST = new StatsEvent(currentST); - newST.setName(id); - currentST.addSubEvent(newST); - } - milestones.addElement(new StatsMilestone(id, startTime, newST)); - } - - public void endTiming(String id) { - long endTime = CMS.getCurrentDate().getTime(); - Thread t = Thread.currentThread(); - if (!mHashtable.containsKey(t.toString())) { - return; /* error */ - } - Vector milestones = (Vector) mHashtable.get(t.toString()); - if (milestones.size() == 0) { - return; /* error */ - } - StatsMilestone last = (StatsMilestone) milestones.remove(milestones - .size() - 1); - StatsEvent st = last.getStatsEvent(); - st.incNoOfOperations(1); - st.incTimeTaken(endTime - last.getStartTime()); - if (milestones.size() == 0) { - mHashtable.remove(t.toString()); + currentST = mAllTrans.getSubEvent(se.getId()); + } else { + currentST = currentST.getSubEvent(se.getId()); } - } - - public void resetCounters() { - mStartTime = CMS.getCurrentDate(); - mAllTrans.resetCounters(); - } - - public StatsEvent getMainStatsEvent() { - return mAllTrans; + } + if (currentST == null) { + if (!mainAction) { + return; /* ignore none main action */ + } + currentST = mAllTrans; + } + StatsEvent newST = currentST.getSubEvent(id); + if (newST == null) { + newST = new StatsEvent(currentST); + newST.setName(id); + currentST.addSubEvent(newST); + } + milestones.addElement(new StatsMilestone(id, startTime, newST)); + } + + public void endTiming(String id) + { + long endTime = CMS.getCurrentDate().getTime(); + Thread t = Thread.currentThread(); + if (!mHashtable.containsKey(t.toString())) { + return; /* error */ + } + Vector milestones = (Vector)mHashtable.get(t.toString()); + if (milestones.size() == 0) { + return; /* error */ + } + StatsMilestone last = (StatsMilestone)milestones.remove(milestones.size() - 1); + StatsEvent st = last.getStatsEvent(); + st.incNoOfOperations(1); + st.incTimeTaken(endTime - last.getStartTime()); + if (milestones.size() == 0) { + mHashtable.remove(t.toString()); + } + } + + public void resetCounters() + { + mStartTime = CMS.getCurrentDate(); + mAllTrans.resetCounters(); + } + + public StatsEvent getMainStatsEvent() + { + return mAllTrans; } public void startup() throws EBaseException { @@ -157,8 +171,9 @@ public class StatsSubsystem implements IStatsSubsystem { } /* - * Returns the root configuration storage of this system. <P> - * + * Returns the root configuration storage of this system. + * <P> + * * @return configuration store of this subsystem */ public IConfigStore getConfigStore() { @@ -166,26 +181,31 @@ public class StatsSubsystem implements IStatsSubsystem { } } -class StatsMilestone { - private String mId = null; - private long mStartTime = 0; - private StatsEvent mST = null; - - public StatsMilestone(String id, long startTime, StatsEvent st) { - mId = id; - mStartTime = startTime; - mST = st; - } - - public String getId() { - return mId; - } - - public long getStartTime() { - return mStartTime; - } - - public StatsEvent getStatsEvent() { - return mST; - } +class StatsMilestone +{ + private String mId = null; + private long mStartTime = 0; + private StatsEvent mST = null; + + public StatsMilestone(String id, long startTime, StatsEvent st) + { + mId = id; + mStartTime = startTime; + mST = st; + } + + public String getId() + { + return mId; + } + + public long getStartTime() + { + return mStartTime; + } + + public StatsEvent getStatsEvent() + { + return mST; + } } diff --git a/pki/base/common/src/com/netscape/cmscore/util/UtilMessage.java b/pki/base/common/src/com/netscape/cmscore/util/UtilMessage.java index f6814aee..a69a976c 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/UtilMessage.java +++ b/pki/base/common/src/com/netscape/cmscore/util/UtilMessage.java @@ -17,14 +17,16 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.util.Locale; import com.netscape.certsrv.base.MessageFormatter; + /** - * This object is used to easily create I18N messages for utility classes and - * standalone programs. - * + * This object is used to easily create I18N messages for utility + * classes and standalone programs. + * * @author mikep * @version $Revision$, $Date$ * @see com.netscape.certsrv.base.MessageFormatter @@ -44,7 +46,7 @@ public class UtilMessage { /** * Constructs a message event * <P> - * + * * @param msgFormat the message string */ public UtilMessage(String msgFormat) { @@ -54,12 +56,11 @@ public class UtilMessage { /** * Constructs a message with a parameter. For example, - * * <PRE> - * new UtilMessage("failed to load {0}", fileName); + * new UtilMessage("failed to load {0}", fileName); * </PRE> * <P> - * + * * @param msgFormat details in message string format * @param param message string parameter */ @@ -70,9 +71,9 @@ public class UtilMessage { } /** - * Constructs a message from an exception. It can be used to carry a system - * exception that may contain information about the context. For example, - * + * Constructs a message from an exception. It can be used to carry + * a system exception that may contain information about + * the context. For example, * <PRE> * try { * ... @@ -81,7 +82,7 @@ public class UtilMessage { * } * </PRE> * <P> - * + * * @param msgFormat exception details in message string format * @param exception system exception */ @@ -94,7 +95,6 @@ public class UtilMessage { /** * Constructs a message from a base exception. This will use the msgFormat * from the exception itself. - * * <PRE> * try { * ... @@ -103,7 +103,7 @@ public class UtilMessage { * } * </PRE> * <P> - * + * * @param exception CMS exception */ public UtilMessage(Exception e) { @@ -113,10 +113,10 @@ public class UtilMessage { } /** - * Constructs a message event with a list of parameters that will be - * substituted into the message format. + * Constructs a message event with a list of parameters + * that will be substituted into the message format. * <P> - * + * * @param msgFormat message string format * @param params list of message format parameters */ @@ -128,7 +128,7 @@ public class UtilMessage { /** * Returns the current message format string. * <P> - * + * * @return details message */ public String getMessage() { @@ -138,7 +138,7 @@ public class UtilMessage { /** * Returns a list of parameters. * <P> - * + * * @return list of message format parameters */ public Object[] getParameters() { @@ -146,10 +146,10 @@ public class UtilMessage { } /** - * Returns localized message string. This method should only be called if a - * localized string is necessary. + * Returns localized message string. This method should + * only be called if a localized string is necessary. * <P> - * + * * @return details message */ public String toString() { @@ -159,18 +159,19 @@ public class UtilMessage { /** * Returns the string based on the given locale. * <P> - * + * * @param locale locale * @return details message */ public String toString(Locale locale) { return MessageFormatter.getLocalizedString(locale, getBundleName(), - getMessage(), getParameters()); + getMessage(), + getParameters()); } /** - * Gets the resource bundle name for this class instance. This should be - * overridden by subclasses who have their own resource bundles. + * Gets the resource bundle name for this class instance. This should + * be overridden by subclasses who have their own resource bundles. */ protected String getBundleName() { return mBundleName; diff --git a/pki/base/common/src/com/netscape/cmscore/util/UtilResources.java b/pki/base/common/src/com/netscape/cmscore/util/UtilResources.java index c6297291..5892adc3 100644 --- a/pki/base/common/src/com/netscape/cmscore/util/UtilResources.java +++ b/pki/base/common/src/com/netscape/cmscore/util/UtilResources.java @@ -17,12 +17,14 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.util; + import java.util.ListResourceBundle; + /** * A class represents a resource bundle for miscellanous utilities * <P> - * + * * @author mikep * @version $Revision$, $Date$ * @see java.util.ListResourceBundle @@ -37,7 +39,8 @@ public class UtilResources extends ListResourceBundle { } /** - * Constants. The suffix represents the number of possible parameters. + * Constants. The suffix represents the number of + * possible parameters. */ public final static String HASH_FILE_CHECK_USAGE = "hashFileCheckUsage"; public final static String BAD_ARG_COUNT = "badArgCount"; @@ -54,20 +57,18 @@ public class UtilResources extends ListResourceBundle { public final static String RESTART_SIG = "restartSignal"; static final Object[][] contents = { - { HASH_FILE_CHECK_USAGE, "usage: HashFileCheck <filename>" }, - { BAD_ARG_COUNT, "incorrect number of arguments" }, - { NO_SUCH_FILE_1, "can''t find file {0}" }, - { FILE_TRUNCATED, "Log file has been truncated." }, - { DIGEST_MATCH_1, "Hash digest matches log file. {0} OK" }, - { - DIGEST_DONT_MATCH_1, - "Hash digest does NOT match log file. {0} and/or hash file is corrupt or the password is incorrect." }, - { EXCEPTION_1, "Caught unexpected exception {0}" }, - { LOG_PASSWORD, "Please enter the log file hash digest password: " }, - { NO_USERID, "No user id in config file. Running as {0}" }, - { NO_SUCH_USER_2, "No such user as {0}. Running as {1}" }, - { NO_UID_PERMISSION_2, - "Can''t change process uid to {0}. Running as {1}" }, - { SHUTDOWN_SIG, "Received shutdown signal" }, - { RESTART_SIG, "Received restart signal" }, }; + {HASH_FILE_CHECK_USAGE, "usage: HashFileCheck <filename>"}, + {BAD_ARG_COUNT, "incorrect number of arguments"}, + {NO_SUCH_FILE_1, "can''t find file {0}"}, + {FILE_TRUNCATED, "Log file has been truncated."}, + {DIGEST_MATCH_1, "Hash digest matches log file. {0} OK"}, + {DIGEST_DONT_MATCH_1, "Hash digest does NOT match log file. {0} and/or hash file is corrupt or the password is incorrect."}, + {EXCEPTION_1, "Caught unexpected exception {0}"}, + {LOG_PASSWORD, "Please enter the log file hash digest password: "}, + {NO_USERID, "No user id in config file. Running as {0}"}, + {NO_SUCH_USER_2, "No such user as {0}. Running as {1}"}, + {NO_UID_PERMISSION_2, "Can''t change process uid to {0}. Running as {1}"}, + {SHUTDOWN_SIG, "Received shutdown signal"}, + {RESTART_SIG, "Received restart signal"}, + }; } |