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;
|
|
|
|
|
2008-09-02 07:13:20 +00:00
|
|
|
/**
|
|
|
|
* The default {@link MessageEvent} implementation. It is recommended to
|
|
|
|
* use {@link Channels#messageEvent(Channel, ChannelFuture, Object)} and
|
|
|
|
* {@link Channels#messageEvent(Channel, ChannelFuture, Object, SocketAddress)}
|
|
|
|
* to create a new {@link MessageEvent} instance rather than calling the
|
|
|
|
* constructor explicitly.
|
|
|
|
*
|
|
|
|
* @author The Netty Project (netty-dev@lists.jboss.org)
|
|
|
|
* @author Trustin Lee (tlee@redhat.com)
|
|
|
|
*
|
|
|
|
* @version $Rev$, $Date$
|
|
|
|
*
|
|
|
|
*/
|
2009-02-05 05:56:47 +00:00
|
|
|
public final 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-05 05:56:47 +00:00
|
|
|
public UpstreamMessageEvent(
|
|
|
|
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() {
|
|
|
|
if (remoteAddress == null) {
|
2009-02-08 16:12:18 +00:00
|
|
|
return getChannel().toString() + " - (RECEIVED: " + message + ')';
|
2008-08-08 00:37:18 +00:00
|
|
|
} else {
|
2009-02-08 16:12:18 +00:00
|
|
|
return getChannel().toString() + " - (RECEIVED: " + message + ", " + remoteAddress + ')';
|
2008-08-08 00:37:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|