# HG changeset patch # User kono # Date 1219836219 -32400 # Node ID 01062be677e94e82ed08c49ad5080246bfd32266 # Parent d6b94713cf454adbec0e72a41ef8f65572bc9ccd *** empty log message *** diff -r d6b94713cf45 -r 01062be677e9 rep/ConnectToSessionManager.java --- a/rep/ConnectToSessionManager.java Wed Aug 27 19:02:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -package rep; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.channels.SocketChannel; - -import rep.net.REPNet; -import test.TestGUI; - -public class ConnectToSessionManager { - private SocketChannel sc; - private REPPacketReceive repreceive; - private REPPacketSend repsend; - private TestGUI gui; - private REPNet rnet; - - public static void main(String[] args){ - ConnectToSessionManager test = new ConnectToSessionManager(); - test.sm_join("localhost"); - } - - public void sm_join(String host){ - rnet = new REPNet(); - rnet.sm_connect(host, 8765); - rnet.send(REPCommand.SMCMD_SESSION_JOIN); - } - -} diff -r d6b94713cf45 -r 01062be677e9 rep/RPanel.java --- a/rep/RPanel.java Wed Aug 27 19:02:11 2008 +0900 +++ b/rep/RPanel.java Wed Aug 27 20:23:39 2008 +0900 @@ -1,19 +1,14 @@ package rep; -import java.awt.BorderLayout; -import java.awt.Component; import java.awt.Dimension; -import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.nio.channels.SocketChannel; -import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JScrollBar; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextArea; @@ -26,6 +21,10 @@ public class RPanel extends JPanel implements ActionListener { + /** + * + */ + private static final long serialVersionUID = 1L; private JButton button; private JTextField textField; private String host; @@ -43,7 +42,7 @@ private DefaultTableModel s_tableModel = new DefaultTableModel(session_column, 0); private DefaultTableModel e_tableModel = new DefaultTableModel(editor_column, 0); LinkedList s_list = new LinkedList(); - LinkedList e_list = new LinkedList(); + LinkedList> e_list = new LinkedList>(); private String s_host; private String s_port; private String s_file; @@ -55,9 +54,9 @@ private JComboBox comboEditor; private JComboBox comboSession; private JButton buttonSelect; - private REPActionListener actionListener; + private REPActionListener actionListener; private JButton buttonUndo; - private REPActionListener undoListener; + private REPActionListener undoListener; public RPanel() { button = new JButton("Connect"); @@ -133,7 +132,7 @@ actionListener.ActionOccured(new REPActionEvent((EditorPlus) comboEditor.getSelectedItem(), (SessionPlus)comboSession.getSelectedItem())); */ - actionListener.ActionOccured(new REPActionEvent((EditorPlus) e_list.get(editor_table.getSelectedRow()), + actionListener.ActionOccured(new REPActionEvent((EditorPlus) e_list.get(editor_table.getSelectedRow()), (SessionPlus)s_list.get(session_table.getSelectedRow()))); }else if(event.getSource() == buttonUndo){ //System.out.println("Undo!"); @@ -146,16 +145,16 @@ this.listener = listener; } - public void addUndoListener(REPActionListener listener3){ + public void addUndoListener(REPActionListener listener3){ undoListener = listener3; } public void setComboEditor(int eid, REPSocketChannel channel) { //comboEditor.addItem("Editor:"+eid); - comboEditor.addItem(new EditorPlus(eid, channel)); + comboEditor.addItem(new EditorPlus(eid, channel)); } - public void addREPActionListener(REPActionListener listener2) { + public void addREPActionListener(REPActionListener listener2) { this.actionListener = listener2; } @@ -166,7 +165,7 @@ public void setTableEditor(int eid, REPSocketChannel channel) { //comboEditor.addItem("Editor:"+eid); - EditorPlus ep = new EditorPlus(eid, channel); + EditorPlus ep = new EditorPlus(eid, channel); e_list.add(ep); Vector editor = new Vector(); e_eid = "Editor : " + eid; diff -r d6b94713cf45 -r 01062be677e9 rep/ServerSample.java --- a/rep/ServerSample.java Wed Aug 27 19:02:11 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -package rep; -import java.nio.*; -import java.nio.channels.*; -import java.nio.charset.*; -import java.net.*; - -public class ServerSample -{ -public static void main(String[] argv) -throws Exception -{ -// セレクタの用意 -Selector selector = Selector.open(); - -// サーバソケットチャンネルを作成。5100番ポートを受付ポートに指定 -// (非ブロックモードに設定:重要) -ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); -serverSocketChannel.configureBlocking(false); -serverSocketChannel.socket().bind(new InetSocketAddress(5100)); - -// セレクタにサーバソケットチャンネルを登録。サーバへの受付を監視 -serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); - -// セレクタにイベントが通知されるごとに処理 -while (true) { - -// セレクタにイベントが発生するまでブロック -selector.select(); - -// 獲得したイベントごとに処理を実行 -for (SelectionKey selectionKey : selector.selectedKeys()) { - -// サーバの受付処理: -// イベントが受付可能である場合、受け付けるべき対象があれば -// セレクタに取得したソケットチャンネルを登録 -if (selectionKey.isAcceptable()) { - -// サーバソケットチャンネルからソケットチャンネルを獲得 -// ソケットチャンネルを経由してクライアントと通信できる -SocketChannel socketChannel = serverSocketChannel.accept(); - -// 接続先がなくてもここに処理が飛ぶことがある。対象が -// nullの場合は処理を抜ける -if (null == socketChannel) continue; - -// ソケットチャンネルを非ブロックモードに設定(重要)し、 -// セレクタに読み込みを対象として登録 -socketChannel.configureBlocking(false); -socketChannel.register(selector, SelectionKey.OP_READ); -socketChannel = null; -} - -// クライアントとの通信処理 -// 読込み可能である場合、内容物を読みこんで標準出力に表示。 -// メッセージをクライアントに送信して、コネクションを切断。 -// セレクタから登録を解除 -else if (selectionKey.isReadable()) { - -// 登録されているソケットチャンネルを取得 -SocketChannel socketChannel = -(SocketChannel)selectionKey.channel(); - -Charset charset = Charset.forName("US-ASCII"); -ByteBuffer byteBuffer = ByteBuffer.allocate(8192); - -// クライアントからメッセージの受信 -switch (socketChannel.read(byteBuffer)) { -case -1: -// クライアント側が接続を切断していた場合は、サーバも -// 接続を切断。セレクタから登録を削除 -socketChannel.close(); -break; -case 0: -// 読み込むべきメッセージは届いていないので処理を飛ばす -continue; -default: -// クライアントからメッセージを取得し、標準出力へ -byteBuffer.flip(); -System.out.print("EEE: " + charset.decode(byteBuffer)); - -// クライアントへメッセージを送信 -socketChannel.write(charset.encode("Good bye!\r\n")); - -// クライアントとの接続を切断。セレクタから登録を削除 -//socketChannel.close(); -break; -} -} -System.out.println(selectionKey.toString()); -} -} -} -} \ No newline at end of file diff -r d6b94713cf45 -r 01062be677e9 rep/SessionManager.java --- a/rep/SessionManager.java Wed Aug 27 19:02:11 2008 +0900 +++ b/rep/SessionManager.java Wed Aug 27 20:23:39 2008 +0900 @@ -62,7 +62,7 @@ public void sessionManagerNet(int port) throws InterruptedException, IOException { - REPServerSocketChannel ssc = REPServerSocketChannel.open(); + REPServerSocketChannel ssc = new REPServerSocketChannel().create(); ssc.configureBlocking(false); //reuse address 必須 @@ -432,7 +432,7 @@ port = send_port; InetSocketAddress addr = new InetSocketAddress(host, port); try { - REPSocketChannel sessionchannel = REPSocketChannel.open(); + REPSocketChannel sessionchannel = new REPSocketChannel().create(); sessionchannel.configureBlocking(true); sessionchannel.connect(addr); while(!sessionchannel.finishConnect()){ diff -r d6b94713cf45 -r 01062be677e9 rep/channel/REPServerSocketChannel.java --- a/rep/channel/REPServerSocketChannel.java Wed Aug 27 19:02:11 2008 +0900 +++ b/rep/channel/REPServerSocketChannel.java Wed Aug 27 20:23:39 2008 +0900 @@ -21,11 +21,16 @@ ss = channel; } - public static REPServerSocketChannel open() throws IOException { + public REPServerSocketChannel() { + super(null); + + } + + public REPServerSocketChannel

