change getInstance to take arg for name of the log
This commit is contained in:
parent
3b91001651
commit
7d77935ffe
@ -20,21 +20,37 @@ public class EventLogThread implements Runnable {
|
|||||||
Logger.getLogger(EventLogThread.class.getName());
|
Logger.getLogger(EventLogThread.class.getName());
|
||||||
|
|
||||||
private Thread thread = null;
|
private Thread thread = null;
|
||||||
private static EventLogThread instance = null;
|
private static HashMap logs = new HashMap();
|
||||||
private boolean shouldDie = false;
|
private boolean shouldDie = false;
|
||||||
private Set notifiers = Collections.synchronizedSet(new HashSet());
|
private Set notifiers = Collections.synchronizedSet(new HashSet());
|
||||||
|
|
||||||
private String logName = "Application";
|
private String logName = "Application";
|
||||||
private long interval = 10 * 1000; // Default to 10 seconds
|
private long interval = 10 * 1000; // Default to 10 seconds
|
||||||
|
|
||||||
public static synchronized EventLogThread getInstance() {
|
public static synchronized EventLogThread getInstance(String name) {
|
||||||
|
EventLogThread instance =
|
||||||
|
(EventLogThread)logs.get(name);
|
||||||
|
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new EventLogThread();
|
instance = new EventLogThread();
|
||||||
|
instance.setLogName(name);
|
||||||
|
logs.put(name, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static synchronized void closeInstances() {
|
||||||
|
for (Iterator it = logs.values().iterator();
|
||||||
|
it.hasNext();)
|
||||||
|
{
|
||||||
|
EventLogThread eventLogThread =
|
||||||
|
(EventLogThread)it.next();
|
||||||
|
eventLogThread.doStop();
|
||||||
|
}
|
||||||
|
logs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void setInterval(long interval) {
|
public void setInterval(long interval) {
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
}
|
}
|
||||||
@ -140,7 +156,6 @@ public class EventLogThread implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
HashMap logs = new HashMap();
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
args = new String[] {
|
args = new String[] {
|
||||||
"System", "Application", "Security"
|
"System", "Application", "Security"
|
||||||
@ -161,13 +176,11 @@ public class EventLogThread implements Runnable {
|
|||||||
for (int i=0; i<args.length; i++) {
|
for (int i=0; i<args.length; i++) {
|
||||||
String name = args[i];
|
String name = args[i];
|
||||||
EventLogThread eventLogThread =
|
EventLogThread eventLogThread =
|
||||||
new EventLogThread();
|
EventLogThread.getInstance(name);
|
||||||
|
|
||||||
eventLogThread.setLogName(name);
|
|
||||||
eventLogThread.doStart();
|
eventLogThread.doStart();
|
||||||
eventLogThread.setInterval(1000);
|
eventLogThread.setInterval(1000);
|
||||||
eventLogThread.add(watcher);
|
eventLogThread.add(watcher);
|
||||||
logs.put(name, eventLogThread);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Press any key to stop");
|
System.out.println("Press any key to stop");
|
||||||
@ -175,12 +188,6 @@ public class EventLogThread implements Runnable {
|
|||||||
System.in.read();
|
System.in.read();
|
||||||
} catch (IOException e) { }
|
} catch (IOException e) { }
|
||||||
|
|
||||||
for (Iterator it = logs.values().iterator();
|
EventLogThread.closeInstances();
|
||||||
it.hasNext();)
|
|
||||||
{
|
|
||||||
EventLogThread eventLogThread =
|
|
||||||
(EventLogThread)it.next();
|
|
||||||
eventLogThread.doStop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user