public String getClientAddressString() { if (clientAddress == null) return null; return clientAddress.getHost() + ":" + clientAddress.getPort(); }
/** * Creates a Thrift TTransport to the given address with the given timeout. All created resources * are closed if an exception is thrown. * * @param addr * The address to connect the client to * @param timeoutMillis * The timeout in milliseconds for the connection * @return A TTransport connected to the given <code>addr</code> * @throws IOException * If the transport fails to be created/connected */ public static TTransport create(HostAndPort addr, long timeoutMillis) throws IOException { return INSTANCE.createInternal(new InetSocketAddress(addr.getHost(), addr.getPort()), timeoutMillis); }
public static MasterClientService.Client getConnection(ClientContext context) { checkArgument(context != null, "context is null"); List<String> locations = context.getMasterLocations(); if (locations.size() == 0) { log.debug("No masters..."); return null; } HostAndPort master = HostAndPort.fromString(locations.get(0)); if (master.getPort() == 0) return null; try { // Master requests can take a long time: don't ever time out return ThriftUtil.getClientNoTimeout(new MasterClientService.Client.Factory(), master, context); } catch (TTransportException tte) { Throwable cause = tte.getCause(); if (cause != null && cause instanceof UnknownHostException) { // do not expect to recover from this throw new RuntimeException(tte); } log.debug("Failed to connect to master=" + master + ", will retry... ", tte); return null; } }
/** * Creates a TThreadPoolServer for normal unsecure operation. Useful for comparing performance * against SSL or SASL transports. * * @param address * Address to bind to * @param processor * TProcessor for the server * @param maxMessageSize * Maximum size of a Thrift message allowed * @return A configured TThreadPoolServer and its bound address information */ public static ServerAddress createBlockingServer(HostAndPort address, TProcessor processor, TProtocolFactory protocolFactory, long maxMessageSize, String serverName, int numThreads, int numSimpleTimerThreads, long timeBetweenThreadChecks) throws TTransportException { InetSocketAddress isa = new InetSocketAddress(address.getHost(), address.getPort()); // Must use an ISA, providing only a port would ignore the hostname given TServerSocket transport = new TServerSocket(isa); ThreadPoolExecutor pool = createSelfResizingThreadPool(serverName, numThreads, numSimpleTimerThreads, timeBetweenThreadChecks); TThreadPoolServer server = createTThreadPoolServer(transport, processor, ThriftUtil.transportFactory(maxMessageSize), protocolFactory, pool); if (address.getPort() == 0) { address = HostAndPort.fromParts(address.getHost(), transport.getServerSocket().getLocalPort()); log.info("Blocking Server bound on {}", address); } return new ServerAddress(server, address); }
TServerSocket transport; try { transport = getSslServerSocket(address.getPort(), (int) socketTimeout, InetAddress.getByName(address.getHost()), sslParams); } catch (UnknownHostException e) { if (address.getPort() == 0) { address = HostAndPort.fromParts(address.getHost(), transport.getServerSocket().getLocalPort());
/** * Create a NonBlockingServer with a custom thread pool that can dynamically resize itself. */ public static ServerAddress createNonBlockingServer(HostAndPort address, TProcessor processor, TProtocolFactory protocolFactory, final String serverName, final int numThreads, final int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize) throws TTransportException { final TNonblockingServerSocket transport = new TNonblockingServerSocket( new InetSocketAddress(address.getHost(), address.getPort())); final CustomNonBlockingServer.Args options = new CustomNonBlockingServer.Args(transport); options.protocolFactory(protocolFactory); options.transportFactory(ThriftUtil.transportFactory(maxMessageSize)); options.maxReadBufferBytes = maxMessageSize; options.stopTimeoutVal(5); // Create our own very special thread pool. ThreadPoolExecutor pool = createSelfResizingThreadPool(serverName, numThreads, numSTThreads, timeBetweenThreadChecks); options.executorService(pool); options.processorFactory(new TProcessorFactory(processor)); if (address.getPort() == 0) { address = HostAndPort.fromParts(address.getHost(), transport.getPort()); } return new ServerAddress(new CustomNonBlockingServer(options), address); }
transport = TSSLTransportFactory.getClientSocket(address.getHost(), address.getPort(), timeout); } else { transport = createClient(wrappingSslSockFactory, address.getHost(), address.getPort(), timeout); log.trace("Creating SASL connection to {}:{}", address.getHost(), address.getPort()); log.trace("Opening normal transport"); if (timeout == 0) { transport = new TSocket(address.getHost(), address.getPort()); transport.open(); } else {
.fromParts(InetAddress.getLocalHost().getHostName(), serverAddress.address.getPort())); } catch (UnknownHostException e) { throw new TTransportException(e);
public String getClientAddressString() { if (clientAddress == null) return null; return clientAddress.getHost() + ":" + clientAddress.getPort(); }
public String getReplicationAddressSTring() { if (null == replicationAddress) { return null; } return replicationAddress.getHost() + ":" + replicationAddress.getPort(); }
public static TTransport create(HostAndPort addr, long timeoutMillis) throws IOException { return create(new InetSocketAddress(addr.getHost(), addr.getPort()), timeoutMillis); }
public static MasterClientService.Client getConnection(ClientContext context) { checkArgument(context != null, "context is null"); List<String> locations = context.getInstance().getMasterLocations(); if (locations.size() == 0) { log.debug("No masters..."); return null; } HostAndPort master = HostAndPort.fromString(locations.get(0)); if (0 == master.getPort()) return null; try { // Master requests can take a long time: don't ever time out MasterClientService.Client client = ThriftUtil .getClientNoTimeout(new MasterClientService.Client.Factory(), master, context); return client; } catch (TTransportException tte) { Throwable cause = tte.getCause(); if (null != cause && cause instanceof UnknownHostException) { // do not expect to recover from this throw new RuntimeException(tte); } log.debug("Failed to connect to master=" + master + ", will retry... ", tte); return null; } }
final HostAndPort hostAndPort = HostAndPort.fromString(zooKeepers); for (int i = 0; i < 5; i++) { Socket socket = new Socket(hostAndPort.getHost(), hostAndPort.getPort()); try { socket.getOutputStream().write("wchs\n".getBytes(), 0, 5);
/** * Creates a TTheadPoolServer for normal unsecure operation. Useful for comparing performance * against SSL or SASL transports. * * @param address * Address to bind to * @param processor * TProcessor for the server * @param maxMessageSize * Maximum size of a Thrift message allowed * @return A configured TThreadPoolServer and its bound address information */ public static ServerAddress createBlockingServer(HostAndPort address, TProcessor processor, TProtocolFactory protocolFactory, long maxMessageSize, String serverName, int numThreads, int numSimpleTimerThreads, long timeBetweenThreadChecks) throws TTransportException { TServerSocket transport = new TServerSocket(address.getPort()); ThreadPoolExecutor pool = createSelfResizingThreadPool(serverName, numThreads, numSimpleTimerThreads, timeBetweenThreadChecks); TThreadPoolServer server = createTThreadPoolServer(transport, processor, ThriftUtil.transportFactory(maxMessageSize), protocolFactory, pool); if (address.getPort() == 0) { address = HostAndPort.fromParts(address.getHost(), transport.getServerSocket().getLocalPort()); log.info("Blocking Server bound on {}", address); } return new ServerAddress(server, address); }
TServerSocket transport; try { transport = getSslServerSocket(address.getPort(), (int) socketTimeout, InetAddress.getByName(address.getHost()), sslParams); } catch (UnknownHostException e) { if (address.getPort() == 0) { address = HostAndPort.fromParts(address.getHost(), transport.getServerSocket().getLocalPort());
/** * Create a NonBlockingServer with a custom thread pool that can dynamically resize itself. */ public static ServerAddress createNonBlockingServer(HostAndPort address, TProcessor processor, TProtocolFactory protocolFactory, final String serverName, String threadName, final int numThreads, final int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize) throws TTransportException { final TNonblockingServerSocket transport = new TNonblockingServerSocket( new InetSocketAddress(address.getHost(), address.getPort())); final CustomNonBlockingServer.Args options = new CustomNonBlockingServer.Args(transport); options.protocolFactory(protocolFactory); options.transportFactory(ThriftUtil.transportFactory(maxMessageSize)); options.maxReadBufferBytes = maxMessageSize; options.stopTimeoutVal(5); // Create our own very special thread pool. ThreadPoolExecutor pool = createSelfResizingThreadPool(serverName, numThreads, numSTThreads, timeBetweenThreadChecks); options.executorService(pool); options.processorFactory(new TProcessorFactory(processor)); if (address.getPort() == 0) { address = HostAndPort.fromParts(address.getHost(), transport.getPort()); } return new ServerAddress(new CustomNonBlockingServer(options), address); }
private void doDetailTable(HttpServletRequest req, StringBuilder sb, HostAndPort address, int numTablets, TabletStats total, TabletStats historical) { Table detailTable = new Table("tServerDetail", "Details"); detailTable.setSubCaption(address.getHost() + ":" + address.getPort()); detailTable.addSortableColumn("Hosted Tablets", new NumberType<Integer>(), null); detailTable.addSortableColumn("Entries", new NumberType<Long>(), null); detailTable.addSortableColumn("Minor Compacting", new NumberType<Integer>(), null); detailTable.addSortableColumn("Major Compacting", new NumberType<Integer>(), null); detailTable.addSortableColumn("Splitting", new NumberType<Integer>(), null); detailTable.addRow(numTablets, total.numEntries, total.minors.status, total.majors.status, historical.splits.status); detailTable.generate(req, sb); }