Mercurial > hg > RemoteEditor > REPSessionManager
changeset 151:4ae9da03cf1e
*** empty log message ***
author | kono |
---|---|
date | Thu, 28 Aug 2008 15:05:14 +0900 |
parents | dce41e665edb |
children | 2ce1a378da85 |
files | rep/channel/NetworkSimulator.java rep/channel/REPLogger.java |
diffstat | 2 files changed, 31 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/channel/NetworkSimulator.java Thu Aug 28 14:39:34 2008 +0900 +++ b/rep/channel/NetworkSimulator.java Thu Aug 28 15:05:14 2008 +0900 @@ -3,13 +3,17 @@ import java.util.LinkedList; -public class NetworkSimulator<P> { +public class NetworkSimulator<P> extends REPLogger { public static NetworkSimulator<?> ns; - synchronized public static <T> NetworkSimulator<T> singleton(){ + + public static <T> NetworkSimulator<?> singleton(){ + // double check singleton if (ns==null) - ns = new NetworkSimulator<T>(); - return (NetworkSimulator<T>) ns; - // NetworkSimulator<Obj> ns = NetworkSimulator.singleton(new NetworkSimulator<Obj>()); + synchronized (NetworkSimulator.class) { + if (ns==null) + ns = new NetworkSimulator<T>(); + } + return ns; } int logLevel=5; @@ -92,22 +96,6 @@ } } - /** simulation log command */ - synchronized public void writeLog(String log, int level){ - if ( level<=logLevel ) - System.out.println(log); - System.out.flush(); - } - public void writeLog(String log){ - writeLog(log, 0); - } - public void writeLog(Thread thr, String log, int level){ - writeLog(thr.getName()+": "+log, level); - } - public void setLogLevel(int logLevel) { - this.logLevel = logLevel; - } - }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/channel/REPLogger.java Thu Aug 28 15:05:14 2008 +0900 @@ -0,0 +1,22 @@ +package rep.channel; + +public class REPLogger { + + private int logLevel; + /** simulation log command */ + synchronized public void writeLog(String log, int level){ + if ( level<=logLevel ) + System.out.println(log); + System.out.flush(); + } + public void writeLog(String log){ + writeLog(log, 0); + } + public void writeLog(Thread thr, String log, int level){ + writeLog(thr.getName()+": "+log, level); + } + public void setLogLevel(int logLevel) { + this.logLevel = logLevel; + } + +}