changeset 124:97a321d91b79

*** empty log message ***
author pin
date Wed, 27 Aug 2008 17:21:25 +0900
parents 5b1a0574b406
children 9faacdd6c9cb
files .classpath rep/EditorChannel.java rep/REPPacketReceive.java rep/SelectableEditorChannel.java rep/SessionManager.java
diffstat 5 files changed, 7 insertions(+), 213 deletions(-) [+]
line wrap: on
line diff
--- a/.classpath	Wed Aug 27 17:21:25 2008 +0900
+++ b/.classpath	Wed Aug 27 17:21:25 2008 +0900
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path=""/>
+	<classpathentry excluding="rep/EditorChannel.java" kind="src" path=""/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="output" path=""/>
 </classpath>
--- a/rep/EditorChannel.java	Wed Aug 27 17:21:25 2008 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-package rep;
-
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-public abstract class EditorChannel extends SocketChannel {
-
-	private REPPacketSend repsend;
-	private REPPacketReceive reprec;
-
-	protected EditorChannel(SelectorProvider provider) {
-		super(provider);
-	}
-	
-	public void putPacket(REPCommand comm){
-		repsend.send(comm);
-	}
-	
-	public REPCommand getPacket(){
-		REPCommand command = reprec.unpack();
-		return command;
-	}
-
-	public void setIO(SocketChannel channel) {
-		repsend = new REPPacketSend(channel);
-		reprec = new REPPacketReceive(channel);
-	}
-	
-	public void setIO() {
-		repsend = new REPPacketSend(this);
-		reprec = new REPPacketReceive(this);
-	}
-
-}
--- a/rep/REPPacketReceive.java	Wed Aug 27 17:21:25 2008 +0900
+++ b/rep/REPPacketReceive.java	Wed Aug 27 17:21:25 2008 +0900
@@ -3,6 +3,7 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
+import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 import java.nio.charset.CharacterCodingException;
@@ -11,13 +12,12 @@
 import java.util.LinkedList;
 import java.util.StringTokenizer;
 
+import rep.channel.ChannelSimulator;
+
 public class REPPacketReceive {
 	
 	SocketChannel socketchannel;
 	private final int HEADER_SIZE = 24;
-	private final int CHAR_ORDER = 3;
-	//private String host;
-	//private int port;
 	SelectionKey key;
 	
 	public REPPacketReceive(SocketChannel sc){
@@ -26,66 +26,8 @@
 	
 	public void setkey(SelectionKey key) {
 		this.key = key;
-		//key.cancel();
 	}
 	
-	public REPCommand unpack() {
-
-		ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE);
-		long len = 0;
-		header.clear();
-		try {
-			len = socketchannel.read(header);
-			if(len == -1){
-				if(key != null){
-					key.cancel();
-				}					
-				socketchannel.close();
-				return null;
-			}else if(len == 0){
-				return null;
-			}
-		} catch (IOException e1) {
-			e1.printStackTrace();
-		}  // limit = read length
-		if (len !=HEADER_SIZE) {
-			System.out.println("てす");
-			// this can't happen
-		}
-		header.rewind();  // position = 0
-
-		String text = "";
-		int cmd = header.getInt();
-		int sid = header.getInt();
-		int eid = header.getInt();
-		int seqid = header.getInt();
-		int lineno = header.getInt();
-		int textsiz = header.getInt()/2;
-		
-		ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz*2);
-
-		try {
-			len = socketchannel.read(textBuffer);
-		} catch (IOException e1) {
-			e1.printStackTrace();
-		}  // limit = read length
-		if (len != textsiz * 2) {
-			// this can't happen
-			System.out.println("あと");
-		}
-		textBuffer.rewind();
-		for(int i=0;i<textsiz;i++) {
-			text +=textBuffer.getChar();
-		}
-		String string = text;
-		//System.out.println(string);
-		//getSocket(string);
-		REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string);
-		System.out.println("received command: " + repcommand.toString());
-		//getSocket(repcommand);
-		//System.out.println("received command: " + repcommand.toString());
-		return repcommand;
-	}
 
 	public REPCommand unpackUConv() {
 		ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE);
@@ -106,7 +48,7 @@
 			e1.printStackTrace();
 		}  // limit = read length
 		if (len !=HEADER_SIZE) {
-			System.out.println("てす");
+			System.out.println("error.");
 			// this can't happen
 		}
 		header.rewind();  // position = 0
