Java Code Examples for java.net.InetSocketAddress#toString()
The following examples show how to use
java.net.InetSocketAddress#toString() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: swim File: IpStation.java License: Apache License 2.0 | 6 votes |
@Override default IpServiceRef bindTcp(InetSocketAddress localAddress, IpService service, IpSettings ipSettings) { try { final Station station = station(); final ServerSocketChannel serverChannel = ServerSocketChannel.open(); serverChannel.configureBlocking(false); serverChannel.socket().setReuseAddress(true); serverChannel.socket().bind(localAddress, station().transportSettings.backlog); final TcpService context = new TcpService(station(), localAddress, serverChannel, service, ipSettings); service.setIpServiceContext(context); station().transport(context, FlowControl.ACCEPT); context.didBind(); return context; } catch (IOException | UnresolvedAddressException error) { throw new StationException(localAddress.toString(), error); } }
Example 2
Source Project: swim File: IpStation.java License: Apache License 2.0 | 6 votes |
@Override default IpServiceRef bindTls(InetSocketAddress localAddress, IpService service, IpSettings ipSettings) { try { final Station station = station(); final ServerSocketChannel serverChannel = ServerSocketChannel.open(); serverChannel.configureBlocking(false); serverChannel.socket().setReuseAddress(true); serverChannel.socket().bind(localAddress, station.transportSettings.backlog); final TlsService context = new TlsService(station, localAddress, serverChannel, service, ipSettings); service.setIpServiceContext(context); station.transport(context, FlowControl.ACCEPT); context.didBind(); return context; } catch (IOException | UnresolvedAddressException error) { throw new StationException(localAddress.toString(), error); } }
Example 3
Source Project: swim File: IpStation.java License: Apache License 2.0 | 6 votes |
@Override default IpSocketRef connectTcp(InetSocketAddress remoteAddress, IpSocket socket, IpSettings ipSettings) { try { final Station station = station(); final SocketChannel channel = SocketChannel.open(); channel.configureBlocking(false); ipSettings.configure(channel.socket()); final boolean connected = channel.connect(remoteAddress); final InetSocketAddress localAddress = (InetSocketAddress) channel.socket().getLocalSocketAddress(); final TcpSocket context = new TcpSocket(localAddress, remoteAddress, channel, ipSettings, true); context.become(socket); if (connected) { station.transport(context, FlowControl.WAIT); context.didConnect(); } else { context.willConnect(); station.transport(context, FlowControl.CONNECT); } return context; } catch (IOException | UnresolvedAddressException error) { throw new StationException(remoteAddress.toString(), error); } }
Example 4
Source Project: gemfirexd-oss File: GfxdTSSLServerSocket.java License: Apache License 2.0 | 6 votes |
/** * Creates a server socket from underlying socket object */ public GfxdTSSLServerSocket(ServerSocket serverSocket, InetSocketAddress bindAddress, SocketParameters params) throws TTransportException { this.socketParams = params; try { this.serverSocket = serverSocket; // Prevent 2MSL delay problem on server restarts serverSocket.setReuseAddress(true); // Bind to listening port if (!serverSocket.isBound()) { // backlog hardcoded to 100 as in TSSLTransportFactory serverSocket.bind(bindAddress, 100); } } catch (IOException ioe) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), ioe); } }
Example 5
Source Project: hadoop File: IPFailoverProxyProvider.java License: Apache License 2.0 | 6 votes |
@Override public synchronized ProxyInfo<T> getProxy() { // Create a non-ha proxy if not already created. if (nnProxyInfo == null) { try { // Create a proxy that is not wrapped in RetryProxy InetSocketAddress nnAddr = NameNode.getAddress(nameNodeUri); nnProxyInfo = new ProxyInfo<T>(NameNodeProxies.createNonHAProxy( conf, nnAddr, xface, UserGroupInformation.getCurrentUser(), false).getProxy(), nnAddr.toString()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } return nnProxyInfo; }
Example 6
Source Project: gemfirexd-oss File: GfxdTSSLServerSocketFactory.java License: Apache License 2.0 | 6 votes |
private static GfxdTSSLServerSocket createServer( SSLServerSocketFactory factory, InetSocketAddress bindAddress, SocketParameters params) throws TTransportException { try { SSLServerSocket serverSocket = (SSLServerSocket)factory .createServerSocket(bindAddress.getPort(), 100, bindAddress.getAddress()); if (params != null) { if (params.getSSLEnabledProtocols() != null) { serverSocket.setEnabledProtocols(params.getSSLEnabledProtocols()); } if (params.getSSLCipherSuites() != null) { serverSocket.setEnabledCipherSuites(params.getSSLCipherSuites()); } serverSocket.setNeedClientAuth(params.getSSLClientAuth()); } return new GfxdTSSLServerSocket(serverSocket, bindAddress, params); } catch (Exception e) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), e); } }
Example 7
Source Project: hbase File: FailedServers.java License: Apache License 2.0 | 6 votes |
/** * Check if the server should be considered as bad. Clean the old entries of the list. * * @return true if the server is in the failed servers list */ public synchronized boolean isFailedServer(final InetSocketAddress address) { if (failedServers.isEmpty()) { return false; } final long now = EnvironmentEdgeManager.currentTime(); if (now > this.latestExpiry) { failedServers.clear(); return false; } String key = address.toString(); Long expiry = this.failedServers.get(key); if (expiry == null) { return false; } if (expiry >= now) { return true; } else { this.failedServers.remove(key); } return false; }
Example 8
Source Project: gemfirexd-oss File: GfxdTServerSocket.java License: Apache License 2.0 | 6 votes |
/** * Creates a port listening server socket */ public GfxdTServerSocket(InetSocketAddress bindAddress, boolean blocking, boolean clientBlocking, SocketParameters params) throws TTransportException { this.clientBlocking = clientBlocking; this.socketParams = params; try { // Make server socket this.serverSockChannel = ServerSocketChannel.open(); this.serverSockChannel.configureBlocking(blocking); ServerSocket socket = this.serverSockChannel.socket(); // Prevent 2MSL delay problem on server restarts socket.setReuseAddress(true); // Bind to listening port socket.bind(bindAddress); } catch (IOException ioe) { throw new TTransportException(TTransportException.NOT_OPEN, "Could not bind to host:port " + bindAddress.toString(), ioe); } }
Example 9
Source Project: RDFS File: TestIPC.java License: Apache License 2.0 | 6 votes |
public void testStandAloneClient() throws Exception { testParallel(10, false, 2, 4, 2, 4, 100); Client client = new Client(LongWritable.class, conf); InetSocketAddress address = new InetSocketAddress("127.0.0.1", 10); try { client.call(new LongWritable(RANDOM.nextLong()), address, null, null, 0); fail("Expected an exception to have been thrown"); } catch (IOException e) { String message = e.getMessage(); String addressText = address.toString(); assertTrue("Did not find "+addressText+" in "+message, message.contains(addressText)); Throwable cause=e.getCause(); assertNotNull("No nested exception in "+e,cause); String causeText=cause.getMessage(); assertTrue("Did not find " + causeText + " in " + message, message.contains(causeText)); } }
Example 10
Source Project: openjdk-jdk9 File: HTTPTestServer.java License: GNU General Public License v2.0 | 5 votes |
static <T extends HttpServer> T create(HttpProtocolType protocol) throws IOException { final int max = addresses.size() + MAX; final List<HttpServer> toClose = new ArrayList<>(); try { for (int i = 1; i <= max; i++) { HttpServer server = newHttpServer(protocol); server.bind(new InetSocketAddress("127.0.0.1", 0), 0); InetSocketAddress address = server.getAddress(); String key = address.toString(); if (addresses.addIfAbsent(key)) { System.out.println("Server bound to: " + key + " after " + i + " attempt(s)"); return (T) server; } System.out.println("warning: address " + key + " already used. Retrying bind."); // keep the port bound until we get a port that we haven't // used already toClose.add(server); } } finally { // if we had to retry, then close the servers we're not // going to use. for (HttpServer s : toClose) { try { s.stop(1); } catch (Exception x) { /* ignore */ } } } throw new IOException("Couldn't bind servers after " + max + " attempts: " + "addresses used before: " + addresses); }
Example 11
Source Project: incubator-retired-blur File: TServerSocket.java License: Apache License 2.0 | 5 votes |
public TServerSocket(InetSocketAddress bindAddr, int clientTimeout) throws TTransportException { clientTimeout_ = clientTimeout; try { // Make server socket serverSocket_ = new ServerSocket(); // Prevent 2MSL delay problem on server restarts serverSocket_.setReuseAddress(true); // Bind to listening port serverSocket_.bind(bindAddr); } catch (IOException ioe) { serverSocket_ = null; throw new TTransportException("Could not create ServerSocket on address " + bindAddr.toString() + "."); } }
Example 12
Source Project: tajo File: NettyClientBase.java License: Apache License 2.0 | 5 votes |
private ConnectException makeConnectException(InetSocketAddress address, ChannelFuture future) { if (future.cause() instanceof UnresolvedAddressException) { return new ConnectException("Can't resolve host name: " + address.toString()); } else { return new ConnectTimeoutException(future.cause().getMessage()); } }
Example 13
Source Project: swim File: IpStation.java License: Apache License 2.0 | 4 votes |
@Override default IpSocketRef connectTls(InetSocketAddress remoteAddress, IpSocket socket, IpSettings ipSettings) { try { final Station station = station(); final SocketChannel channel = SocketChannel.open(); channel.configureBlocking(false); ipSettings.configure(channel.socket()); final TlsSettings tlsSettings = ipSettings.tlsSettings(); final SSLEngine sslEngine = tlsSettings.sslContext().createSSLEngine(); sslEngine.setUseClientMode(true); final SNIHostName serverName = new SNIHostName(remoteAddress.getHostName()); final List<SNIServerName> serverNames = new ArrayList<>(1); serverNames.add(serverName); final SSLParameters sslParameters = sslEngine.getSSLParameters(); sslParameters.setServerNames(serverNames); sslEngine.setSSLParameters(sslParameters); switch (tlsSettings.clientAuth()) { case NEED: sslEngine.setNeedClientAuth(true); break; case WANT: sslEngine.setWantClientAuth(true); break; case NONE: sslEngine.setWantClientAuth(false); break; default: } final Collection<String> cipherSuites = tlsSettings.cipherSuites(); if (cipherSuites != null) { sslEngine.setEnabledCipherSuites(cipherSuites.toArray(new String[cipherSuites.size()])); } final Collection<String> protocols = tlsSettings.protocols(); if (protocols != null) { sslEngine.setEnabledProtocols(protocols.toArray(new String[protocols.size()])); } final boolean connected = channel.connect(remoteAddress); final InetSocketAddress localAddress = (InetSocketAddress) channel.socket().getLocalSocketAddress(); final TlsSocket context = new TlsSocket(localAddress, remoteAddress, channel, sslEngine, ipSettings, true); context.become(socket); if (connected) { station.transport(context, FlowControl.WAIT); context.didConnect(); } else { context.willConnect(); station.transport(context, FlowControl.CONNECT); } return context; } catch (IOException | UnresolvedAddressException error) { throw new StationException(remoteAddress.toString(), error); } }
Example 14
Source Project: monsoon File: InetAddressOptionHandler.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected String print(InetSocketAddress v) { return v.toString(); }
Example 15
Source Project: SparkRDMA File: RdmaNode.java License: Apache License 2.0 | 4 votes |
public RdmaChannel getRdmaChannel(InetSocketAddress remoteAddr, boolean mustRetry, RdmaChannel.RdmaChannelType rdmaChannelType) throws IOException, InterruptedException { final long startTime = System.nanoTime(); final int maxConnectionAttempts = conf.maxConnectionAttempts(); final long connectionTimeout = maxConnectionAttempts * conf.rdmaCmEventTimeout(); long elapsedTime = 0; int connectionAttempts = 0; RdmaChannel rdmaChannel; do { rdmaChannel = activeRdmaChannelMap.get(remoteAddr); if (rdmaChannel == null) { RdmaCompletionListener listener = null; if (rdmaChannelType == RdmaChannel.RdmaChannelType.RPC) { // Executor <-> Driver rdma channels need listener on both sides. listener = receiveListener; } rdmaChannel = new RdmaChannel(rdmaChannelType, conf, rdmaBufferManager, listener, getNextCpuVector()); RdmaChannel actualRdmaChannel = activeRdmaChannelMap.putIfAbsent(remoteAddr, rdmaChannel); if (actualRdmaChannel != null) { rdmaChannel = actualRdmaChannel; } else { try { rdmaChannel.connect(remoteAddr); logger.info("Established connection to " + remoteAddr + " in " + (System.nanoTime() - startTime) / 1000000 + " ms"); } catch (IOException e) { ++connectionAttempts; activeRdmaChannelMap.remove(remoteAddr, rdmaChannel); rdmaChannel.stop(); if (mustRetry) { if (connectionAttempts == maxConnectionAttempts) { logger.error("Failed to connect to " + remoteAddr + " after " + maxConnectionAttempts + " attempts, aborting"); throw e; } else { logger.error("Failed to connect to " + remoteAddr + ", attempt " + connectionAttempts + " of " + maxConnectionAttempts + " with exception: " + e); continue; } } else { logger.error("Failed to connect to " + remoteAddr + " with exception: " + e); } } } } if (rdmaChannel.isError()) { activeRdmaChannelMap.remove(remoteAddr, rdmaChannel); rdmaChannel.stop(); continue; } if (!rdmaChannel.isConnected()) { rdmaChannel.waitForActiveConnection(); elapsedTime = (System.nanoTime() - startTime) / 1000000; } if (rdmaChannel.isConnected()) { break; } } while (mustRetry && (connectionTimeout - elapsedTime) > 0); if (mustRetry && !rdmaChannel.isConnected()) { throw new IOException("Timeout in establishing a connection to " + remoteAddr.toString()); } return rdmaChannel; }
Example 16
Source Project: monsoon File: ManyInetAddressOptionHandler.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected String print(InetSocketAddress v) { return v.toString(); }
Example 17
Source Project: hadoop File: RemoteBlockReader2.java License: Apache License 2.0 | 2 votes |
/** * File name to print when accessing a block directly (from servlets) * @param s Address of the block location * @param poolId Block pool ID of the block * @param blockId Block ID of the block * @return string that has a file name for debug purposes */ public static String getFileName(final InetSocketAddress s, final String poolId, final long blockId) { return s.toString() + ":" + poolId + ":" + blockId; }
Example 18
Source Project: hadoop File: BlockReaderFactory.java License: Apache License 2.0 | 2 votes |
/** * File name to print when accessing a block directly (from servlets) * @param s Address of the block location * @param poolId Block pool ID of the block * @param blockId Block ID of the block * @return string that has a file name for debug purposes */ public static String getFileName(final InetSocketAddress s, final String poolId, final long blockId) { return s.toString() + ":" + poolId + ":" + blockId; }
Example 19
Source Project: JRakNet File: ServerOfflineException.java License: MIT License | 2 votes |
/** * Constructs a <code>ServerOfflineException</code>. * * @param client * the client that attempted to the offline server. * @param address * the address of the offline server. */ public ServerOfflineException(RakNetClient client, InetSocketAddress address) { super(client, "Server at address " + address.toString() + " is offline"); this.address = address; }
Example 20
Source Project: big-c File: BlockReaderFactory.java License: Apache License 2.0 | 2 votes |
/** * File name to print when accessing a block directly (from servlets) * @param s Address of the block location * @param poolId Block pool ID of the block * @param blockId Block ID of the block * @return string that has a file name for debug purposes */ public static String getFileName(final InetSocketAddress s, final String poolId, final long blockId) { return s.toString() + ":" + poolId + ":" + blockId; }