2008-08-08 00:37:18 +00:00
|
|
|
/*
|
2011-12-09 14:18:34 +09:00
|
|
|
* Copyright 2011 The Netty Project
|
2008-08-08 00:37:18 +00:00
|
|
|
*
|
2011-12-09 14:18:34 +09:00
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
2008-08-08 00:37:18 +00:00
|
|
|
*
|
2011-12-09 14:18:34 +09:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-08-08 01:27:24 +00:00
|
|
|
*
|
2009-08-28 07:15:49 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
2011-12-09 14:18:34 +09:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2009-08-28 07:15:49 +00:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-08-08 00:37:18 +00:00
|
|
|
*/
|
2011-12-09 12:38:59 +09:00
|
|
|
package io.netty.channel;
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2011-12-09 12:38:59 +09:00
|
|
|
import static io.netty.channel.Channels.*;
|
2009-02-05 05:56:47 +00:00
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
import java.net.SocketAddress;
|
|
|
|
|
2011-12-09 12:38:59 +09:00
|
|
|
import io.netty.util.internal.StringUtil;
|
2009-02-08 16:37:49 +00:00
|
|
|
|
2008-09-02 07:13:20 +00:00
|
|
|
/**
|
2009-06-17 09:33:20 +00:00
|
|
|
* The default upstream {@link MessageEvent} implementation.
|
2008-09-02 07:13:20 +00:00
|
|
|
*/
|
2009-02-11 09:47:53 +00:00
|
|
|
public class UpstreamMessageEvent implements MessageEvent {
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2009-02-05 05:56:47 +00:00
|
|
|
private final Channel channel;
|
2008-08-08 00:37:18 +00:00
|
|
|
private final Object message;
|
|
|
|
private final SocketAddress remoteAddress;
|
|
|
|
|
2008-09-03 04:10:04 +00:00
|
|
|
/**
|
|
|
|
* Creates a new instance.
|
|
|
|
*/
|
2009-02-11 09:47:53 +00:00
|
|
|
public UpstreamMessageEvent(
|
2009-02-05 05:56:47 +00:00
|
|
|
Channel channel, Object message, SocketAddress remoteAddress) {
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2009-02-05 05:56:47 +00:00
|
|
|
if (channel == null) {
|
|
|
|
throw new NullPointerException("channel");
|
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
if (message == null) {
|
|
|
|
throw new NullPointerException("message");
|
|
|
|
}
|
2009-02-05 05:56:47 +00:00
|
|
|
this.channel = channel;
|
2008-08-08 00:37:18 +00:00
|
|
|
this.message = message;
|
2009-07-18 07:46:49 +00:00
|
|
|
if (remoteAddress != null) {
|
|
|
|
this.remoteAddress = remoteAddress;
|
|
|
|
} else {
|
|
|
|
this.remoteAddress = channel.getRemoteAddress();
|
|
|
|
}
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2009-02-05 05:56:47 +00:00
|
|
|
public Channel getChannel() {
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2009-02-05 05:56:47 +00:00
|
|
|
public ChannelFuture getFuture() {
|
|
|
|
return succeededFuture(getChannel());
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
public Object getMessage() {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2010-11-12 09:45:39 +09:00
|
|
|
@Override
|
2008-08-08 00:37:18 +00:00
|
|
|
public SocketAddress getRemoteAddress() {
|
2009-07-18 07:46:49 +00:00
|
|
|
return remoteAddress;
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2009-07-18 07:49:31 +00:00
|
|
|
if (getRemoteAddress() == getChannel().getRemoteAddress()) {
|
2009-02-16 11:59:33 +00:00
|
|
|
return getChannel().toString() + " RECEIVED: " +
|
|
|
|
StringUtil.stripControlCharacters(getMessage());
|
2008-08-08 00:37:18 +00:00
|
|
|
} else {
|
2009-02-16 11:59:33 +00:00
|
|
|
return getChannel().toString() + " RECEIVED: " +
|
2009-07-18 07:38:39 +00:00
|
|
|
StringUtil.stripControlCharacters(getMessage()) + " from " +
|
2009-02-16 11:59:33 +00:00
|
|
|
getRemoteAddress();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|