@@ -117,8 +59,6 @@
 		int seqid = header.getInt();
 		int lineno = header.getInt();
 		int textsiz = header.getInt();
-		//int tmptextsiz = header.getInt();
-		//int textsiz = (tmptextsiz /5) + (tmptextsiz % 5);
 		
 		ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz);
 		
@@ -136,7 +76,7 @@
 		}  // limit = read length
 		if (len != textsiz) {
 			// this can't happen
-			System.out.println("あと");
+			System.out.println("error.");
 		}
 		textBuffer.rewind();
 
@@ -154,14 +94,6 @@
 		String string = cb.toString();
 		
 		textsiz = string.length();
-//		if(textsiz > 2){
-//			System.out.println(string);
-//		}
-		//System.out.println("CharBuffer size: " +cb.length());
-		
-		//System.out.println("textsize: " +textsiz);			
-		
-		//System.out.println(cb.toString());
 
 		REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string);
 		System.out.println("UnPack Packet: => cmd:"+cmd+" sid:"+sid+" eid:"+eid+"seqid:"+seqid+" lineno:"+lineno+" textsiz:" +textsiz+" text: "+string);
@@ -169,23 +101,4 @@
 		
 		return repcommand;		
 	}
-
-	private void getSocket(REPCommand command) {
-		if(command.cmd != REP.SMCMD_JOIN){
-		String string = command.string;
-		StringTokenizer st2 = new StringTokenizer(string, ":");
-		LinkedList<String> list = new LinkedList<String>();
-		while (st2.hasMoreTokens()){
-			list.add(st2.nextToken());
-		}
-		String port = list.getLast();
-		list.removeLast();
-		String host = list.getLast();
-		int socketInfoLength = host.length() + port.length() + 2;
-		System.out.println(host.length() + ":" + port.length() + ":" + socketInfoLength);
-		command.setString(string.substring(0, string.length() - socketInfoLength));
-		command.setHost(host);
-		command.setPort(port);
-		}
-	}
 }
--- a/rep/SelectableEditorChannel.java	Wed Aug 27 17:21:25 2008 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-package rep;
-
-import java.io.IOException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-public class SelectableEditorChannel extends SelectableChannel{
-	
-	private SocketChannel channel;
-	private REPPacketSend repsend;
-	private REPPacketReceive reprec;
-
-	public SelectableEditorChannel(SocketChannel channel){
-		this.channel = channel;
-		repsend = new REPPacketSend(channel);
-		reprec = new REPPacketReceive(channel);
-		
-	}
-
-	@Override
-	public Object blockingLock() {
-		return channel.blockingLock();
-		//return null;
-	}
-
-	@Override
-	public SelectableChannel configureBlocking(boolean block) throws IOException {
-		return channel.configureBlocking(block);
-		//return null;
-	}
-
-	@Override
-	public boolean isBlocking() {
-		
-		return channel.isBlocking();
-	}
-
-	@Override
-	public boolean isRegistered() {
-		return channel.isRegistered();
-	}
-
-	@Override
-	public SelectionKey keyFor(Selector sel) {
-		return channel.keyFor(sel);
-	}
-
-	@Override
-	public SelectorProvider provider() {
-		return channel.provider();
-	}
-
-	@Override
-	public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException {
-		return channel.register(sel, ops, att);
-	}
-
-	@Override
-	public int validOps() {
-		return channel.validOps();
-	}
-
-	@Override
-	protected void implCloseChannel() throws IOException {
-		
-	}
-	
-	public void putPacket(REPCommand comm){
-		repsend.send(comm);
-	}
-	public REPCommand getPacket(){
-		REPCommand command = reprec.unpack();
-		return command;
-	}
-
-	//public void setIO(SocketChannel channel) {
-	//	repsend = new REPPacketSend(channel);
-	//	reprec = new REPPacketReceive(channel);
-	//}
-
-}
--- a/rep/SessionManager.java	Wed Aug 27 17:21:25 2008 +0900
+++ b/rep/SessionManager.java	Wed Aug 27 17:21:25 2008 +0900
@@ -66,7 +66,7 @@
 	public void sessionManagerNet(int port) throws InterruptedException, IOException {
 	
 		//ServerSocketChannel ssc = ServerSocketChannel.open();
-		ServerSocketChannel ssc = REPServerSocketChannel.open();
+		REPServerSocketChannel ssc = REPServerSocketChannel.open();
 		
 		ssc.configureBlocking(false);	//reuse address 必須