Use InetSocketAddress wherever possible / Tighten the return type of Channel.parent()
This commit is contained in:
parent
793a571465
commit
3c9d912355
@ -21,13 +21,16 @@ import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A SCTP/IP {@link Channel}
|
||||
*/
|
||||
public interface SctpChannel extends Channel {
|
||||
@Override
|
||||
SctpServerChannel parent();
|
||||
|
||||
/**
|
||||
* Returns the underlying SCTP association.
|
||||
*/
|
||||
@ -44,13 +47,13 @@ public interface SctpChannel extends Channel {
|
||||
* with SctpStandardSocketOption.SCTP_PRIMARY_ADDR option).
|
||||
*/
|
||||
@Override
|
||||
SocketAddress localAddress();
|
||||
InetSocketAddress localAddress();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
Set<SocketAddress> allLocalAddresses();
|
||||
Set<InetSocketAddress> allLocalAddresses();
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
@Override
|
||||
SocketAddress remoteAddress();
|
||||
InetSocketAddress remoteAddress();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
Set<SocketAddress> allRemoteAddresses();
|
||||
Set<InetSocketAddress> allRemoteAddresses();
|
||||
|
||||
/**
|
||||
* Bind a address to the already bound channel to enable multi-homing.
|
||||
|
@ -17,7 +17,7 @@ package io.netty.channel.socket.sctp;
|
||||
|
||||
import io.netty.channel.ServerChannel;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -45,11 +45,11 @@ public interface SctpServerChannel extends ServerChannel {
|
||||
* with SctpStandardSocketOption.SCTP_PRIMARY_ADDR option).
|
||||
*/
|
||||
@Override
|
||||
SocketAddress localAddress();
|
||||
InetSocketAddress localAddress();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
Set<SocketAddress> allLocalAddresses();
|
||||
Set<InetSocketAddress> allLocalAddresses();
|
||||
}
|
||||
|
@ -32,17 +32,20 @@ import io.netty.channel.socket.sctp.DefaultSctpChannelConfig;
|
||||
import io.netty.channel.socket.sctp.SctpChannelConfig;
|
||||
import io.netty.channel.socket.sctp.SctpMessage;
|
||||
import io.netty.channel.socket.sctp.SctpNotificationHandler;
|
||||
import io.netty.channel.socket.sctp.SctpServerChannel;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
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
|
||||
public ChannelMetadata metadata() {
|
||||
return METADATA;
|
||||
@ -128,12 +136,12 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SocketAddress> allLocalAddresses() {
|
||||
public Set<InetSocketAddress> allLocalAddresses() {
|
||||
try {
|
||||
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) {
|
||||
addresses.add(socketAddress);
|
||||
addresses.add((InetSocketAddress) socketAddress);
|
||||
}
|
||||
return addresses;
|
||||
} catch (Throwable t) {
|
||||
@ -147,12 +155,12 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SocketAddress> allRemoteAddresses() {
|
||||
public Set<InetSocketAddress> allRemoteAddresses() {
|
||||
try {
|
||||
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) {
|
||||
addresses.add(socketAddress);
|
||||
addresses.add((InetSocketAddress) socketAddress);
|
||||
}
|
||||
return addresses;
|
||||
} catch (Throwable t) {
|
||||
|
@ -30,8 +30,8 @@ import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -70,12 +70,12 @@ public class NioSctpServerChannel extends AbstractNioMessageChannel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SocketAddress> allLocalAddresses() {
|
||||
public Set<InetSocketAddress> allLocalAddresses() {
|
||||
try {
|
||||
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) {
|
||||
addresses.add(socketAddress);
|
||||
addresses.add((InetSocketAddress) socketAddress);
|
||||
}
|
||||
return addresses;
|
||||
} catch (Throwable t) {
|
||||
|
@ -32,18 +32,20 @@ import io.netty.channel.socket.sctp.DefaultSctpChannelConfig;
|
||||
import io.netty.channel.socket.sctp.SctpChannelConfig;
|
||||
import io.netty.channel.socket.sctp.SctpMessage;
|
||||
import io.netty.channel.socket.sctp.SctpNotificationHandler;
|
||||
import io.netty.channel.socket.sctp.SctpServerChannel;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -132,6 +134,11 @@ public class OioSctpChannel extends AbstractOioMessageChannel
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SctpServerChannel parent() {
|
||||
return (SctpServerChannel) super.parent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMetadata metadata() {
|
||||
return METADATA;
|
||||
@ -270,12 +277,12 @@ public class OioSctpChannel extends AbstractOioMessageChannel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SocketAddress> allLocalAddresses() {
|
||||
public Set<InetSocketAddress> allLocalAddresses() {
|
||||
try {
|
||||
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) {
|
||||
addresses.add(socketAddress);
|
||||
addresses.add((InetSocketAddress) socketAddress);
|
||||
}
|
||||
return addresses;
|
||||
} catch (Throwable t) {
|
||||
@ -297,12 +304,12 @@ public class OioSctpChannel extends AbstractOioMessageChannel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SocketAddress> allRemoteAddresses() {
|
||||
public Set<InetSocketAddress> allRemoteAddresses() {
|
||||
try {
|
||||
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) {
|
||||
addresses.add(socketAddress);
|
||||
addresses.add((InetSocketAddress) socketAddress);
|
||||
}
|
||||
return addresses;
|
||||
} catch (Throwable t) {
|
||||
|
@ -21,9 +21,9 @@ import io.netty.buffer.BufType;
|
||||
import io.netty.buffer.MessageBuf;
|
||||
import io.netty.channel.ChannelException;
|
||||
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.SctpServerChannelConfig;
|
||||
import io.netty.channel.socket.oio.AbstractOioMessageChannel;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
@ -33,8 +33,8 @@ import java.net.SocketAddress;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -147,12 +147,12 @@ public class OioSctpServerChannel extends AbstractOioMessageChannel
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<SocketAddress> allLocalAddresses() {
|
||||
public Set<InetSocketAddress> allLocalAddresses() {
|
||||
try {
|
||||
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) {
|
||||
addresses.add(socketAddress);
|
||||
addresses.add((InetSocketAddress) socketAddress);
|
||||
}
|
||||
return addresses;
|
||||
} catch (Throwable t) {
|
||||
|
@ -18,6 +18,8 @@ package io.netty.transport.udt;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.transport.udt.nio.NioUdtProvider;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* UDT {@link Channel}.
|
||||
* <p>
|
||||
@ -31,4 +33,9 @@ public interface UdtChannel extends Channel {
|
||||
@Override
|
||||
UdtChannelConfig config();
|
||||
|
||||
@Override
|
||||
InetSocketAddress localAddress();
|
||||
@Override
|
||||
InetSocketAddress remoteAddress();
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ import java.net.Socket;
|
||||
* @apiviz.composedOf io.netty.channel.socket.SocketChannelConfig
|
||||
*/
|
||||
public interface SocketChannel extends Channel {
|
||||
@Override
|
||||
ServerSocketChannel parent();
|
||||
|
||||
@Override
|
||||
SocketChannelConfig config();
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.FileRegion;
|
||||
import io.netty.channel.socket.ChannelInputShutdownEvent;
|
||||
import io.netty.channel.socket.ServerSocketChannel;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -101,6 +102,11 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
|
||||
config = new DefaultAioSocketChannelConfig(this, ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSocketChannel parent() {
|
||||
return (ServerSocketChannel) super.parent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return ch != null && javaChannel().isOpen() && remoteAddress0() != null;
|
||||
|
@ -24,6 +24,7 @@ import io.netty.channel.ChannelMetadata;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.socket.DefaultSocketChannelConfig;
|
||||
import io.netty.channel.socket.ServerSocketChannel;
|
||||
import io.netty.channel.socket.SocketChannelConfig;
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
@ -93,6 +94,11 @@ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty
|
||||
config = new DefaultSocketChannelConfig(this, socket.socket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSocketChannel parent() {
|
||||
return (ServerSocketChannel) super.parent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMetadata metadata() {
|
||||
return METADATA;
|
||||
|
@ -25,6 +25,7 @@ import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.FileRegion;
|
||||
import io.netty.channel.socket.DefaultSocketChannelConfig;
|
||||
import io.netty.channel.socket.ServerSocketChannel;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.SocketChannelConfig;
|
||||
import io.netty.logging.InternalLogger;
|
||||
@ -108,6 +109,11 @@ public class OioSocketChannel extends AbstractOioByteChannel
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSocketChannel parent() {
|
||||
return (ServerSocketChannel) super.parent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMetadata metadata() {
|
||||
return METADATA;
|
||||
|
Loading…
Reference in New Issue
Block a user