changeset 337:5ba5b7a9761b

use REPLogger
author kono
date Sun, 12 Oct 2008 18:42:18 +0900
parents d00cb51ba652
children bcb4ea4ff208
files rep/Editor.java rep/EditorList.java rep/REPCommandPacker.java rep/SessionList.java rep/SessionManager.java rep/handler/REPEditorHandler.java rep/handler/REPSessionManagerHandler.java
diffstat 7 files changed, 27 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/rep/Editor.java	Sun Oct 12 18:06:54 2008 +0900
+++ b/rep/Editor.java	Sun Oct 12 18:42:18 2008 +0900
@@ -72,7 +72,7 @@
 		if (prev==null || prev.seq != command.seq || prev.eid!=command.eid) {
 			String err = "Editor.checkReturnedCommand() : command = " + command + " prev=";
 			err += prev==null?"null":prev.toString();
-			System.out.println(err);
+			SessionManager.logger.writeLog(err);
 			assert(false);
 		}
 
--- a/rep/EditorList.java	Sun Oct 12 18:06:54 2008 +0900
+++ b/rep/EditorList.java	Sun Oct 12 18:42:18 2008 +0900
@@ -51,14 +51,14 @@
 	
 	private void error(Object obj) {
 		if(obj == null){
-			System.out.println("null!");
+			SessionManager.logger.writeLog("null!");
 		}
 	}
 	private void error(String str1, String str2){
 		if(str1.equals(str2)){
 			return;
 		}else{
-			System.out.println("Not equals! str1:str2");
+			SessionManager.logger.writeLog("Not equals! str1:str2");
 		}
 	}
 
