2008-08-08 00:37:18 +00:00
|
|
|
/*
|
2009-08-28 07:15:49 +00:00
|
|
|
* Copyright 2009 Red Hat, Inc.
|
2008-08-08 00:37:18 +00:00
|
|
|
*
|
2009-08-28 07:15:49 +00:00
|
|
|
* Red Hat 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
|
|
|
*
|
2009-08-28 07:15:49 +00: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
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-08-08 00:37:18 +00:00
|
|
|
*/
|
2008-08-08 01:40:10 +00:00
|
|
|
package org.jboss.netty.channel;
|
2008-08-08 00:37:18 +00:00
|
|
|
|
2009-02-05 05:56:47 +00:00
|
|
|
import static org.jboss.netty.channel.Channels.*;
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
import java.net.SocketAddress;
|
|
|
|
|
2009-04-03 07:41:54 +00:00
|
|
|
import org.jboss.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
|
|
|
*
|
2010-01-26 09:04:19 +00:00
|
|
|
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
|
|
|
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
2008-09-02 07:13:20 +00:00
|
|
|
*
|
|
|
|
* @version $Rev$, $Date$
|
|
|
|
*
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2009-02-05 05:56:47 +00:00
|
|
|
public Channel getChannel() {
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ChannelFuture getFuture() {
|
|
|
|
return succeededFuture(getChannel());
|
|
|
|
}
|
|
|
|
|
2008-08-08 00:37:18 +00:00
|
|
|
public Object getMessage() {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|