create() throws IOException { if(isSimulation){ - return ServerChannelSimulatorImpl.open(); + return new ServerChannelSimulatorImpl

(null).open(); }else{ - return new REPServerSocketChannel(open()); + return new REPServerSocketChannel

(open()); } } diff -r d6b94713cf45 -r 01062be677e9 rep/channel/REPSocketChannel.java --- a/rep/channel/REPSocketChannel.java Wed Aug 27 19:02:11 2008 +0900 +++ b/rep/channel/REPSocketChannel.java Wed Aug 27 20:23:39 2008 +0900 @@ -8,6 +8,7 @@ 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{ @@ -82,6 +83,14 @@ // TODO Auto-generated method stub return null; } + + public REPSocketChannel

create() throws IOException { + if (REPServerSocketChannel.isSimulation) { + return new ChannelSimulator

(null); + } else { + return new REPSocketChannel

(SocketChannel.open()); + } + } diff -r d6b94713cf45 -r 01062be677e9 rep/channel/ServerChannelSimulatorImpl.java --- a/rep/channel/ServerChannelSimulatorImpl.java Wed Aug 27 19:02:11 2008 +0900 +++ b/rep/channel/ServerChannelSimulatorImpl.java Wed Aug 27 20:23:39 2008 +0900 @@ -6,10 +6,10 @@ import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; -public class ServerChannelSimulatorImpl extends REPServerSocketChannel{ +public class ServerChannelSimulatorImpl

extends REPServerSocketChannel

{ -protected ServerChannelSimulatorImpl(SelectorProvider provider) { + protected ServerChannelSimulatorImpl(SelectorProvider provider) { super(provider); } @@ -42,9 +42,8 @@ } - public static REPServerSocketChannel open() { - new ServerChannelSimulator(null, null); - return null; + public REPServerSocketChannel

open() { + return new ServerChannelSimulatorImpl

(null); } } diff -r d6b94713cf45 -r 01062be677e9 test/TestGUI.java --- a/test/TestGUI.java Wed Aug 27 19:02:11 2008 +0900 +++ b/test/TestGUI.java Wed Aug 27 20:23:39 2008 +0900 @@ -5,7 +5,6 @@ import javax.swing.JFrame; -import rep.ConnectToSessionManager; import rep.ConnectionListener; import rep.RPanel; import rep.gui.ConnectionPanel;