@@ -73,7 +73,6 @@
 
 
 	public void setHost(String myHost) {
-		// TODO Auto-generated method stub
 		for(Editor editor : editorList) {
 			editor.setHost(myHost);
 		}
@@ -81,18 +80,13 @@
 
 
 	public Forwarder getEditor(String hostport) {
-		// TODO Auto-generated method stub
 		for(Editor editor : editorList){
 			String[] splited = hostport.split(":");
-			System.out.println(splited[0] + "," + editor.getHost());
+			SessionManager.logger.writeLog(
+					splited[0] + "," + editor.getHost());
 			if(splited[0].equals(editor.getHost())){
 				return editor;
 			}
-			
-			//String hostandport = editor.getHost() + ":" + editor.getPort();
-			//if(hostport.equals(hostandport)){
-			//	return editor;
-			//}
 		}
 		return null;
 	}
@@ -106,7 +100,6 @@
 
 
 	public Forwarder getEditor(REPSocketChannel<REPCommand> channel) {
-		// TODO Auto-generated method stub
 		Forwarder editor1 = null;
 		for(Forwarder editor: editorList){
 			if(channel == editor.getChannel()){
--- a/rep/REPCommandPacker.java	Sun Oct 12 18:06:54 2008 +0900
+++ b/rep/REPCommandPacker.java	Sun Oct 12 18:42:18 2008 +0900
@@ -32,7 +32,6 @@
 	private static final int HEADER_SIZE = 24;
 	// JIS/S-JIS = 2, UTF-8 = 3, UTF-?? = 5
 	private static final int CHARSIZE = 5;
-	private static final boolean isLogging=false;
 
 	Charset charset = Charset.forName("UTF-8");
 	CharsetEncoder encoder = charset.newEncoder();
@@ -42,11 +41,6 @@
 	 * @see rep.REPPack#packUConv(rep.REPCommand)
 	 */
 	public ByteBuffer packUConv(REPCommand command){
-		if (isLogging)
-			System.out.println("Sending: " + command);
-    	if(command.string == null){
-    		command.setString("");
-    	}
     	ByteBuffer buffer = ByteBuffer.allocateDirect(HEADER_SIZE+(command.string.length()*CHARSIZE));
     	buffer.clear();  // position = 0 
     	buffer.putInt(command.cmd.id);
@@ -58,14 +52,16 @@
     	int pos = buffer.position();
     	buffer.putInt(0);
     	int pos1 = buffer.position();
-    	
-    	//Encode to UTF8
-    	CharBuffer cb = CharBuffer.wrap(command.string);
-		try {
-			encoder.encode(cb, buffer, true);
-		} catch (IllegalStateException e) {
-			buffer.position(pos1);
-		}
+
+    	if (command.string!=null) {
+    		//Encode to UTF8
+    		CharBuffer cb = CharBuffer.wrap(command.string);
+    		try {
+    			encoder.encode(cb, buffer, true);
+    		} catch (IllegalStateException e) {
+    			buffer.position(pos1);
+    		}
+    	}
 		
 		//Encoded string length set
 		int length = buffer.position() -pos1 ;
@@ -117,8 +113,8 @@
 		}
 		textsiz = string.length();
 		REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string);
-		if (isLogging)
-			System.out.println("Reading: "+repcommand);
+		//if (isLogging)
+		//System.out.println("Reading: "+repcommand);
 		return repcommand;		
 	}
 
--- a/rep/SessionList.java	Sun Oct 12 18:06:54 2008 +0900
+++ b/rep/SessionList.java	Sun Oct 12 18:42:18 2008 +0900
@@ -27,7 +27,8 @@
 
 	public String getSessionList() {
 		if (sessionLinkedList != null) {
-			System.out.println(sessionLinkedList.toString());
+			SessionManager.logger.writeLog(
+					sessionLinkedList.toString());
 			return sessionLinkedList.toString();
 		}
 		return "{}";
--- a/rep/SessionManager.java	Sun Oct 12 18:06:54 2008 +0900
+++ b/rep/SessionManager.java	Sun Oct 12 18:42:18 2008 +0900
@@ -12,6 +12,7 @@
 import java.util.concurrent.LinkedBlockingQueue;
 
 
+import rep.channel.REPLogger;
 import rep.channel.REPServerSocketChannel;
 import rep.channel.REPSocketChannel;
 import rep.handler.PacketSet;
@@ -42,7 +43,8 @@
 */
 
 public class SessionManager implements SessionManagerEventListener{
-	
+	static public REPLogger logger = REPLogger.singleton();
+
 	LinkedList<Session> sessionList;
 	private SessionManagerGUI gui;
 	private REPSelector<REPCommand> selector;
@@ -183,7 +185,7 @@
 		for(REPSelectionKey<REPCommand> key : keys){
 			if(key.isAcceptable()){
 				REPSocketChannel<REPCommand> channel = key.accept(new REPCommandPacker());
-				System.out.println("SessionManager.select() : key.isAcceptable : channel = " + channel);
+				logger.writeLog("SessionManager.select() : key.isAcceptable : channel = " + channel);
 				registerChannel (channel, SelectionKey.OP_READ);
 				channel = null;
 
@@ -508,10 +510,7 @@
 			REPSocketChannel<REPCommand> sessionchannel = REPSocketChannel.<REPCommand>create(new REPCommandPacker());
 			sessionchannel.configureBlocking(true);
 			sessionchannel.connect(addr);
-			while(!sessionchannel.finishConnect()){
-				System.out.print("test afro");
-			}
-			System.out.println("");
+			while(!sessionchannel.finishConnect());
 			registerChannel(sessionchannel, SelectionKey.OP_READ);
 			
 			sm_join(sessionchannel);
@@ -552,7 +551,7 @@
 		
 		Editor editor = (Editor)event.getEditor();
 		if(editor == null){
-			System.out.println("SessionManager.selectSession():editor = " + editor);
+			logger.writeLog("SessionManager.selectSession():editor = " + editor);
 			return;
 		}
 		if (editor.hasSession()) return;
--- a/rep/handler/REPEditorHandler.java	Sun Oct 12 18:06:54 2008 +0900
+++ b/rep/handler/REPEditorHandler.java	Sun Oct 12 18:42:18 2008 +0900
@@ -19,7 +19,7 @@
 	public void handle(REPSelectionKey<REPCommand> key) throws IOException {
 		REPSocketChannel<REPCommand> channel = key.channel1();
 		REPCommand command = channel.read();
-		System.out.println("REPHandlerImpl.handle() read : command = " + command +" from "+channel);
+		SessionManager.logger.writeLog("REPHandlerImpl.handle() read : command = " + command +" from "+channel);
 
 		manager.manage(channel, command);
 	}
--- a/rep/handler/REPSessionManagerHandler.java	Sun Oct 12 18:06:54 2008 +0900
+++ b/rep/handler/REPSessionManagerHandler.java	Sun Oct 12 18:42:18 2008 +0900
@@ -29,7 +29,7 @@
 		 */
 		REPSocketChannel<REPCommand> channel = key.channel1();
 		REPCommand command = channel.read();
-		System.out.println("REPHandlerImpl.handle() : command = " + command);
+		SessionManager.logger.writeLog("REPHandlerImpl.handle() : command = " + command);
 		Session s = manager.getSession(command.sid);
 		Forwarder editor = s.getFirstForwarder();
 		if (editor!=null) {