Use InetSocketAddress wherever possible / Tighten the return type of Channel.parent()

This commit is contained in:
Trustin Lee 2013-01-10 14:17:38 +09:00
parent 793a571465
commit 3c9d912355
11 changed files with 76 additions and 30 deletions

View File

@ -21,13 +21,16 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.SocketAddress; import java.net.InetSocketAddress;
import java.util.Set; import java.util.Set;
/** /**
* A SCTP/IP {@link Channel} * A SCTP/IP {@link Channel}
*/ */
public interface SctpChannel extends Channel { public interface SctpChannel extends Channel {
@Override
SctpServerChannel parent();
/** /**
* Returns the underlying SCTP association. * Returns the underlying SCTP association.
*/ */
@ -44,13 +47,13 @@ public interface SctpChannel extends Channel {
* with SctpStandardSocketOption.SCTP_PRIMARY_ADDR option). * with SctpStandardSocketOption.SCTP_PRIMARY_ADDR option).
*/ */
@Override @Override
SocketAddress localAddress(); InetSocketAddress localAddress();
/** /**
* Return all local addresses of the SCTP channel. * Return all local addresses of the SCTP channel.
* Please note that, it will return more than one address if this channel is using multi-homing * Please note that, it will return more than one address if this channel is using multi-homing
*/ */
Set<SocketAddress> allLocalAddresses(); Set<InetSocketAddress> allLocalAddresses();
/** /**
* Returns the {@link SctpChannelConfig} configuration of the channel. * Returns the {@link SctpChannelConfig} configuration of the channel.
@ -69,13 +72,13 @@ public interface SctpChannel extends Channel {
* calling the local SCTP stack with SctpStandardSocketOption.SCTP_SET_PEER_PRIMARY_ADDR option) * calling the local SCTP stack with SctpStandardSocketOption.SCTP_SET_PEER_PRIMARY_ADDR option)
*/ */
@Override @Override
SocketAddress remoteAddress(); InetSocketAddress remoteAddress();
/** /**
* Return all remote addresses of the SCTP server channel. * Return all remote addresses of the SCTP server channel.
* Please note that, it will return more than one address if the remote is using multi-homing. * Please note that, it will return more than one address if the remote is using multi-homing.
*/ */
Set<SocketAddress> allRemoteAddresses(); Set<InetSocketAddress> allRemoteAddresses();
/** /**
* Bind a address to the already bound channel to enable multi-homing. * Bind a address to the already bound channel to enable multi-homing.

View File

@ -17,7 +17,7 @@ package io.netty.channel.socket.sctp;
import io.netty.channel.ServerChannel; import io.netty.channel.ServerChannel;
import java.net.SocketAddress; import java.net.InetSocketAddress;
import java.util.Set; import java.util.Set;
/** /**
@ -45,11 +45,11 @@ public interface SctpServerChannel extends ServerChannel {
* with SctpStandardSocketOption.SCTP_PRIMARY_ADDR option). * with SctpStandardSocketOption.SCTP_PRIMARY_ADDR option).
*/ */
@Override @Override
SocketAddress localAddress(); InetSocketAddress localAddress();
/** /**
* Return all local addresses of the SCTP server channel. * Return all local addresses of the SCTP server channel.
* Please note that, it will return more than one address if this channel is using multi-homing * Please note that, it will return more than one address if this channel is using multi-homing
*/ */
Set<SocketAddress> allLocalAddresses(); Set<InetSocketAddress> allLocalAddresses();
} }

View File

