Add EventLog.getLogNames() method
This commit is contained in:
		
							parent
							
								
									3981cadde4
								
							
						
					
					
						commit
						82f7664068
					
				@ -1,3 +1,7 @@
 | 
				
			|||||||
 | 
					2007-01-18  Doug MacEachern  <dougm@hyperic.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        * Add EventLog.getLogNames() method
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2007-01-17  Doug MacEachern  <dougm@hyperic.com>
 | 
					2007-01-17  Doug MacEachern  <dougm@hyperic.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        * Various fixes for sparc64
 | 
					        * Various fixes for sparc64
 | 
				
			||||||
 | 
				
			|||||||
@ -117,4 +117,31 @@ public class EventLog extends Win32 {
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public native void waitForChange(int timeout)
 | 
					    public native void waitForChange(int timeout)
 | 
				
			||||||
        throws Win32Exception;
 | 
					        throws Win32Exception;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Eventlog names are store in the registry under:
 | 
				
			||||||
 | 
					     * SYSTEM\CurrentControlSet\Services\Eventlog
 | 
				
			||||||
 | 
					     * This method returns the list of these entries.
 | 
				
			||||||
 | 
					     * @return All Eventlog names
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static String[] getLogNames() {
 | 
				
			||||||
 | 
					        final String EVENTLOG_KEY =
 | 
				
			||||||
 | 
					            "SYSTEM\\CurrentControlSet\\Services\\Eventlog";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String[] names;
 | 
				
			||||||
 | 
					        RegistryKey key = null;
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            key = RegistryKey.LocalMachine.openSubKey(EVENTLOG_KEY);
 | 
				
			||||||
 | 
					            names = key.getSubKeyNames();
 | 
				
			||||||
 | 
					        } catch (Win32Exception e) {
 | 
				
			||||||
 | 
					            names =
 | 
				
			||||||
 | 
					                new String[] { SYSTEM, APPLICATION, SECURITY };
 | 
				
			||||||
 | 
					        } finally {
 | 
				
			||||||
 | 
					            if (key != null) {
 | 
				
			||||||
 | 
					                key.close();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return names;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -93,21 +93,27 @@ public class TestEventLog extends SigarTestCase {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private boolean readAll(String logname) throws Exception {
 | 
					    private boolean readAll(String logname) throws Exception {
 | 
				
			||||||
        int fail = 0, success = 0; 
 | 
					        int fail = 0, success = 0, max = 500;
 | 
				
			||||||
 | 
					        String testMax = System.getProperty("sigar.testeventlog.max");
 | 
				
			||||||
 | 
					        if (testMax != null) {
 | 
				
			||||||
 | 
					            max = Integer.parseInt(testMax);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        EventLogRecord record;
 | 
					        EventLogRecord record;
 | 
				
			||||||
        EventLog log = new EventLog();
 | 
					        EventLog log = new EventLog();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        log.open(logname);
 | 
					        log.open(logname);
 | 
				
			||||||
        int oldestRecord = log.getOldestRecord();
 | 
					        int oldestRecord = log.getOldestRecord();
 | 
				
			||||||
        int numRecords = log.getNumberOfRecords();
 | 
					        int numRecords = log.getNumberOfRecords();
 | 
				
			||||||
        traceln("oldest=" + oldestRecord + ", total=" + numRecords);
 | 
					        traceln("oldest=" + oldestRecord +
 | 
				
			||||||
 | 
					                ", total=" + numRecords +
 | 
				
			||||||
 | 
					                ", max=" + max);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int i = oldestRecord; i < oldestRecord + numRecords; i++) {
 | 
					        for (int i = oldestRecord; i < oldestRecord + numRecords; i++) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                record = log.read(i);
 | 
					                record = log.read(i);
 | 
				
			||||||
                success++;
 | 
					                success++;
 | 
				
			||||||
                if (!getVerbose() && (success > 500)) {
 | 
					                if (success > max) {
 | 
				
			||||||
                    break; //read plenty
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } catch (Win32Exception e) {
 | 
					            } catch (Win32Exception e) {
 | 
				
			||||||
                fail++;
 | 
					                fail++;
 | 
				
			||||||
@ -124,10 +130,7 @@ public class TestEventLog extends SigarTestCase {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Test reading all records
 | 
					    // Test reading all records
 | 
				
			||||||
    public void testRead() throws Exception {
 | 
					    public void testRead() throws Exception {
 | 
				
			||||||
        String[] logs = {
 | 
					        String[] logs = EventLog.getLogNames();
 | 
				
			||||||
            EventLog.SYSTEM,
 | 
					 | 
				
			||||||
            EventLog.APPLICATION
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
        for (int i=0; i<logs.length; i++) {
 | 
					        for (int i=0; i<logs.length; i++) {
 | 
				
			||||||
            String msg = "readAll(" + logs[i] + ")"; 
 | 
					            String msg = "readAll(" + logs[i] + ")"; 
 | 
				
			||||||
            traceln(msg);
 | 
					            traceln(msg);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user