# HG changeset patch
# User kent
# Date 1219995491 -32400
# Node ID 3c82100cdadd513c86cc89b0958315276c9d6295
# Parent eb89a73976fa6438f6bfd1ef5af56317dc64e273
*** empty log message ***
diff -r eb89a73976fa -r 3c82100cdadd rep/channel/REPPack.java
--- a/rep/channel/REPPack.java Fri Aug 29 13:40:29 2008 +0900
+++ b/rep/channel/REPPack.java Fri Aug 29 16:38:11 2008 +0900
@@ -1,9 +1,14 @@
package rep.channel;
+import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
public interface REPPack
{
- public abstract ByteBuffer packUConv(P command);
+ public ByteBuffer packUConv(P command);
+
+ public P unpackUConv(SocketChannel sc) throws IOException ;
+
}
\ No newline at end of file
diff -r eb89a73976fa -r 3c82100cdadd rep/channel/REPPacketSend.java
--- a/rep/channel/REPPacketSend.java Fri Aug 29 13:40:29 2008 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-package rep.channel;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-
-import rep.REPCommand;
-import rep.channel.REPPack;
-
-
-public class REPPacketSend implements REPPack {
- REPSocketChannel socketchannel;
- // JIS/S-JIS = 2, UTF-8 = 3, UTF-?? = 5
- final int CHAR_ORDER = 5;
-
- public REPPacketSend(REPSocketChannel channel){
- socketchannel = channel;
- }
-
- /* (non-Javadoc)
- * @see rep.REPPack#packUConv(rep.REPCommand)
- */
- public ByteBuffer packUConv(REPCommand command){
- System.out.println("send command byUTF8: " + command.toString());
- if(command.string == null){
- command.setString("test");
- }
- ByteBuffer buffer = ByteBuffer.allocateDirect(24+(command.string.length()*CHAR_ORDER));
- buffer.clear(); // position = 0
- buffer.putInt(command.cmd); buffer.putInt(command.sid); buffer.putInt(command.eid);
- buffer.putInt(command.seq); buffer.putInt(command.lineno);
-
- int pos = buffer.position();
- buffer.putInt(0);
-
- //Encode to UTF8
- CharBuffer cb = CharBuffer.wrap(command.string);
- Charset charset = Charset.forName("UTF-8");
- CharsetEncoder encoder = charset.newEncoder();
- try {
- encoder.encode(cb, buffer, true);
- } catch (IllegalStateException e) {
- e.printStackTrace();
- }
-
- //Encoded string length set
- int length = (buffer.position() -pos) -4;
- System.out.println("UTF-8: Set REPComand textlen(Byte) : " + (buffer.position() - pos-4));
- if(length < 0) {
- length = 0;
- }
- buffer.putInt(pos, length);
-
- buffer.limit(24+length);
- buffer.rewind();
-
- return buffer;
- }
-
- /* (non-Javadoc)
- * @see rep.REPPack#send(rep.REPCommand)
- */
- public void send(REPCommand command){
- try {
- //socketchannel.write(pack(command));
- socketchannel.write(packUConv(command));
- //System.out.println(command.toString());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-}
diff -r eb89a73976fa -r 3c82100cdadd rep/channel/REPSelectionKey.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rep/channel/REPSelectionKey.java Fri Aug 29 16:38:11 2008 +0900
@@ -0,0 +1,51 @@
+package rep.channel;
+
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+
+public class REPSelectionKey extends SelectionKey {
+
+ @Override
+ public void cancel() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public SelectableChannel channel() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int interestOps() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public SelectionKey interestOps(int ops) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isValid() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int readyOps() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public Selector selector() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff -r eb89a73976fa -r 3c82100cdadd rep/channel/REPSelector.java
--- a/rep/channel/REPSelector.java Fri Aug 29 13:40:29 2008 +0900
+++ b/rep/channel/REPSelector.java Fri Aug 29 16:38:11 2008 +0900
@@ -61,6 +61,12 @@
@Override
public Set selectedKeys() {
+ /*
+ Set keys = new HashSet();
+ for (SelectionKey key: selector.selectedKeys()){
+ keys.add(new SelectionKeySimulator(new REPSocketChannel>(), key.readyOps(), selector));
+ new SelectionKey();
+ }*/
return selector.selectedKeys();
}
diff -r eb89a73976fa -r 3c82100cdadd rep/channel/REPServerSocketChannel.java
--- a/rep/channel/REPServerSocketChannel.java Fri Aug 29 13:40:29 2008 +0900
+++ b/rep/channel/REPServerSocketChannel.java Fri Aug 29 16:38:11 2008 +0900
@@ -16,15 +16,16 @@
public static boolean isSimulation;
private ServerSocketChannel ss;
+ private REPPack packer;
- protected REPServerSocketChannel(SelectorProvider provider) {
+ /*protected REPServerSocketChannel(SelectorProvider provider) {
super(provider);
-
- }
+ }*/
- public REPServerSocketChannel(ServerSocketChannel channel){
+ public REPServerSocketChannel(ServerSocketChannel channel, REPPack
_packer){
super(null);
ss = channel;
+ packer = _packer;
}
public REPServerSocketChannel() {
@@ -32,16 +33,16 @@
}
- public static REPServerSocketChannel open() throws IOException{
+ public static REPServerSocketChannel open(REPPack packer) throws IOException{
if(isSimulation){
return new ServerChannelSimulator();
}else{
- return new REPServerSocketChannel(ServerSocketChannel.open());
+ return new REPServerSocketChannel(ServerSocketChannel.open(), packer);
}
}
public REPSocketChannel accept1() throws IOException {
- return new REPSocketChannel
(ss.accept());
+ return new REPSocketChannel
(ss.accept(), packer);
}
@Override
diff -r eb89a73976fa -r 3c82100cdadd rep/channel/REPSocketChannel.java
--- a/rep/channel/REPSocketChannel.java Fri Aug 29 13:40:29 2008 +0900
+++ b/rep/channel/REPSocketChannel.java Fri Aug 29 16:38:11 2008 +0900
@@ -9,26 +9,17 @@
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
-import java.nio.channels.ServerSocketChannel;
import java.nio.channels.spi.SelectorProvider;
public class REPSocketChannel
extends SelectableChannel{
private SocketChannel sc;
- private REPUnpack
unpack;
private REPPack
pack;
- public REPSocketChannel(SocketChannel channel) {
+ public REPSocketChannel(SocketChannel channel, REPPack
packer) {
sc = channel;
+ pack = packer;
}
-
- public void setUnpack(REPUnpack
_unpack){
- unpack = _unpack;
- }
- public void setPack(REPPack
_pack){
- pack = _pack;
- }
-
@Override
public Object blockingLock() {
@@ -96,7 +87,7 @@
}
public P read() throws IOException{
- return unpack.unpackUConv(sc);
+ return pack.unpackUConv(sc);
}
public boolean write(P p){
ByteBuffer bb = pack.packUConv(p);
@@ -110,11 +101,12 @@
}
}
- public static REPSocketChannel create() throws IOException {
+ public static REPSocketChannel create(REPPack packer) throws IOException {
if (REPServerSocketChannel.isSimulation) {
return new ChannelSimulator();
} else {
- return new REPSocketChannel(SocketChannel.open());
+ REPSocketChannel rsc = new REPSocketChannel(SocketChannel.open(), packer);
+ return rsc;
}
}
diff -r eb89a73976fa -r 3c82100cdadd rep/channel/REPUnpack.java
--- a/rep/channel/REPUnpack.java Fri Aug 29 13:40:29 2008 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-package rep.channel;
-
-import java.io.IOException;
-import java.nio.channels.SocketChannel;
-
-public interface REPUnpack {
-
- public P unpackUConv(SocketChannel sc) throws IOException;
-
-}
\ No newline at end of file
diff -r eb89a73976fa -r 3c82100cdadd rep/channel/SelectableChannelSimulator.java
--- a/rep/channel/SelectableChannelSimulator.java Fri Aug 29 13:40:29 2008 +0900
+++ b/rep/channel/SelectableChannelSimulator.java Fri Aug 29 16:38:11 2008 +0900
@@ -12,7 +12,7 @@
protected SelectorSimulator readSelector;
public SelectableChannelSimulator(SocketChannel channel) {
- super(channel);
+ super(channel, null);
}
/* read from Queue. */