本文整理匯總了Java中java.net.InetSocketAddress.getPort方法的典型用法代碼示例。如果您正苦於以下問題:Java InetSocketAddress.getPort方法的具體用法?Java InetSocketAddress.getPort怎麽用?Java InetSocketAddress.getPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.InetSocketAddress
的用法示例。
在下文中一共展示了InetSocketAddress.getPort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendFromNativeBuffer
import java.net.InetSocketAddress; //導入方法依賴的package包/類
private int sendFromNativeBuffer(int fd,
ByteBuffer bb,
SocketAddress target,
int assocId,
int streamNumber,
boolean unordered,
int ppid)
throws IOException {
InetAddress addr = null; // no preferred address
int port = 0;
if (target != null) {
InetSocketAddress isa = Net.checkAddress(target);
addr = isa.getAddress();
port = isa.getPort();
}
int pos = bb.position();
int lim = bb.limit();
assert (pos <= lim);
int rem = (pos <= lim ? lim - pos : 0);
int written = send0(fd, ((DirectBuffer)bb).address() + pos, rem, addr,
port, assocId, streamNumber, unordered, ppid);
if (written > 0)
bb.position(pos + written);
return written;
}
示例2: isClientSide
import java.net.InetSocketAddress; //導入方法依賴的package包/類
protected boolean isClientSide(Channel channel) {
String side = (String) channel.getAttribute(Constants.SIDE_KEY);
if ("client".equals(side)) {
return true;
} else if ("server".equals(side)) {
return false;
} else {
InetSocketAddress address = channel.getRemoteAddress();
URL url = channel.getUrl();
boolean client = url.getPort() == address.getPort()
&& NetUtils.filterLocalHost(url.getIp()).equals(
NetUtils.filterLocalHost(address.getAddress()
.getHostAddress()));
channel.setAttribute(Constants.SIDE_KEY, client ? "client"
: "server");
return client;
}
}
示例3: isConsumerSide
import java.net.InetSocketAddress; //導入方法依賴的package包/類
/**
* is consumer side.
*
* @return consumer side.
*/
public boolean isConsumerSide() {
URL url = getUrl();
if (url == null) {
return false;
}
InetSocketAddress address = getRemoteAddress();
if (address == null) {
return false;
}
String host;
if (address.getAddress() == null) {
host = address.getHostName();
} else {
host = address.getAddress().getHostAddress();
}
return url.getPort() == address.getPort() &&
NetUtils.filterLocalHost(url.getIp()).equals(NetUtils.filterLocalHost(host));
}
示例4: setFailoverConfigurations
import java.net.InetSocketAddress; //導入方法依賴的package包/類
/**
* Sets the required configurations for performing failover
*/
public static void setFailoverConfigurations(Configuration conf,
String logicalName, InetSocketAddress nnAddr1,
InetSocketAddress nnAddr2) {
String nameNodeId1 = "nn1";
String nameNodeId2 = "nn2";
String address1 = "hdfs://" + nnAddr1.getHostName() + ":" + nnAddr1.getPort();
String address2 = "hdfs://" + nnAddr2.getHostName() + ":" + nnAddr2.getPort();
conf.set(DFSUtil.addKeySuffixes(DFS_NAMENODE_RPC_ADDRESS_KEY,
logicalName, nameNodeId1), address1);
conf.set(DFSUtil.addKeySuffixes(DFS_NAMENODE_RPC_ADDRESS_KEY,
logicalName, nameNodeId2), address2);
conf.set(DFSConfigKeys.DFS_NAMESERVICES, logicalName);
conf.set(DFSUtil.addKeySuffixes(DFS_HA_NAMENODES_KEY_PREFIX, logicalName),
nameNodeId1 + "," + nameNodeId2);
conf.set(DFS_CLIENT_FAILOVER_PROXY_PROVIDER_KEY_PREFIX + "." + logicalName,
ConfiguredFailoverProxyProvider.class.getName());
conf.set("fs.defaultFS", "hdfs://" + logicalName);
}
示例5: getPermission
import java.net.InetSocketAddress; //導入方法依賴的package包/類
public final Permission getPermission() throws IOException {
int hostPort;
URL url = getURL();
String hostName = url.getHost();
if (url.getPort() != -1) {
hostPort = url.getPort();
} else {
hostPort = HttpUrl.defaultPort(url.getProtocol());
}
if (usingProxy()) {
InetSocketAddress proxyAddress = (InetSocketAddress) this.client.getProxy().address();
hostName = proxyAddress.getHostName();
hostPort = proxyAddress.getPort();
}
return new SocketPermission(hostName + ":" + hostPort, "connect, resolve");
}
示例6: bind
import java.net.InetSocketAddress; //導入方法依賴的package包/類
@Override
public SctpMultiChannel bind(SocketAddress local, int backlog)
throws IOException {
synchronized (receiveLock) {
synchronized (sendLock) {
synchronized (stateLock) {
ensureOpen();
if (isBound())
SctpNet.throwAlreadyBoundException();
InetSocketAddress isa = (local == null) ?
new InetSocketAddress(0) : Net.checkAddress(local);
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkListen(isa.getPort());
Net.bind(fd, isa.getAddress(), isa.getPort());
InetSocketAddress boundIsa = Net.localAddress(fd);
port = boundIsa.getPort();
localAddresses.add(isa);
if (isa.getAddress().isAnyLocalAddress())
wildcard = true;
SctpNet.listen(fdVal, backlog < 1 ? 50 : backlog);
}
}
}
return this;
}
示例7: bind
import java.net.InetSocketAddress; //導入方法依賴的package包/類
@Override
public SctpServerChannel bind(SocketAddress local, int backlog)
throws IOException {
synchronized (lock) {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (isBound())
SctpNet.throwAlreadyBoundException();
InetSocketAddress isa = (local == null) ?
new InetSocketAddress(0) : Net.checkAddress(local);
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkListen(isa.getPort());
Net.bind(fd, isa.getAddress(), isa.getPort());
InetSocketAddress boundIsa = Net.localAddress(fd);
port = boundIsa.getPort();
localAddresses.add(isa);
if (isa.getAddress().isAnyLocalAddress())
wildcard = true;
SctpNet.listen(fdVal, backlog < 1 ? 50 : backlog);
}
}
return this;
}
示例8: getParameter
import java.net.InetSocketAddress; //導入方法依賴的package包/類
@Override public Object getParameter(String name) {
if (name.equals(ConnRouteParams.DEFAULT_PROXY)) {
Proxy proxy = client.proxy();
if (proxy == null) {
return null;
}
InetSocketAddress address = (InetSocketAddress) proxy.address();
return new HttpHost(address.getHostName(), address.getPort());
}
throw new IllegalArgumentException(name);
}
示例9: getServer
import java.net.InetSocketAddress; //導入方法依賴的package包/類
private String getServer(Channel channel) {
String server = Context.getConfig().getString(getProtocolName() + ".server");
if (server == null) {
InetSocketAddress address = (InetSocketAddress) channel.getLocalAddress();
server = address.getAddress().getHostAddress() + ":" + address.getPort();
}
return server;
}
示例10: getPermission
import java.net.InetSocketAddress; //導入方法依賴的package包/類
@Override public Permission getPermission() throws IOException {
URL url = getURL();
String hostname = url.getHost();
int hostPort = url.getPort() != -1
? url.getPort()
: HttpUrl.defaultPort(url.getProtocol());
if (usingProxy()) {
InetSocketAddress proxyAddress = (InetSocketAddress) client.proxy().address();
hostname = proxyAddress.getHostName();
hostPort = proxyAddress.getPort();
}
return new SocketPermission(hostname + ":" + hostPort, "connect, resolve");
}
示例11: handleInbound
import java.net.InetSocketAddress; //導入方法依賴的package包/類
public void handleInbound(DiscoveryEvent discoveryEvent) {
Message m = discoveryEvent.getMessage();
InetSocketAddress sender = discoveryEvent.getAddress();
Node n = new Node(m.getNodeId(), sender.getHostString(), sender.getPort());
if (inboundOnlyFromKnownNodes && !hasNodeHandler(n)) {
logger.debug("=/=> (" + sender + "): inbound packet from unknown peer rejected due to config option.");
return;
}
NodeHandler nodeHandler = getNodeHandler(n);
logger.trace("===> ({}) {} [{}] {}", sender, m.getClass().getSimpleName(), nodeHandler, m);
byte type = m.getType()[0];
switch (type) {
case 1:
nodeHandler.handlePing((PingMessage) m);
break;
case 2:
nodeHandler.handlePong((PongMessage) m);
break;
case 3:
nodeHandler.handleFindNode((FindNodeMessage) m);
break;
case 4:
nodeHandler.handleNeighbours((NeighborsMessage) m);
break;
}
}
示例12: testPreConfiguredConnectorAndServerHandler
import java.net.InetSocketAddress; //導入方法依賴的package包/類
@Test
public void testPreConfiguredConnectorAndServerHandler() throws Exception {
String protocol = "pre-configured";
NettyNetworkService service = createService(c ->
c.withConnector(new NetworkConnectorConfig<String>()
.withProtocol(protocol)
.withMessageCodec(createStringCodecFactory())
.withServerHandler((message, from) -> from.send(message.decode() + "-response"))
));
InetSocketAddress bindAddr = service.bind(new NetworkBindCallback() {
// No-op.
}).get().address();
service.start();
InetSocketAddress connectAddr = new InetSocketAddress(InetAddress.getLocalHost(), bindAddr.getPort());
NetworkConnector<String> connector = service.connector(protocol);
NetworkClient<String> client = connector.newClient();
try {
NetworkClientCallbackMock<String> callback = new NetworkClientCallbackMock<>();
client.connect(connectAddr, callback);
client.send("test");
callback.awaitForMessages("test-response");
} finally {
client.disconnect();
}
}
示例13: formatHostAddress
import java.net.InetSocketAddress; //導入方法依賴的package包/類
/**
* Returns a description of a given host address.
*
* @param address an address
* @return a description of the address
*/
public static String formatHostAddress(final InetSocketAddress address) {
if (address != null) {
final String host = address.getAddress().getHostAddress();
final int port = address.getPort();
return formatHostAddress(host, port);
}
return null;
}
示例14: getUri
import java.net.InetSocketAddress; //導入方法依賴的package包/類
public static URI getUri(InetSocketAddress namenode) {
int port = namenode.getPort();
String portString = port == DEFAULT_PORT ? "" : (":"+port);
return URI.create(HdfsConstants.HDFS_URI_SCHEME + "://"
+ namenode.getHostName()+portString);
}
示例15: testClientAfterServiceStop
import java.net.InetSocketAddress; //導入方法依賴的package包/類
@Test
public void testClientAfterServiceStop() throws Exception {
NettyNetworkService serverService = createService(c ->
c.withConnector(new NetworkConnectorConfig<String>()
.withProtocol("test")
.withMessageCodec(createStringCodecFactory())
.withServerHandler((message, from) -> from.send(message + "-response"))
));
NettyNetworkService clientService = createService(c ->
c.withConnector(new NetworkConnectorConfig<String>()
.withProtocol("test")
.withMessageCodec(createStringCodecFactory())
));
InetSocketAddress bindAddr = serverService.bind(new NetworkBindCallback() {
// No-op.
}).get().address();
clientService.bind(new NetworkBindCallback() {
// No-op.
}).get();
InetSocketAddress connectAddr = new InetSocketAddress(InetAddress.getLocalHost(), bindAddr.getPort());
serverService.start();
clientService.start();
NetworkClient<Object> client = clientService.connector("test").newClient();
NetworkClientCallbackMock<Object> callback = new NetworkClientCallbackMock<>();
client.connect(connectAddr, callback).get();
assertSame(NetworkClient.State.CONNECTED, client.state());
clientService.stop();
assertSame(NetworkClient.State.DISCONNECTED, client.state());
try {
client.connect(connectAddr, callback).get(1, TimeUnit.SECONDS);
fail("Error was expected.");
} catch (IllegalStateException e) {
assertEquals("I/O thread pool terminated.", e.getMessage());
}
assertSame(NetworkClient.State.DISCONNECTED, client.state());
callback.assertConnects(1);
callback.assertDisconnects(1);
callback.assertErrors(0);
}