# HG changeset patch # User kent # Date 1219844890 -32400 # Node ID 785a3e8ea858042410669ef9daaff9d7d97d33ad # Parent abaf502e6d8fa1fce29c8bb576977a4b38b20c8d *** empty log message *** diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/ChannelSimulator.java --- a/rep/channel/ChannelSimulator.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/ChannelSimulator.java Wed Aug 27 22:48:10 2008 +0900 @@ -18,8 +18,8 @@ public ChannelSimulator(NetworkSimulator
_ns){ this(_ns, null); } - - public ChannelSimulator(NetworkSimulator
_ns, SelectorSimulator
_selector){ + + public ChannelSimulator(NetworkSimulator
_ns, SelectorSimulator _selector){ super(null); ns = _ns; //ns = NetworkSimulator.singleton(); //どっちがいい? @@ -69,7 +69,7 @@ } public SelectionKey keyFor(Selector selector2) { - return ((SelectorSimulator
) selector2).getKey(this); + return ((SelectorSimulator) selector2).getKey(this); } @Override public Object blockingLock() { @@ -97,11 +97,17 @@ // TODO Auto-generated method stub return null; } + @SuppressWarnings("unchecked") @Override public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException { - // TODO Auto-generated method stub - return null; + SelectorSimulator selector = (SelectorSimulator) sel; + return selector.register(this, ops, att); } + public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { + REPSelector selector = sel; + return selector.register(this, ops, att); + } + @Override public int validOps() { // TODO Auto-generated method stub diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/NetworkSimulator.java --- a/rep/channel/NetworkSimulator.java Wed Aug 27 21:31:21 2008 +0900 +++ b/rep/channel/NetworkSimulator.java Wed Aug 27 22:48:10 2008 +0900 @@ -26,7 +26,7 @@ /* */ - synchronized public void listen(int ip, SelectorSimulator
selector) { + synchronized public void listen(int ip, SelectorSimulator selector) { serverList.add(new ServerData
(ip, selector)); writeLog(Thread.currentThread(), "listen", 1); printAllState(); @@ -113,11 +113,11 @@ class ServerData
{ int virtualIP; - SelectorSimulator
selector;
+ SelectorSimulator selector;
LinkedList _selector){
+ ServerData(int ip, SelectorSimulator _selector){
virtualIP = ip;
selector = _selector;
acceptWaitingList = new LinkedList create() throws IOException {
+ public static (null).open();
+ return new ServerChannelSimulatorImpl (open());
+ return new REPServerSocketChannel create() throws IOException {
if (REPServerSocketChannel.isSimulation) {
diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/SelectableChannelSimulator.java
--- a/rep/channel/SelectableChannelSimulator.java Wed Aug 27 21:31:21 2008 +0900
+++ b/rep/channel/SelectableChannelSimulator.java Wed Aug 27 22:48:10 2008 +0900
@@ -11,8 +11,8 @@
protected BlockingQueue qread;
protected BlockingQueue qwrite;
- protected SelectorSimulator writeSelector;
- protected SelectorSimulator readSelector;
+ protected SelectorSimulator writeSelector;
+ protected SelectorSimulator readSelector;
public SelectableChannelSimulator(SocketChannel channel) {
super(channel);
@@ -65,7 +65,7 @@
public void createWriteQ(){
qwrite = new LinkedBlockingQueue ();
}
- public void setWriteSelector(SelectorSimulator _selector){
+ public void setWriteSelector(SelectorSimulator _selector){
writeSelector = _selector;
}
diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/SelectionKeySimulator.java
--- a/rep/channel/SelectionKeySimulator.java Wed Aug 27 21:31:21 2008 +0900
+++ b/rep/channel/SelectionKeySimulator.java Wed Aug 27 22:48:10 2008 +0900
@@ -1,16 +1,17 @@
package rep.channel;
+import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
-public class SelectionKeySimulator extends SelectionKey{
+public class SelectionKeySimulator extends SelectionKey{
private int interestOpt;
- private SelectableChannelSimulator channel;
+ private SelectableChannel channel;
private int ready;
public Selector selector;
- public SelectionKeySimulator(SelectableChannelSimulator cs, int opt, Selector _selector) {
+ public SelectionKeySimulator(SelectableChannel cs, int opt, Selector _selector) {
channel = cs;
interestOpt = opt;
selector = _selector;
@@ -28,26 +29,26 @@
}
public void setFlag() {
+ SelectableChannelSimulator> scs = (SelectableChannelSimulator>) channel;
ready = 0;
- if(channel.isAcceptable()) ready |= OP_ACCEPT;
- if(channel.isReadable()) ready |= OP_READ;
- if(channel.isWritable()) ready |= OP_WRITE;
+ if(scs.isAcceptable()) ready |= OP_ACCEPT;
+ if(scs.isReadable()) ready |= OP_READ;
+ if(scs.isWritable()) ready |= OP_WRITE;
}
- public SelectableChannelSimulator channel() {
+ public SelectableChannel channel() {
return channel;
}
@Override
public void cancel() {
- // TODO Auto-generated method stub
-
+ System.err.println("cancel is not implemented yet.");
+ //selector.
}
@Override
public int interestOps() {
- // TODO Auto-generated method stub
return interestOpt;
}
@@ -69,7 +70,6 @@
@Override
public Selector selector() {
- // TODO Auto-generated method stub
return selector;
}
diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/SelectorSimulator.java
--- a/rep/channel/SelectorSimulator.java Wed Aug 27 21:31:21 2008 +0900
+++ b/rep/channel/SelectorSimulator.java Wed Aug 27 22:48:10 2008 +0900
@@ -12,7 +12,7 @@
-public class SelectorSimulator extends REPSelector{
+public class SelectorSimulator extends REPSelector{
private TreeSet cs, int opt){
+ public cs, int opt, Object handler){
+
+ public channel){
+ public _ns, SelectorSimulator rselector){
+ public ServerChannelSimulator(NetworkSimulator _ns, SelectorSimulator rselector){
super(null);
ns = _ns;
readSelector = rselector;
diff -r abaf502e6d8f -r 785a3e8ea858 rep/channel/ServerChannelSimulatorImpl.java
--- a/rep/channel/ServerChannelSimulatorImpl.java Wed Aug 27 21:31:21 2008 +0900
+++ b/rep/channel/ServerChannelSimulatorImpl.java Wed Aug 27 22:48:10 2008 +0900
@@ -41,9 +41,5 @@
// TODO Auto-generated method stub
}
-
- public REPServerSocketChannel open() {
- return new ServerChannelSimulatorImpl (null);
- }
}