01: package dalma.endpoints.irc;
02:
03: import f00f.net.irc.martyr.commands.MessageCommand;
04:
05: import java.io.Serializable;
06:
07: /**
08: * Represents a private communication channel between another user.
09: *
10: * @author Kohsuke Kawaguchi
11: */
12: public final class PrivateChat extends Session {
13:
14: private final Buddy buddy;
15:
16: PrivateChat(IRCEndPoint endpoint, Buddy buddy) {
17: super (endpoint);
18: this .buddy = buddy;
19: }
20:
21: /**
22: * Gets the {@link Buddy} to which this chat is held.
23: *
24: * @return never null.
25: */
26: public Buddy getBuddy() {
27: return buddy;
28: }
29:
30: public void send(String message) {
31: endpoint.connection.sendCommand(new MessageCommand(buddy
32: .getName(), message));
33: }
34:
35: public void close() {
36: buddy.onChatClosed();
37: }
38:
39: protected Object writeReplace() {
40: return new Moniker(buddy);
41: }
42:
43: private static final class Moniker implements Serializable {
44: private final Buddy buddy;
45:
46: public Moniker(Buddy buddy) {
47: this .buddy = buddy;
48: }
49:
50: private Object readResolve() {
51: return buddy.getChat();
52: }
53:
54: private static final long serialVersionUID = 1L;
55: }
56: }
|