Mercurial > hg > RemoteEditor > Eclipse
diff src/pathfinder/BlockingQnoSeMa/ChannelSimulator.java @ 83:3db21fae825a
pathfinder simulation without SessionManager
author | kent |
---|---|
date | Mon, 12 Nov 2007 17:53:48 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pathfinder/BlockingQnoSeMa/ChannelSimulator.java Mon Nov 12 17:53:48 2007 +0900 @@ -0,0 +1,52 @@ +package pathfinder.BlockingQnoSeMa; + +import java.util.concurrent.BlockingQueue; + +public class ChannelSimulator<P> { + private BlockingQueue<P> qread; + private BlockingQueue<P> qwrite; + + public ChannelSimulator(BlockingQueue<P> _a, BlockingQueue<P> _b){ + qread = _a; + qwrite = _b; + } + + public P read(){ + try { + return qread.take(); + } catch (InterruptedException e) { + e.printStackTrace(); + return null; + } + } + + public boolean write(P p){ + try { + qwrite.put(p); + return true; + } catch (InterruptedException e) { + e.printStackTrace(); + return false; + } + } + + public BlockingQueue<P> getReadQ(){ + return qread; + } + public BlockingQueue<P> getWriteQ(){ + return qwrite; + } + public void setReadQ(BlockingQueue<P> bq){ + qread = bq; + } + public void setWriteQ(BlockingQueue<P> bq){ + qwrite = bq; + } + + public boolean readQisEmpty() { + return qread.isEmpty(); + } + public boolean writeQisEmpty() { + return qwrite.isEmpty(); + } +}