Mercurial > hg > RemoteEditor > REPSessionManager
view rep/SessionList.java @ 287:1ff8bfc0a99a test-editor
*** empty log message ***
author | kono |
---|---|
date | Sun, 28 Sep 2008 15:46:36 +0900 |
parents | 90965a3bd4f3 |
children | 77f443f6dc9f |
line wrap: on
line source
package rep; import java.nio.channels.SocketChannel; import java.util.LinkedList; import rep.channel.REPSocketChannel; import rep.xml.SessionXMLEncoder; public class SessionList { // Hashtable<Integer, Session> session3 = new Hashtable<Integer, Session>(); LinkedList<Session> sessionLinkedList = new LinkedList<Session>(); LinkedList<String> stringlist = new LinkedList<String>(); private int sessionID = 0; private int editorCount = 0; private boolean channelequals = false; private String maxHost; //private TranslaterImp1 translater; public SessionList(){ makeDefaultSession(); } public void add(REPSocketChannel<REPCommand> channel) { } public void makeDefaultSession(){ // session3.put(0, new Session(0, null, null)); // session4.add(0, new Session(0, null, null)); } public int getEditorNumber() { return 0; } public void add(REPSocketChannel<REPCommand> channel, int sid) { } public int addSession(REPSocketChannel<REPCommand> channel, String string) { sessionID++; // session3.put(sessionID, new Session(sessionID, string, channel)); // sessionLinkedList.add(new Session(sessionID, string, channel)); return sessionID; } public void addEditor(REPSocketChannel<REPCommand> channel, int sid, REPCommand repCmd) { int editorID = repCmd.eid; // if(session3.get(sid) == null) System.out.println("ぬるぽ!"); // session3.get(sid).addEditor(editorID, channel); sessionLinkedList.get(sid-1).addEditor(editorID, channel); //本当はforループで検索しないといけないよ。 } // public int getSessionID(SocketChannel channel) { // return 0; // } public int getNumberOfEditor() { editorCount++; return editorCount; } public void sendCmd(REPSocketChannel<REPCommand> channel2, REPCommand repCmd) { // LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); LinkedList <Editor> editorList = sessionLinkedList.get(repCmd.sid).getEditorList(); //ここもforループで検索しないといけないよ。 for(Editor editor : editorList){ REPSocketChannel<REPCommand> channel = editor.getChannel(); if(channel.equals(channel2)) { System.out.println("equals"); continue; } channel.write(repCmd); } } public void sendCmd(REPSocketChannel<REPCommand> channel, REPCommand repCmd, boolean ring){ // LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); LinkedList <Editor> editorList = sessionLinkedList.get(repCmd.sid).getEditorList(); //ここもforループで検索しないといけないよ。 for(Editor editor : editorList){ REPSocketChannel<REPCommand> channel2 = editor.getChannel(); if(channel.equals(channel2)){ System.out.println("equals"); channelequals = true; }else if(channelequals){ channel2.write(repCmd); } } } public void addSessionManager(SocketChannel channel, REPCommand repCmd) { } // public void sendAddedSession(REPCommand repCmd) { // repCmd.setCMD(REP.SMCMD_SM_JOIN); // REPPacketSend repSend = new REPPacketSend(smchannel); // } public String getSessionList() { // if (session3 != null) { // System.out.println(session3.toString()); // return session3.toString(); // } if (sessionLinkedList != null) { System.out.println(sessionLinkedList.toString()); return sessionLinkedList.toString(); } return "{}"; } public void addEditor(REPSocketChannel<REPCommand> editorChannel, int sid, int eid) { // session3.get(sid).addEditor(eid, editorChannel); sessionLinkedList.get(sid-1).addEditor(eid, editorChannel); } public void sendSelect(int sid) { // SocketChannel channel = session3.get(sid).getMaster().getChannel(); REPSocketChannel<REPCommand> channel = sessionLinkedList.get(sid-1).getOwner().getChannel(); channel.write(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, "")); } public void addSession(REPSocketChannel<REPCommand> channel, String string, int i) { // tmpSessionList.add(new Session(0, string, channel)); } // public String getXML() { ///* SessionListをXMLに書き出す。ときの形式 // * <Session> // * <editor> // * <sid/> // * <host/> // * <port/> // * <filename/> // * </editor> // * <editor> // * <sid/> // * <host/> // * <port/> // * </editor> // * </Session> // * <SessionManager> // * <host/> // * <port/> // * </SessionManager> // * <Session> // * </Session> // * // StringWriter str = null; // try { // str = new StringWriter(); // DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // DocumentBuilder builder = factory.newDocumentBuilder(); // Document doc = builder.newDocument(); // Element root = doc.getDocumentElement(); // root = doc.createElement("SessionList"); // for(Session session : session4){ // Element element = doc.createElement("Session"); // root.appendChild(element); // Element element2 = doc.createElement("editor"); // element.appendChild(element2); // Editor editor = session.getMaster(); // Element element3 = doc.createElement(editor.getHost()); // Element element4 = doc.createElement(editor.getPort()); // Element element5 = doc.createElement(editor.getName()); // element5 = doc.createElement(session.getName()); // element2.appendChild(element3); // element2.appendChild(element4); // element2.appendChild(element5); // // } // doc.appendChild(root); // // TransformerFactory tfactory = TransformerFactory.newInstance(); // Transformer transformer = tfactory.newTransformer(); // StreamResult result = new StreamResult(str); // //transformer.transform(new DOMSource(doc), new StreamResult(System.out)); // transformer.transform(new DOMSource(doc), result); // System.out.println(str); //// //// XMLEncoder e = new XMLEncoder(System.out); //// e.writeObject(session4); //// e.writeObject(stringlist); //// e.close(); // // //System.out.println(doc); // }catch (Exception e){ // e.printStackTrace(); // } // return str.toString(); // }*/ public LinkedList<Session> getList() { return sessionLinkedList; } public String toXML() { SessionXMLEncoder encoder = new SessionXMLEncoder(sessionLinkedList); encoder.sessionListToXML(); return null; } public int addSession(Session session) { sessionID++; // session3.put(sessionID, session); session.setSID(sessionID); sessionLinkedList.add(session); return sessionID; } public void addToRoutingTable(SocketChannel channel) { } public Session getSession(int sid) { for(Session session : sessionLinkedList){ if(session.getSID() == sid){ return session; } } return sessionLinkedList.get(sid - 1); } public void setMaxHost(String myHost) { // TODO Auto-generated method stub maxHost = myHost; } public String getMaxHost() { // TODO Auto-generated method stub return maxHost; } public void setList(LinkedList<Session> list) { // TODO Auto-generated method stub sessionLinkedList = list; } public void update(REPSocketChannel<REPCommand> channel, SessionList receivedSessionList) { LinkedList<Session> list = receivedSessionList.getList(); int i = 0; for(Session session : list){ session.getEditorList().get(0).setChannel(channel); ++i; int sid = addSession(session); setTranslationTable(channel, i, sid); } } private void setTranslationTable(REPSocketChannel<REPCommand> channel, int i, int sid) { } }