2008-08-08 00:37:18 +00:00
|
|
|
/*
|
2008-08-08 01:27:24 +00:00
|
|
|
* JBoss, Home of Professional Open Source
|
2008-08-08 00:37:18 +00:00
|
|
|
*
|
2008-08-08 01:27:24 +00:00
|
|
|
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
|
|
|
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
|
|
|
|
* full listing of individual contributors.
|
2008-08-08 00:37:18 +00:00
|
|
|
*
|
2008-08-08 01:27:24 +00:00
|
|
|
* This is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed in the hope that it will be useful,
|
2008-08-08 00:37:18 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-08 01:27:24 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2008-08-08 00:37:18 +00:00
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2008-08-08 01:27:24 +00:00
|
|
|
* License along with this software; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
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
|
|
|
*
|
|
|
|
* @author The Netty Project (netty-dev@lists.jboss.org)
|
|
|
|
* @author Trustin Lee (tlee@redhat.com)
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
this.remoteAddress = remoteAddress;
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
return remoteAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2009-02-08 16:37:49 +00:00
|
|
|
if (getRemoteAddress() == null) {
|
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-02-08 16:37:49 +00:00
|
|
|
StringUtil.stripControlCharacters(getMessage()) + ", " +
|
2009-02-16 11:59:33 +00:00
|
|
|
getRemoteAddress();
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|