@ -32,17 +32,20 @@ import io.netty.channel.socket.sctp.DefaultSctpChannelConfig;
import io.netty.channel.socket.sctp.SctpChannelConfig; import io.netty.channel.socket.sctp.SctpChannelConfig;
import io.netty.channel.socket.sctp.SctpMessage; import io.netty.channel.socket.sctp.SctpMessage;
import io.netty.channel.socket.sctp.SctpNotificationHandler; import io.netty.channel.socket.sctp.SctpNotificationHandler;
import io.netty.channel.socket.sctp.SctpServerChannel;
import io.netty.logging.InternalLogger; import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory; import io.netty.logging.InternalLoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
/** /**
@ -113,6 +116,11 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
} }
} }
@Override
public SctpServerChannel parent() {
return (SctpServerChannel) super.parent();
}
@Override @Override
public ChannelMetadata metadata() { public ChannelMetadata metadata() {
return METADATA; return METADATA;
@ -128,12 +136,12 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
} }
@Override @Override
public Set<SocketAddress> allLocalAddresses() { public Set<InetSocketAddress> allLocalAddresses() {
try { try {
final Set<SocketAddress> allLocalAddresses = javaChannel().getAllLocalAddresses(); final Set<SocketAddress> allLocalAddresses = javaChannel().getAllLocalAddresses();
final Set<SocketAddress> addresses = new HashSet<SocketAddress>(allLocalAddresses.size()); final Set<InetSocketAddress> addresses = new LinkedHashSet<InetSocketAddress>(allLocalAddresses.size());
for (SocketAddress socketAddress : allLocalAddresses) { for (SocketAddress socketAddress : allLocalAddresses) {
addresses.add(socketAddress); addresses.add((InetSocketAddress) socketAddress);
} }
return addresses; return addresses;
} catch (Throwable t) { } catch (Throwable t) {
@ -147,12 +155,12 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
} }
@Override @Override
public Set<SocketAddress> allRemoteAddresses() { public Set<InetSocketAddress> allRemoteAddresses() {
try { try {
final Set<SocketAddress> allLocalAddresses = javaChannel().getRemoteAddresses(); final Set<SocketAddress> allLocalAddresses = javaChannel().getRemoteAddresses();
final Set<SocketAddress> addresses = new HashSet<SocketAddress>(allLocalAddresses.size()); final Set<InetSocketAddress> addresses = new HashSet<InetSocketAddress>(allLocalAddresses.size());
for (SocketAddress socketAddress : allLocalAddresses) { for (SocketAddress socketAddress : allLocalAddresses) {
addresses.add(socketAddress); addresses.add((InetSocketAddress) socketAddress);
} }
return addresses; return addresses;
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -30,8 +30,8 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
/** /**
@ -70,12 +70,12 @@ public class NioSctpServerChannel extends AbstractNioMessageChannel
} }
@Override @Override
public Set<SocketAddress> allLocalAddresses() { public Set<InetSocketAddress> allLocalAddresses() {
try { try {
final Set<SocketAddress> allLocalAddresses = javaChannel().getAllLocalAddresses(); final Set<SocketAddress> allLocalAddresses = javaChannel().getAllLocalAddresses();
final Set<SocketAddress> addresses = new HashSet<SocketAddress>(allLocalAddresses.size()); final Set<InetSocketAddress> addresses = new LinkedHashSet<InetSocketAddress>(allLocalAddresses.size());
for (SocketAddress socketAddress : allLocalAddresses) { for (SocketAddress socketAddress : allLocalAddresses) {
addresses.add(socketAddress); addresses.add((InetSocketAddress) socketAddress);
} }
return addresses; return addresses;
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -32,18 +32,20 @@ import io.netty.channel.socket.sctp.DefaultSctpChannelConfig;
import io.netty.channel.socket.sctp.SctpChannelConfig; import io.netty.channel.socket.sctp.SctpChannelConfig;
import io.netty.channel.socket.sctp.SctpMessage; import io.netty.channel.socket.sctp.SctpMessage;
import io.netty.channel.socket.sctp.SctpNotificationHandler; import io.netty.channel.socket.sctp.SctpNotificationHandler;
import io.netty.channel.socket.sctp.SctpServerChannel;
import io.netty.logging.InternalLogger; import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory; import io.netty.logging.InternalLoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.Selector; import java.nio.channels.Selector;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
/** /**
@ -132,6 +134,11 @@ public class OioSctpChannel extends AbstractOioMessageChannel
} }
} }
@Override
public SctpServerChannel parent() {
return (SctpServerChannel) super.parent();
}
@Override @Override
public ChannelMetadata metadata() { public ChannelMetadata metadata() {
return METADATA; return METADATA;
@ -270,12 +277,12 @@ public class OioSctpChannel extends AbstractOioMessageChannel
} }
@Override @Override
public Set<SocketAddress> allLocalAddresses() { public Set<InetSocketAddress> allLocalAddresses() {
try { try {
final Set<SocketAddress> allLocalAddresses = ch.getAllLocalAddresses(); final Set<SocketAddress> allLocalAddresses = ch.getAllLocalAddresses();
final Set<SocketAddress> addresses = new HashSet<SocketAddress>(allLocalAddresses.size()); final Set<InetSocketAddress> addresses = new LinkedHashSet<InetSocketAddress>(allLocalAddresses.size());
for (SocketAddress socketAddress : allLocalAddresses) { for (SocketAddress socketAddress : allLocalAddresses) {
addresses.add(socketAddress); addresses.add((InetSocketAddress) socketAddress);
} }
return addresses; return addresses;
} catch (Throwable t) { } catch (Throwable t) {
@ -297,12 +304,12 @@ public class OioSctpChannel extends AbstractOioMessageChannel
} }
@Override @Override
public Set<SocketAddress> allRemoteAddresses() { public Set<InetSocketAddress> allRemoteAddresses() {
try { try {
final Set<SocketAddress> allLocalAddresses = ch.getRemoteAddresses(); final Set<SocketAddress> allLocalAddresses = ch.getRemoteAddresses();
final Set<SocketAddress> addresses = new HashSet<SocketAddress>(allLocalAddresses.size()); final Set<InetSocketAddress> addresses = new LinkedHashSet<InetSocketAddress>(allLocalAddresses.size());
for (SocketAddress socketAddress : allLocalAddresses) { for (SocketAddress socketAddress : allLocalAddresses) {
addresses.add(socketAddress); addresses.add((InetSocketAddress) socketAddress);
} }
return addresses; return addresses;
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -21,9 +21,9 @@ import io.netty.buffer.BufType;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
import io.netty.channel.socket.oio.AbstractOioMessageChannel;
import io.netty.channel.socket.sctp.DefaultSctpServerChannelConfig; import io.netty.channel.socket.sctp.DefaultSctpServerChannelConfig;
import io.netty.channel.socket.sctp.SctpServerChannelConfig; import io.netty.channel.socket.sctp.SctpServerChannelConfig;
import io.netty.channel.socket.oio.AbstractOioMessageChannel;
import io.netty.logging.InternalLogger; import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory; import io.netty.logging.InternalLoggerFactory;
@ -33,8 +33,8 @@ import java.net.SocketAddress;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.Selector; import java.nio.channels.Selector;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
/** /**
@ -147,12 +147,12 @@ public class OioSctpServerChannel extends AbstractOioMessageChannel
} }
@Override @Override
public Set<SocketAddress> allLocalAddresses() { public Set<InetSocketAddress> allLocalAddresses() {
try { try {
final Set<SocketAddress> allLocalAddresses = sch.getAllLocalAddresses(); final Set<SocketAddress> allLocalAddresses = sch.getAllLocalAddresses();
final Set<SocketAddress> addresses = new HashSet<SocketAddress>(allLocalAddresses.size()); final Set<InetSocketAddress> addresses = new LinkedHashSet<InetSocketAddress>(allLocalAddresses.size());
for (SocketAddress socketAddress : allLocalAddresses) { for (SocketAddress socketAddress : allLocalAddresses) {
addresses.add(socketAddress); addresses.add((InetSocketAddress) socketAddress);
} }
return addresses; return addresses;
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -18,6 +18,8 @@ package io.netty.transport.udt;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.transport.udt.nio.NioUdtProvider; import io.netty.transport.udt.nio.NioUdtProvider;
import java.net.InetSocketAddress;
/** /**
* UDT {@link Channel}. * UDT {@link Channel}.
* <p> * <p>
@ -31,4 +33,9 @@ public interface UdtChannel extends Channel {
@Override @Override
UdtChannelConfig config(); UdtChannelConfig config();
@Override
InetSocketAddress localAddress();
@Override
InetSocketAddress remoteAddress();
} }

View File

@ -29,6 +29,9 @@ import java.net.Socket;
* @apiviz.composedOf io.netty.channel.socket.SocketChannelConfig * @apiviz.composedOf io.netty.channel.socket.SocketChannelConfig
*/ */
public interface SocketChannel extends Channel { public interface SocketChannel extends Channel {
@Override
ServerSocketChannel parent();
@Override @Override
SocketChannelConfig config(); SocketChannelConfig config();
@Override @Override

View File

@ -26,6 +26,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.FileRegion; import io.netty.channel.FileRegion;
import io.netty.channel.socket.ChannelInputShutdownEvent; import io.netty.channel.socket.ChannelInputShutdownEvent;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import java.io.IOException; import java.io.IOException;
@ -101,6 +102,11 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
config = new DefaultAioSocketChannelConfig(this, ch); config = new DefaultAioSocketChannelConfig(this, ch);
} }
@Override
public ServerSocketChannel parent() {
return (ServerSocketChannel) super.parent();
}
@Override @Override
public boolean isActive() { public boolean isActive() {
return ch != null && javaChannel().isOpen() && remoteAddress0() != null; return ch != null && javaChannel().isOpen() && remoteAddress0() != null;

View File

@ -24,6 +24,7 @@ import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.socket.DefaultSocketChannelConfig; import io.netty.channel.socket.DefaultSocketChannelConfig;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannelConfig; import io.netty.channel.socket.SocketChannelConfig;
import io.netty.logging.InternalLogger; import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory; import io.netty.logging.InternalLoggerFactory;
@ -93,6 +94,11 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
config = new DefaultSocketChannelConfig(this, socket.socket()); config = new DefaultSocketChannelConfig(this, socket.socket());
} }
@Override
public ServerSocketChannel parent() {
return (ServerSocketChannel) super.parent();
}
@Override @Override
public ChannelMetadata metadata() { public ChannelMetadata metadata() {
return METADATA; return METADATA;

View File

@ -25,6 +25,7 @@ import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.FileRegion; import io.netty.channel.FileRegion;
import io.netty.channel.socket.DefaultSocketChannelConfig; import io.netty.channel.socket.DefaultSocketChannelConfig;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.SocketChannelConfig; import io.netty.channel.socket.SocketChannelConfig;
import io.netty.logging.InternalLogger; import io.netty.logging.InternalLogger;
@ -108,6 +109,11 @@ public class OioSocketChannel extends AbstractOioByteChannel
} }
} }
@Override
public ServerSocketChannel parent() {
return (ServerSocketChannel) super.parent();
}
@Override @Override
public ChannelMetadata metadata() { public ChannelMetadata metadata() {
return METADATA; return METADATA;