1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.channel;
17
18 import java.net.SocketAddress;
19
20 import org.jboss.netty.util.internal.StringUtil;
21
22
23
24
25 public class DownstreamMessageEvent implements MessageEvent {
26
27 private final Channel channel;
28 private final ChannelFuture future;
29 private final Object message;
30 private final SocketAddress remoteAddress;
31
32
33
34
35 public DownstreamMessageEvent(
36 Channel channel, ChannelFuture future,
37 Object message, SocketAddress remoteAddress) {
38
39 if (channel == null) {
40 throw new NullPointerException("channel");
41 }
42 if (future == null) {
43 throw new NullPointerException("future");
44 }
45 if (message == null) {
46 throw new NullPointerException("message");
47 }
48 this.channel = channel;
49 this.future = future;
50 this.message = message;
51 if (remoteAddress != null) {
52 this.remoteAddress = remoteAddress;
53 } else {
54 this.remoteAddress = channel.getRemoteAddress();
55 }
56 }
57
58 public Channel getChannel() {
59 return channel;
60 }
61
62 public ChannelFuture getFuture() {
63 return future;
64 }
65
66 public Object getMessage() {
67 return message;
68 }
69
70 public SocketAddress getRemoteAddress() {
71 return remoteAddress;
72 }
73
74 @Override
75 public String toString() {
76 if (getRemoteAddress() == getChannel().getRemoteAddress()) {
77 return getChannel().toString() + " WRITE: " +
78 StringUtil.stripControlCharacters(getMessage());
79 } else {
80 return getChannel().toString() + " WRITE: " +
81 StringUtil.stripControlCharacters(getMessage()) + " to " +
82 getRemoteAddress();
83 }
84 }
85 }