List of usage examples for java.net InetSocketAddress toString
@Override
public String toString()
From source file:com.pinterest.rocksplicator.controller.tasks.HealthCheckTask.java
@Override public void process(Context ctx) throws Exception { final String clusterName = ctx.getCluster(); try {//from www . j a va 2s . c o m ClusterBean clusterBean = ZKUtil.getClusterConfig(zkClient, clusterName); if (clusterBean == null) { ctx.getTaskQueue().failTask(ctx.getId(), "Failed to read cluster config from zookeeper."); return; } Set<InetSocketAddress> hosts = new HashSet<>(); for (SegmentBean segmentBean : clusterBean.getSegments()) { for (HostBean hostBean : segmentBean.getHosts()) { hosts.add(new InetSocketAddress(hostBean.getIp(), hostBean.getPort())); } // check segment replica checkSegment(segmentBean, getParameter().getNumReplicas()); } // ping all hosts Set<String> badHosts = new HashSet<>(); for (InetSocketAddress hostAddr : hosts) { try { clientFactory.getClient(hostAddr).ping(); } catch (TException | ExecutionException ex) { // record bad host badHosts.add(hostAddr.toString()); } } if (!badHosts.isEmpty()) { ctx.getTaskQueue().failTask(ctx.getId(), String.format("Unable to ping hosts: %s", badHosts)); return; } LOG.info("All hosts are good"); ctx.getTaskQueue().finishTask(ctx.getId(), String.format("Cluster %s is healthy", clusterName)); } catch (Exception ex) { ctx.getTaskQueue().failTask(ctx.getId(), String.format("Cluster %s is unhealthy, reason = %s", clusterName, ex.getMessage())); } }
From source file:co.rsk.net.discovery.PeerExplorer.java
public Set<String> startConversationWithNewNodes() { Set<String> sentAddresses = new HashSet<>(); for (InetSocketAddress nodeAddress : this.bootNodes) { sendPing(nodeAddress, 1);// w w w .j a va 2 s .com sentAddresses.add(nodeAddress.toString()); } this.bootNodes.removeAll(pendingPingRequests.values().stream().map(PeerDiscoveryRequest::getAddress) .collect(Collectors.toList())); return sentAddresses; }
From source file:org.apache.hama.bsp.message.HamaAsyncMessageManagerImpl.java
@Override public void transfer(InetSocketAddress addr, M msg) throws IOException { HamaMessageManager<M> bspPeerConnection = this.getBSPPeerConnection(addr); if (bspPeerConnection == null) { throw new IllegalArgumentException("Can not find " + addr.toString() + " to transfer messages to!"); } else {/* www . ja v a 2s . c om*/ bspPeerConnection.put(msg); } }
From source file:org.apache.hama.bsp.message.HamaMessageManagerImpl.java
@Override public final void transfer(InetSocketAddress addr, BSPMessageBundle<M> bundle) throws IOException { HamaMessageManager<M> bspPeerConnection = this.getBSPPeerConnection(addr); if (bspPeerConnection == null) { throw new IllegalArgumentException("Can not find " + addr.toString() + " to transfer messages to!"); } else {//from w ww .java 2s. co m if (conf.getBoolean(Constants.MESSENGER_RUNTIME_COMPRESSION, false)) { ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); DataOutputStream bufferDos = new DataOutputStream(byteBuffer); bundle.write(bufferDos); byte[] compressed = compressor.compress(byteBuffer.toByteArray()); peer.incrementCounter(BSPPeerImpl.PeerCounter.TOTAL_COMPRESSED_BYTES_TRANSFERED, compressed.length); peer.incrementCounter(BSPPeerImpl.PeerCounter.TOTAL_DECOMPRESSED_BYTES, byteBuffer.size()); bspPeerConnection.put(compressed); } else { //peer.incrementCounter(BSPPeerImpl.PeerCounter.TOTAL_MESSAGE_BYTES_TRANSFERED, bundle.getLength()); bspPeerConnection.put(bundle); } } }
From source file:org.apache.hama.bsp.message.HamaAsyncMessageManagerImpl.java
@Override public final void transfer(InetSocketAddress addr, BSPMessageBundle<M> bundle) throws IOException { HamaMessageManager<M> bspPeerConnection = this.getBSPPeerConnection(addr); if (bspPeerConnection == null) { throw new IllegalArgumentException("Can not find " + addr.toString() + " to transfer messages to!"); } else {/*from ww w . j a v a 2 s.c om*/ if (conf.getBoolean(Constants.MESSENGER_RUNTIME_COMPRESSION, false)) { ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); DataOutputStream bufferDos = new DataOutputStream(byteBuffer); bundle.write(bufferDos); byte[] compressed = compressor.compress(byteBuffer.toByteArray()); peer.incrementCounter(BSPPeerImpl.PeerCounter.TOTAL_MESSAGE_BYTES_TRANSFERED, compressed.length); bspPeerConnection.put(compressed); } else { // peer.incrementCounter(BSPPeerImpl.PeerCounter.TOTAL_MESSAGE_BYTES_TRANSFERED, // bundle.getLength()); bspPeerConnection.put(bundle); } } }
From source file:org.apache.niolex.config.service.impl.ReplicaServiceImpl.java
public void tryConnectToOtherServer(InetSocketAddress addr) { /**//from w ww . ja va2s . c om * First of all, let's remove localhost from the list. */ if (IP_SET.contains(addr.getAddress()) && localPort == addr.getPort()) { return; } final PacketClient client = new PacketClient(); otherServers.put(addr.toString(), client); LOG.info("Want to connect to {}.", addr); client.setConnectTimeout(60000); client.setServerAddress(addr); ReConnectHandler handler = new ReConnectHandler(); handler.addHandler(CodeMap.GROUP_DIF, diffHandler); handler.addHandler(CodeMap.GROUP_ADD, addHandler); client.setPacketHandler(handler); // Do try connect in another thread. new Thread() { public void run() { initConnection(client); } }.start(); }
From source file:org.apache.hama.ipc.TestIPC.java
@SuppressWarnings("deprecation") 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", 1234); try {/* w ww .j ava 2 s . c o m*/ client.call(new LongWritable(RANDOM.nextLong()), address); 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:ch.epfl.eagle.daemon.nodemonitor.NodeMonitor.java
private List<InetSocketAddress> getCleanWorkersList() { Set<InetSocketAddress> backends = state.getNodeMonitors(); List<InetSocketAddress> listBackends = new ArrayList<InetSocketAddress>(backends); /*try {/*from w w w . j a va 2s . c om*/ //String inetAddress = InetAddress.getLocalHost().getHostAddress(); // Take out this monitor from backends int i = 0; for (InetSocketAddress backend : backends) { if (backend.getAddress().getHostAddress().equals(ipAddress)) //|| backend.getAddress().getHostAddress().equals(inetAddress)) break; i++; } //LOG.debug("STEALING: Going to search "+ ipAddress + " or "+ inetAddress + " in " + listBackends+ " index "+ i); //assert(i<listBackends.size()); listBackends.remove(i); } catch (UnknownHostException e1) { e1.printStackTrace(); }*/ // Order by id Collections.sort(listBackends, new Comparator<InetSocketAddress>() { public int compare(InetSocketAddress a1, InetSocketAddress a2) { return a1.toString().compareTo(a2.toString()); } }); return listBackends; }
From source file:org.eclipse.ecf.internal.provider.filetransfer.httpclient4.ECFHttpClientProtocolSocketFactory.java
public Socket connectSocket(final Socket sock, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { int timeout = params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0); Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, ECFHttpClientProtocolSocketFactory.class, "connectSocket " + remoteAddress.toString() + " timeout=" + timeout); //$NON-NLS-1$ //$NON-NLS-2$ try {/*from w w w . java 2s . com*/ // Use String.valueOf to protect against null Trace.trace(Activator.PLUGIN_ID, "bind(" + String.valueOf(localAddress) + ")"); //$NON-NLS-1$//$NON-NLS-2$ sock.bind(localAddress); Trace.trace(Activator.PLUGIN_ID, "connect(" + remoteAddress.toString() + ", " + timeout + ")"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ sock.connect(remoteAddress, timeout); Trace.trace(Activator.PLUGIN_ID, "connected"); //$NON-NLS-1$ } catch (IOException e) { Trace.catching(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_CATCHING, ECFHttpClientProtocolSocketFactory.class, "createSocket", e); //$NON-NLS-1$ fireEvent(socketConnectListener, new SocketClosedEvent(source, sock, sock)); Trace.throwing(Activator.PLUGIN_ID, DebugOptions.EXCEPTIONS_THROWING, ECFHttpClientProtocolSocketFactory.class, "createSocket", e); //$NON-NLS-1$ throw e; } Socket toReturn; Socket wrapped = new CloseMonitoringSocket(sock, socketConnectListener, source); SocketConnectedEvent connectedEvent = new SocketConnectedEvent(source, sock, wrapped); fireEvent(socketConnectListener, connectedEvent); // Change the wrapped socket if one of the receivers of the SocketConnectedEvent changed it if (connectedEvent.getSocket() != wrapped) { toReturn = connectedEvent.getSocket(); ((CloseMonitoringSocket) wrapped).setWrappedSocket(toReturn); } else { toReturn = wrapped; } return toReturn; }
From source file:ch.epfl.eagle.daemon.nodemonitor.NodeMonitor.java
public void initialize(Configuration conf, int nodeMonitorInternalPort) throws UnknownHostException { String mode = conf.getString(EagleConf.DEPLOYMENT_MODE, "unspecified"); stealing = conf.getBoolean(EagleConf.STEALING, EagleConf.DEFAULT_STEALING); maxStealingAttempts = conf.getInt(EagleConf.STEALING_ATTEMPTS, EagleConf.DEFAULT_STEALING_ATTEMPTS); smallPartition = conf.getInt(EagleConf.SMALL_PARTITION, EagleConf.DEFAULT_SMALL_PARTITION); bigPartition = conf.getInt(EagleConf.BIG_PARTITION, EagleConf.DEFAULT_BIG_PARTITION); gossiping = conf.getBoolean(EagleConf.GOSSIPING, EagleConf.DEFAULT_GOSSIPING); stealingAttempts = 0;//from w w w. j a v a2 s .c o m LOG.info("STEALING set to : " + stealing); if (mode.equals("standalone")) { state = new StandaloneNodeMonitorState(); } else if (mode.equals("configbased")) { state = new ConfigNodeMonitorState(); } else { throw new RuntimeException("Unsupported deployment mode: " + mode); } try { state.initialize(conf); } catch (IOException e) { LOG.fatal("Error initializing node monitor state.", e); } longStatusTimestamp = -1; // At the beginning all nodes will be free from Long jobs notExecutingLong = new ArrayList<String>(); List<InetSocketAddress> nodeList = Lists.newArrayList(state.getNodeMonitors()); // TODO EAGLE add itself to the list for (InetSocketAddress isa : nodeList) notExecutingLong.add(isa.toString()); int mem = Resources.getSystemMemoryMb(conf); LOG.info("Using memory allocation: " + mem); ipAddress = Network.getIPAddress(conf); int cores = Resources.getSystemCPUCount(conf); LOG.info("Using core allocation: " + cores); String task_scheduler_type = conf.getString(EagleConf.NM_TASK_SCHEDULER_TYPE, "fifo"); LOG.info("Task scheduler type: " + task_scheduler_type); if (task_scheduler_type.equals("round_robin")) { scheduler = new RoundRobinTaskScheduler(cores); } else if (task_scheduler_type.equals("fifo")) { scheduler = new FifoTaskScheduler(cores, this); } else if (task_scheduler_type.equals("priority")) { scheduler = new PriorityTaskScheduler(cores); } else { throw new RuntimeException("Unsupported task scheduler type: " + mode); } scheduler.initialize(conf, nodeMonitorInternalPort); taskLauncherService = new TaskLauncherService(); taskLauncherService.initialize(conf, scheduler, nodeMonitorInternalPort); }