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