List of usage examples for java.net InetSocketAddress toString
@Override
public String toString()
From source file:com.ngdata.sep.impl.SepConsumer.java
/** * @param subscriptionTimestamp timestamp of when the index subscription became active (or more accurately, not * inactive)/*from w w w. j a v a 2 s.c o m*/ * @param listener listeners that will process the events * @param threadCnt number of worker threads that will handle incoming SEP events * @param hostName hostname to bind to * @param payloadExtractor extracts payloads to include in SepEvents */ public SepConsumer(String subscriptionId, long subscriptionTimestamp, EventListener listener, int threadCnt, String hostName, ZooKeeperItf zk, Configuration hbaseConf, PayloadExtractor payloadExtractor) throws IOException, InterruptedException { Preconditions.checkArgument(threadCnt > 0, "Thread count must be > 0"); this.subscriptionId = SepModelImpl.toInternalSubscriptionName(subscriptionId); this.subscriptionTimestamp = subscriptionTimestamp; this.listener = listener; this.zk = zk; this.hbaseConf = hbaseConf; this.sepMetrics = new SepMetrics(subscriptionId); this.payloadExtractor = payloadExtractor; this.executors = Lists.newArrayListWithCapacity(threadCnt); InetSocketAddress initialIsa = new InetSocketAddress(hostName, 0); if (initialIsa.getAddress() == null) { throw new IllegalArgumentException("Failed resolve of " + initialIsa); } String name = "regionserver/" + initialIsa.toString(); this.rpcServer = new RpcServer(this, name, getServices(), /*HBaseRPCErrorHandler.class, OnlineRegions.class},*/ initialIsa, // BindAddress is IP we got for this server. hbaseConf.getInt("hbase.regionserver.handler.count", 10), hbaseConf.getInt("hbase.regionserver.metahandler.count", 10), hbaseConf, HConstants.QOS_THRESHOLD); this.serverName = new ServerName(hostName, rpcServer.getListenerAddress().getPort(), System.currentTimeMillis()); this.zkWatcher = new ZooKeeperWatcher(hbaseConf, this.serverName.toString(), null); // login the zookeeper client principal (if using security) ZKUtil.loginClient(hbaseConf, "hbase.zookeeper.client.keytab.file", "hbase.zookeeper.client.kerberos.principal", hostName); // login the server principal (if using secure Hadoop) User.login(hbaseConf, "hbase.regionserver.keytab.file", "hbase.regionserver.kerberos.principal", hostName); for (int i = 0; i < threadCnt; i++) { ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100)); executor.setRejectedExecutionHandler(new WaitPolicy()); executors.add(executor); } }
From source file:org.opendaylight.controller.netconf.it.NetconfITTest.java
private TestingNetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception { final TestingNetconfClient netconfClient = new TestingNetconfClient("test " + address.toString(), address, 5000, clientDispatcher);/*from www . j a va2 s . c o m*/ assertEquals(expected, Long.toString(netconfClient.getSessionId())); return netconfClient; }
From source file:org.apache.tajo.rpc.NettyClientBase.java
private ConnectException makeConnectException(InetSocketAddress address, ChannelFuture future) { if (future.cause() instanceof UnresolvedAddressException) { return new ConnectException("Can't resolve host name: " + address.toString()); } else {// www .j a v a2s.c om return new ConnectTimeoutException(future.cause().getMessage()); } }
From source file:com.alibaba.dragoon.common.protocol.transport.socket.SocketConnector.java
public Future<DragoonSession> connect(final SocketAddress address, final MessageHandler messageHandler) { if (address == null) { throw new IllegalArgumentException("address is null"); }//from w ww .ja v a 2s. c o m if (!(address instanceof InetSocketAddress)) { throw new IllegalArgumentException("address must be VmPipeAddress."); } final InetSocketAddress inetSocketAddress = (InetSocketAddress) address; FutureTask<DragoonSession> task = new FutureTask<DragoonSession>(new Callable<DragoonSession>() { public DragoonSession call() throws Exception { connectCount.incrementAndGet(); if (LOG.isInfoEnabled()) { LOG.info("CONNECT TO " + inetSocketAddress); } remoteAddress = inetSocketAddress.toString(); Socket socket = new Socket(inetSocketAddress.getAddress(), inetSocketAddress.getPort()); connectEstablishedCount.incrementAndGet(); if (LOG.isInfoEnabled()) { LOG.info("CONNECTED TO " + inetSocketAddress); } SocketSessionImpl impl = new SocketSessionImpl(socket, receivedBytes, receivedMessages, sentBytes, sentMessages); final long sessionId = generateSessionId(); DragoonSession session = new DragoonSession(sessionId, new DragoonSessionConfig(messageHandler), impl); impl.init(session); return session; } }); connectorExecutor.submit(task); return task; }
From source file:org.openhab.binding.lifx.internal.LifxLightDiscovery.java
private void handlePacket(Packet packet, InetSocketAddress address) { logger.trace("Discovery : Packet type '{}' received from '{}' for '{}' with sequence '{}' and source '{}'", new Object[] { packet.getClass().getSimpleName(), address.toString(), packet.getTarget().getHex(), packet.getSequence(), Long.toString(packet.getSource(), 16) }); if (packet.getSource() == sourceId || packet.getSource() == 0) { MACAddress macAddress = packet.getTarget(); DiscoveredLight light = discoveredLights.get(macAddress); if (packet instanceof StateServiceResponse) { int port = (int) ((StateServiceResponse) packet).getPort(); if (port != 0) { try { InetSocketAddress socketAddress = new InetSocketAddress(address.getAddress(), port); if (light == null || (!socketAddress.equals(light.socketAddress))) { if (light != null) { light.cancelUnicastKey(); }/*from ww w . j ava 2s . c om*/ Selector lightSelector = selector; if (lightSelector != null) { String logId = getLogId(macAddress, socketAddress); light = new DiscoveredLight(lightSelector, macAddress, socketAddress, logId, openUnicastChannel(lightSelector, logId, socketAddress)); discoveredLights.put(macAddress, light); } } } catch (Exception e) { logger.warn("{} while connecting to IP address: {}", e.getClass().getSimpleName(), e.getMessage()); return; } } } else if (light != null) { if (packet instanceof StateLabelResponse) { light.label = ((StateLabelResponse) packet).getLabel().trim(); } else if (packet instanceof StateVersionResponse) { try { light.product = Product .getProductFromProductID(((StateVersionResponse) packet).getProduct()); light.productVersion = ((StateVersionResponse) packet).getVersion(); } catch (IllegalArgumentException e) { logger.debug("Discovered an unsupported light ({}): {}", light.macAddress.getAsLabel(), e.getMessage()); light.supportedProduct = false; } } } if (light != null && light.isDataComplete()) { try { thingDiscovered(createDiscoveryResult(light)); } catch (IllegalArgumentException e) { logger.trace("{} while creating discovery result of light ({})", e.getClass().getSimpleName(), light.logId, e); } } } }
From source file:IntergrationTest.OCSPIntegrationTest.java
private byte[] httpGetBin(URI uri, boolean bActiveCheckUnknownHost) throws Exception { InputStream is = null;//from w w w . j a va 2 s. c om InputStream is_temp = null; try { if (uri == null) return null; URL url = uri.toURL(); if (bActiveCheckUnknownHost) { url.getProtocol(); String host = url.getHost(); int port = url.getPort(); if (port == -1) port = url.getDefaultPort(); InetSocketAddress isa = new InetSocketAddress(host, port); if (isa.isUnresolved()) { //fix JNLP popup error issue throw new UnknownHostException("Host Unknown:" + isa.toString()); } } HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setDoInput(true); uc.setAllowUserInteraction(false); uc.setInstanceFollowRedirects(true); setTimeout(uc); String contentEncoding = uc.getContentEncoding(); int len = uc.getContentLength(); // is = uc.getInputStream(); if (contentEncoding != null && contentEncoding.toLowerCase().indexOf("gzip") != -1) { is_temp = uc.getInputStream(); is = new GZIPInputStream(is_temp); } else if (contentEncoding != null && contentEncoding.toLowerCase().indexOf("deflate") != -1) { is_temp = uc.getInputStream(); is = new InflaterInputStream(is_temp); } else { is = uc.getInputStream(); } if (len != -1) { int ch, i = 0; byte[] res = new byte[len]; while ((ch = is.read()) != -1) { res[i++] = (byte) (ch & 0xff); } return res; } else { ArrayList<byte[]> buffer = new ArrayList<>(); int buf_len = 1024; byte[] res = new byte[buf_len]; int ch, i = 0; while ((ch = is.read()) != -1) { res[i++] = (byte) (ch & 0xff); if (i == buf_len) { //rotate buffer.add(res); i = 0; res = new byte[buf_len]; } } int total_len = buffer.size() * buf_len + i; byte[] buf = new byte[total_len]; for (int j = 0; j < buffer.size(); j++) { System.arraycopy(buffer.get(j), 0, buf, j * buf_len, buf_len); } if (i > 0) { System.arraycopy(res, 0, buf, buffer.size() * buf_len, i); } return buf; } } catch (Exception e) { e.printStackTrace(); return null; } finally { closeInputStream(is_temp); closeInputStream(is); } }
From source file:org.apache.hadoop.ipc.TestIPC.java
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 {//from w ww . j a va 2 s. co m client.call(new LongWritable(RANDOM.nextLong()), address, null, null, 0, conf); 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)); } }
From source file:com.dotmarketing.business.MemcachedCacheAdministratorImpl.java
public void removeServer(String inetAddress) { synchronized (this) { try {/*from w w w. jav a 2s .co m*/ Logger.info(this.getClass(), "***\t Memcached Config removing server:" + inetAddress); boolean reset = false; List<InetSocketAddress> newServers = new ArrayList<InetSocketAddress>(); List<Integer> newWeights = new ArrayList<Integer>(); InetSocketAddress addr = AddrUtil.getOneAddress(inetAddress); for (int i = 0; i < _servers.size(); i++) { InetSocketAddress ip = _servers.get(i); if (ip.equals(addr) || ip.toString().endsWith(addr.toString())) { reset = true; } else { newServers.add(ip); newWeights.add(_weights.get(i)); } } if (reset) { MemcachedClient x = getClient(); this._servers = newServers; this._weights = newWeights; this._client = null; x.shutdown(); x = null; } } catch (Exception e) { Logger.error(this.getClass(), "No memcache client can be built:" + e.getMessage(), e); } } }
From source file:com.dotmarketing.business.MemcachedCacheAdministratorImpl.java
public void addServer(String inetAddress, int weight) { synchronized (this) { Logger.info(this.getClass(), "***\t Memcached Config adding server:" + inetAddress + " " + weight); boolean reset = true; try {/* w w w. j a va2 s . c o m*/ List<InetSocketAddress> newServers = new ArrayList<InetSocketAddress>(); List<Integer> newWeights = new ArrayList<Integer>(); InetSocketAddress addr = AddrUtil.getOneAddress(inetAddress); newServers.add(addr); newWeights.add(weight); for (int i = 0; i < _servers.size(); i++) { InetSocketAddress ip = _servers.get(i); if (ip.equals(addr) || ip.toString().endsWith(addr.toString())) { reset = false; } else { newWeights.add(_weights.get(i)); newServers.add(ip); } } if (reset) { MemcachedClient x = getClient(); this._servers = newServers; this._weights = newWeights; this._client = null; x.shutdown(); x = null; } } catch (Exception e) { Logger.error(this.getClass(), "No memcache client can be built:" + e.getMessage(), e); } } }
From source file:org.apache.synapse.transport.passthru.PassThroughHttpListener.java
/** * Start specified end points for given set of bind addresses * * @param bindAddresses InetSocketAddress list to be started * @throws AxisFault/* w w w .jav a 2 s . co m*/ */ private void startSpecificEndpoints(Set<InetSocketAddress> bindAddresses) throws AxisFault { if (PassThroughConfiguration.getInstance().getMaxActiveConnections() != -1) { addMaxActiveConnectionCountController(PassThroughConfiguration.getInstance().getMaxActiveConnections()); } List<InetSocketAddress> addressList = new ArrayList<InetSocketAddress>(bindAddresses); Collections.sort(addressList, new Comparator<InetSocketAddress>() { public int compare(InetSocketAddress a1, InetSocketAddress a2) { String s1 = a1.toString(); String s2 = a2.toString(); return s1.compareTo(s2); } }); for (InetSocketAddress address : addressList) { passThroughListeningIOReactorManager.startPTTEndpoint(address, ioReactor, namePrefix); } }