本文整理汇总了Java中io.netty.channel.local.LocalAddress类的典型用法代码示例。如果您正苦于以下问题:Java LocalAddress类的具体用法?Java LocalAddress怎么用?Java LocalAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalAddress类属于io.netty.channel.local包,在下文中一共展示了LocalAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldInheritClusterOverride
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
@Test
public void shouldInheritClusterOverride() {
BoundCluster cluster =
new BoundCluster(
ClusterSpec.builder().withPeerInfo("protocol_versions", Lists.newArrayList(5)).build(),
0L,
null);
BoundDataCenter dc = new BoundDataCenter(cluster);
BoundNode node =
new BoundNode(
new LocalAddress(UUID.randomUUID().toString()),
NodeSpec.builder().withName("node0").withId(0L).build(),
Collections.emptyMap(),
cluster,
dc,
null,
timer,
null, // channel reference only needed for closing, not useful in context of this test.
false);
assertThat(node.getFrameCodec().getSupportedProtocolVersions()).containsOnly(5);
assertThat(dc.getFrameCodec().getSupportedProtocolVersions()).containsOnly(5);
assertThat(cluster.getFrameCodec().getSupportedProtocolVersions()).containsOnly(5);
}
示例2: shouldInheritClusterOverrideFromCassandraVersion
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
@Test
public void shouldInheritClusterOverrideFromCassandraVersion() {
BoundCluster cluster =
new BoundCluster(ClusterSpec.builder().withCassandraVersion("2.1.17").build(), 0L, null);
BoundDataCenter dc = new BoundDataCenter(cluster);
BoundNode node =
new BoundNode(
new LocalAddress(UUID.randomUUID().toString()),
NodeSpec.builder().withName("node0").withId(0L).build(),
Collections.emptyMap(),
cluster,
dc,
null,
timer,
null, // channel reference only needed for closing, not useful in context of this test.
false);
assertThat(node.getFrameCodec().getSupportedProtocolVersions()).containsOnly(3);
assertThat(dc.getFrameCodec().getSupportedProtocolVersions()).containsOnly(3);
assertThat(cluster.getFrameCodec().getSupportedProtocolVersions()).containsOnly(3);
}
示例3: testShouldUseProtocolVersionOverride
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
@Test
public void testShouldUseProtocolVersionOverride() {
BoundCluster cluster = new BoundCluster(ClusterSpec.builder().build(), 0L, null);
BoundDataCenter dc = new BoundDataCenter(cluster);
BoundNode node =
new BoundNode(
new LocalAddress(UUID.randomUUID().toString()),
NodeSpec.builder()
.withName("node0")
.withId(0L)
.withCassandraVersion("2.1.17")
.withPeerInfo("protocol_versions", Lists.newArrayList(4))
.build(),
Collections.emptyMap(),
cluster,
dc,
null,
timer,
null, // channel reference only needed for closing, not useful in context of this test.
false);
assertThat(node.getFrameCodec().getSupportedProtocolVersions()).containsOnly(4);
}
示例4: testProtocolVersionForCassandraVersion
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
public void testProtocolVersionForCassandraVersion(
String cassandraVersion, Integer... expectedProtocolVersions) {
BoundCluster cluster = new BoundCluster(ClusterSpec.builder().build(), 0L, null);
BoundDataCenter dc = new BoundDataCenter(cluster);
BoundNode node =
new BoundNode(
new LocalAddress(UUID.randomUUID().toString()),
NodeSpec.builder()
.withName("node0")
.withId(0L)
.withCassandraVersion(cassandraVersion)
.build(),
Collections.emptyMap(),
cluster,
dc,
null,
timer,
null, // channel reference only needed for closing, not useful in context of this test.
false);
assertThat(node.getFrameCodec().getSupportedProtocolVersions())
.containsOnly(expectedProtocolVersions);
}
示例5: addLocalEndpoint
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
/**
* Adds a channel that listens locally
*/
public SocketAddress addLocalEndpoint()
{
ChannelFuture channelfuture;
synchronized (this.endpoints)
{
channelfuture = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(LocalServerChannel.class)).childHandler(new ChannelInitializer<Channel>()
{
protected void initChannel(Channel p_initChannel_1_) throws Exception
{
NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
networkmanager.setNetHandler(new NetHandlerHandshakeMemory(NetworkSystem.this.mcServer, networkmanager));
NetworkSystem.this.networkManagers.add(networkmanager);
p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
}
}).group((EventLoopGroup)eventLoops.getValue()).localAddress(LocalAddress.ANY)).bind().syncUninterruptibly();
this.endpoints.add(channelfuture);
}
return channelfuture.channel().localAddress();
}
示例6: main
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
NettyServerBuilder.forAddress(LocalAddress.ANY).forPort(19876)
.maxConcurrentCallsPerConnection(12).maxMessageSize(16777216)
.addService(new MockApplicationRegisterService())
.addService(new MockInstanceDiscoveryService())
.addService(new MockJVMMetricsService())
.addService(new MockServiceNameDiscoveryService())
.addService(new MockTraceSegmentService()).build().start();
Server jettyServer = new Server(new InetSocketAddress("0.0.0.0",
Integer.valueOf(12800)));
String contextPath = "/";
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
servletContextHandler.setContextPath(contextPath);
servletContextHandler.addServlet(GrpcAddressHttpService.class, GrpcAddressHttpService.SERVLET_PATH);
servletContextHandler.addServlet(ReceiveDataService.class, ReceiveDataService.SERVLET_PATH);
servletContextHandler.addServlet(ClearReceiveDataService.class, ClearReceiveDataService.SERVLET_PATH);
jettyServer.setHandler(servletContextHandler);
jettyServer.start();
}
示例7: addLocalEndpoint
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
/**
* Adds a channel that listens locally
*/
public SocketAddress addLocalEndpoint()
{
ChannelFuture channelfuture;
synchronized (this.endpoints)
{
channelfuture = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(LocalServerChannel.class)).childHandler(new ChannelInitializer<Channel>()
{
protected void initChannel(Channel p_initChannel_1_) throws Exception
{
NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
networkmanager.setNetHandler(new NetHandlerHandshakeMemory(NetworkSystem.this.mcServer, networkmanager));
NetworkSystem.this.networkManagers.add(networkmanager);
p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
}
}).group((EventLoopGroup)SERVER_NIO_EVENTLOOP.getValue()).localAddress(LocalAddress.ANY)).bind().syncUninterruptibly();
this.endpoints.add(channelfuture);
}
return channelfuture.channel().localAddress();
}
示例8: addLocalEndpoint
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
/**
* Adds a channel that listens locally
*/
@SideOnly(Side.CLIENT)
public SocketAddress addLocalEndpoint()
{
ChannelFuture channelfuture;
synchronized (this.endpoints)
{
channelfuture = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(LocalServerChannel.class)).childHandler(new ChannelInitializer<Channel>()
{
protected void initChannel(Channel p_initChannel_1_) throws Exception
{
NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.SERVERBOUND);
networkmanager.setNetHandler(new NetHandlerHandshakeMemory(NetworkSystem.this.mcServer, networkmanager));
NetworkSystem.this.networkManagers.add(networkmanager);
p_initChannel_1_.pipeline().addLast((String)"packet_handler", (ChannelHandler)networkmanager);
}
}).group((EventLoopGroup)SERVER_NIO_EVENTLOOP.getValue()).localAddress(LocalAddress.ANY)).bind().syncUninterruptibly();
this.endpoints.add(channelfuture);
}
return channelfuture.channel().localAddress();
}
示例9: SimpleConnectionPool
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
public SimpleConnectionPool(Bootstrap bootstrap, HandlerConfig handlerConfig, SocketAddress remoteAddress, int connectTimeout) {
super(bootstrap, new RpcClientChannelPoolHandler(handlerConfig, remoteAddress));
this.connectTimeout = connectTimeout;
this.socketAddress = remoteAddress;
if (remoteAddress instanceof InetSocketAddress) {
InetSocketAddress inetSocketAddress = (InetSocketAddress) remoteAddress;
host = inetSocketAddress.getAddress().getHostAddress();
port = inetSocketAddress.getPort();
} else if (remoteAddress instanceof LocalAddress) {
LocalAddress localAddress = (LocalAddress) remoteAddress;
int myPort = -1;
try {
myPort = Integer.parseInt(localAddress.id());
} catch (NumberFormatException e) {
throw new RpcFrameworkException(localAddress.id() + " port parse error", e);
}
host = "local";
port = myPort;
} else {
throw new RpcFrameworkException(
"SocketAddress must be '" + InetSocketAddress.class.getName() + "' or '" + LocalAddress.class.getName() + "' (sub) class");
}
poolContext = new ConnectionPoolContext(handlerConfig.getResponsePromiseContainer());
}
示例10: setUpServer
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
/**
* Sets up a server channel bound to the given local address.
*
* @return the event loop group used to process incoming connections.
*/
static EventLoopGroup setUpServer(
ChannelInitializer<LocalChannel> serverInitializer, LocalAddress localAddress)
throws Exception {
// Only use one thread in the event loop group. The same event loop group will be used to
// register client channels during setUpClient as well. This ensures that all I/O activities
// in both channels happen in the same thread, making debugging easier (i. e. no need to jump
// between threads when debugging, everything happens synchronously within the only I/O
// effectively). Note that the main thread is still separate from the I/O thread and
// synchronization (using the lock field) is still needed when the main thread needs to verify
// properties calculated by the I/O thread.
EventLoopGroup eventLoopGroup = new NioEventLoopGroup(1);
ServerBootstrap sb =
new ServerBootstrap()
.group(eventLoopGroup)
.channel(LocalServerChannel.class)
.childHandler(serverInitializer);
ChannelFuture unusedFuture = sb.bind(localAddress).syncUninterruptibly();
return eventLoopGroup;
}
示例11: addLocalEndpoint
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
@SideOnly(Side.CLIENT)
public SocketAddress addLocalEndpoint()
{
List list = this.endpoints;
ChannelFuture channelfuture;
synchronized (this.endpoints)
{
channelfuture = ((ServerBootstrap)((ServerBootstrap)(new ServerBootstrap()).channel(LocalServerChannel.class)).childHandler(new ChannelInitializer()
{
private static final String __OBFID = "CL_00001449";
protected void initChannel(Channel p_initChannel_1_)
{
NetworkManager networkmanager = new NetworkManager(false);
networkmanager.setNetHandler(new NetHandlerHandshakeMemory(NetworkSystem.this.mcServer, networkmanager));
NetworkSystem.this.networkManagers.add(networkmanager);
p_initChannel_1_.pipeline().addLast("packet_handler", networkmanager);
}
}).group(eventLoops).localAddress(LocalAddress.ANY)).bind().syncUninterruptibly();
this.endpoints.add(channelfuture);
}
return channelfuture.channel().localAddress();
}
示例12: shouldInheritDCOverride
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
@Test
public void shouldInheritDCOverride() {
ClusterSpec clusterSpec =
ClusterSpec.builder().withPeerInfo("protocol_versions", Lists.newArrayList(5)).build();
BoundCluster cluster = new BoundCluster(clusterSpec, 0L, null);
DataCenterSpec dcSpec =
clusterSpec
.addDataCenter()
.withPeerInfo("protocol_versions", Lists.newArrayList(4))
.build();
BoundDataCenter dc = new BoundDataCenter(dcSpec, cluster);
BoundNode node =
new BoundNode(
new LocalAddress(UUID.randomUUID().toString()),
NodeSpec.builder().withName("node0").withId(0L).build(),
Collections.emptyMap(),
cluster,
dc,
null,
timer,
null, // channel reference only needed for closing, not useful in context of this test.
false);
assertThat(node.getFrameCodec().getSupportedProtocolVersions()).containsOnly(4);
assertThat(dc.getFrameCodec().getSupportedProtocolVersions()).containsOnly(4);
assertThat(cluster.getFrameCodec().getSupportedProtocolVersions()).containsOnly(5);
}
示例13: getHostString
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
public static String getHostString(SocketAddress address) {
if (address instanceof InetSocketAddress) {
return ((InetSocketAddress) address).getHostString();
} else if (address instanceof LocalAddress) {
return LOCAL_ADDRESS;
}
return address.toString();
}
示例14: testFailure_defaultTrustManager_rejectSelfSignedCert
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
@Test
public void testFailure_defaultTrustManager_rejectSelfSignedCert() throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate(SSL_HOST);
LocalAddress localAddress = new LocalAddress("DEFAULT_TRUST_MANAGER_REJECT_SELF_SIGNED_CERT");
Lock clientLock = new ReentrantLock();
Lock serverLock = new ReentrantLock();
ByteBuf buffer = Unpooled.buffer();
Exception clientException = new Exception();
Exception serverException = new Exception();
EventLoopGroup eventLoopGroup =
setUpServer(
getServerInitializer(ssc.key(), ssc.cert(), serverLock, serverException), localAddress);
SslClientInitializer<LocalChannel> sslClientInitializer =
new SslClientInitializer<>(SslProvider.JDK, (X509Certificate[]) null);
Channel channel =
setUpClient(
eventLoopGroup,
getClientInitializer(sslClientInitializer, clientLock, buffer, clientException),
localAddress,
PROTOCOL);
// Wait for handshake exception to throw.
clientLock.lock();
serverLock.lock();
// The connection is now terminated, both the client side and the server side should get
// exceptions (caught in the caughtException method in EchoHandler and DumpHandler,
// respectively).
assertThat(clientException).hasCauseThat().isInstanceOf(DecoderException.class);
assertThat(clientException)
.hasCauseThat()
.hasCauseThat()
.isInstanceOf(SSLHandshakeException.class);
assertThat(serverException).hasCauseThat().isInstanceOf(DecoderException.class);
assertThat(serverException).hasCauseThat().hasCauseThat().isInstanceOf(SSLException.class);
assertThat(channel.isActive()).isFalse();
Future<?> unusedFuture = eventLoopGroup.shutdownGracefully().syncUninterruptibly();
}
示例15: testSuccess_customTrustManager_acceptCertSignedByTrustedCa
import io.netty.channel.local.LocalAddress; //导入依赖的package包/类
@Test
public void testSuccess_customTrustManager_acceptCertSignedByTrustedCa() throws Exception {
LocalAddress localAddress =
new LocalAddress("CUSTOM_TRUST_MANAGER_ACCEPT_CERT_SIGNED_BY_TRUSTED_CA");
Lock clientLock = new ReentrantLock();
Lock serverLock = new ReentrantLock();
ByteBuf buffer = Unpooled.buffer();
Exception clientException = new Exception();
Exception serverException = new Exception();
// Generate a new key pair.
KeyPair keyPair = getKeyPair();
// Generate a self signed certificate, and use it to sign the key pair.
SelfSignedCertificate ssc = new SelfSignedCertificate();
X509Certificate cert = signKeyPair(ssc, keyPair, SSL_HOST);
// Set up the server to use the signed cert and private key to perform handshake;
PrivateKey privateKey = keyPair.getPrivate();
EventLoopGroup eventLoopGroup =
setUpServer(
getServerInitializer(privateKey, cert, serverLock, serverException), localAddress);
// Set up the client to trust the self signed cert used to sign the cert that server provides.
SslClientInitializer<LocalChannel> sslClientInitializer =
new SslClientInitializer<>(SslProvider.JDK, ssc.cert());
Channel channel =
setUpClient(
eventLoopGroup,
getClientInitializer(sslClientInitializer, clientLock, buffer, clientException),
localAddress,
PROTOCOL);
verifySslChannel(channel, ImmutableList.of(cert), clientLock, serverLock, buffer, SSL_HOST);
Future<?> unusedFuture = eventLoopGroup.shutdownGracefully().syncUninterruptibly();
}