Mercurial > hg > RemoteEditor > REPSessionManager
changeset 140:01062be677e9
*** empty log message ***
author | kono |
---|---|
date | Wed, 27 Aug 2008 20:23:39 +0900 |
parents | d6b94713cf45 |
children | 6f15a8880ed8 |
files | rep/ConnectToSessionManager.java rep/RPanel.java rep/ServerSample.java rep/SessionManager.java rep/channel/REPServerSocketChannel.java rep/channel/REPSocketChannel.java rep/channel/ServerChannelSimulatorImpl.java test/TestGUI.java |
diffstat | 8 files changed, 35 insertions(+), 145 deletions(-) [+] |
line wrap: on
line diff
--- 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); - } - -}
--- 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<SessionPlus> s_list = new LinkedList<SessionPlus>(); - LinkedList<EditorPlus> e_list = new LinkedList<EditorPlus>(); + LinkedList<EditorPlus<REPCommand>> e_list = new LinkedList<EditorPlus<REPCommand>>(); 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<REPCommand> actionListener; private JButton buttonUndo; - private REPActionListener undoListener; + private REPActionListener<REPCommand> 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<REPCommand>((EditorPlus<REPCommand>) 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<REPCommand> listener3){ undoListener = listener3; } public void setComboEditor(int eid, REPSocketChannel<REPCommand> channel) { //comboEditor.addItem("Editor:"+eid); - comboEditor.addItem(new EditorPlus(eid, channel)); + comboEditor.addItem(new EditorPlus<REPCommand>(eid, channel)); } - public void addREPActionListener(REPActionListener listener2) { + public void addREPActionListener(REPActionListener<REPCommand> listener2) { this.actionListener = listener2; } @@ -166,7 +165,7 @@ public void setTableEditor(int eid, REPSocketChannel<REPCommand> channel) { //comboEditor.addItem("Editor:"+eid); - EditorPlus ep = new EditorPlus(eid, channel); + EditorPlus<REPCommand> ep = new EditorPlus<REPCommand>(eid, channel); e_list.add(ep); Vector editor = new Vector(); e_eid = "Editor : " + eid;
--- 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
--- 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<REPCommand> ssc = REPServerSocketChannel.open(); + REPServerSocketChannel<REPCommand> ssc = new REPServerSocketChannel<REPCommand>().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<REPCommand>().create(); sessionchannel.configureBlocking(true); sessionchannel.connect(addr); while(!sessionchannel.finishConnect()){
--- 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<P> create() throws IOException { if(isSimulation){ - return ServerChannelSimulatorImpl.open(); + return new ServerChannelSimulatorImpl<P>(null).open(); }else{ - return new REPServerSocketChannel(open()); + return new REPServerSocketChannel<P>(open()); } }
--- 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<P> extends SelectableChannel{ @@ -82,6 +83,14 @@ // TODO Auto-generated method stub return null; } + + public REPSocketChannel<P> create() throws IOException { + if (REPServerSocketChannel.isSimulation) { + return new ChannelSimulator<P>(null); + } else { + return new REPSocketChannel<P>(SocketChannel.open()); + } + }
--- 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<P> extends REPServerSocketChannel<P>{ -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<P> open() { + return new ServerChannelSimulatorImpl<P>(null); } }