comparison rep/handler/Forwarder.java @ 382:4b87f89b3afd

REP Session Manager (Java version) new structure
author one@firefly.cr.ie.u-ryukyu.ac.jp
date Mon, 10 Nov 2008 22:07:45 +0900
parents
children 1fca50ce3508
comparison
equal deleted inserted replaced
381:65fdb3dc1885 382:4b87f89b3afd
1 package rep.handler;
2
3 import java.io.IOException;
4
5 import rep.PacketSet;
6 import rep.REP;
7 import rep.REPCommand;
8 import rep.SessionManager;
9 import rep.channel.REPLogger;
10 import rep.channel.REPSelectionKey;
11 import rep.channel.REPSocketChannel;
12
13 /**
14 * @author kono
15 * Forward Editor Command to the other Session Manager
16 * Basic send API is supported.
17 */
18 public class Forwarder extends REPNode {
19 int seq = 0;
20 // REPCommands we sent to the next editor
21 final int limit=100; // debugging purpose, assert check only
22 final REPLogger ns = REPLogger.singleton();
23 SessionManager manager;
24 public REP mode = null;
25
26 public Forwarder(SessionManager manager) {
27 this.manager = manager;
28 }
29
30 public int seq() {
31 return seq++;
32 }
33
34 public void send(REPCommand command) {
35 assert(command!=null);
36 assert(channel!=null);
37 REPCommand c = new REPCommand(command);
38 manager.addWriteQueue(new PacketSet(channel,null, c));
39 }
40
41 public void sendWithSeq(REPCommand command) {
42 assert(command!=null);
43 assert(channel!=null);
44 REPCommand c = new REPCommand(command);
45 c.setSEQID(seq());
46 manager.addWriteQueue(new PacketSet(channel,null, c));
47 }
48
49 public REPSocketChannel<REPCommand> getChannel() {
50 return channel;
51 }
52
53 public void setChannel(REPSocketChannel<REPCommand> channel) {
54 this.channel = channel;
55 }
56
57 public void setQuit2(REPCommand cmd) {
58 send(cmd);
59 }
60
61 public void setNext(Forwarder next) {
62 this.next = next;
63 }
64
65 public REPNode getNextForwarder() {
66 return next;
67 }
68
69 public boolean manage(REPCommand command) {
70 next.send(command);
71 return true;
72 }
73
74 public String toString(){
75 return ("Forwarder:" + channel);
76 }
77
78 public String getLocalHostName() {
79 return channel.getLocalHostName();
80 }
81
82 public void cancel(REPSocketChannel<REPCommand> socketChannel) {
83 manager.remove(socketChannel);
84 }
85
86 public void handle(REPSelectionKey<REPCommand> key) throws IOException {
87 assert false;
88 }
89
90
91 public boolean isMerging() {
92 return false;
93 }
94
95
96 }