@Bean public Candidate candidate(LeaderProperties leaderProperties) throws UnknownHostException { String id = Inet4Address.getLocalHost().getHostName(); String role = leaderProperties.getRole(); return new DefaultCandidate(id, role); }
private static String getUid(Configuration config) { final String localHostErrMsg = "Cannot determine local host"; final String uid; if (config.has(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_HOSTNAME) && config.get(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_HOSTNAME)) { try { uid = Inet4Address.getLocalHost().getHostName(); } catch (UnknownHostException e) { throw new JanusGraphConfigurationException(localHostErrMsg, e); } } else { final byte[] addrBytes; try { addrBytes = Inet4Address.getLocalHost().getAddress(); } catch (UnknownHostException e) { throw new JanusGraphConfigurationException(localHostErrMsg, e); } uid = new String(Hex.encodeHex(addrBytes)); } return uid; }
private static String computeUniqueInstanceId(Configuration config) { final String suffix; if (config.has(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_SUFFIX)) { suffix = LongEncoding.encode(config.get( GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_SUFFIX)); } else { suffix = ManagementFactory.getRuntimeMXBean().getName() + LongEncoding.encode(INSTANCE_COUNTER.incrementAndGet()); } byte[] addrBytes; try { addrBytes = Inet4Address.getLocalHost().getAddress(); } catch (UnknownHostException e) { throw new TitanConfigurationException("Cannot determine local host", e); } String uid = new String(Hex.encodeHex(addrBytes)) + suffix; for (char c : ConfigElement.ILLEGAL_CHARS) { uid = StringUtils.replaceChars(uid,c,'-'); } return uid; }
@Test public void instanceIdShouldEqualHostname() throws UnknownHostException { final Map<String, Object> map = new HashMap<String, Object>(); map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory"); map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true); final MapConfiguration config = new MapConfiguration(map); final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config))); assertEquals(graph.openManagement().getOpenInstances().size(), 1); assertEquals(graph.openManagement().getOpenInstances().toArray()[0], Inet4Address.getLocalHost().getHostName()); graph.close(); }
@Test public void instanceIdShouldEqualHostnamePlusSuffix() throws UnknownHostException { final Map<String, Object> map = new HashMap<String, Object>(); map.put(STORAGE_BACKEND.toStringWithoutRoot(), "inmemory"); map.put(UNIQUE_INSTANCE_ID_HOSTNAME.toStringWithoutRoot(), true); map.put(UNIQUE_INSTANCE_ID_SUFFIX.toStringWithoutRoot(), 1); final MapConfiguration config = new MapConfiguration(map); final StandardJanusGraph graph = new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(config))); assertEquals(graph.openManagement().getOpenInstances().size(), 1); assertEquals(graph.openManagement().getOpenInstances().toArray()[0], Inet4Address.getLocalHost().getHostName() + "1"); graph.close(); } }
public RSVPHopIPv4(){ classNum = 3; cType = 1; length = 12; bytes = new byte[length]; try{ next_previousHopAddress = (Inet4Address) Inet4Address.getLocalHost(); }catch(UnknownHostException e){ } logicalInterfaceHandle = 0; }
public FilterSpecIPv4(){ classNum = 10; cType = 1; length = 12; bytes = new byte[length]; try{ srcAddress = (Inet4Address) Inet4Address.getLocalHost(); }catch(UnknownHostException e){ } srcPort = 0; }
public ResvConfirmIPv4(){ classNum = 15; cType = 1; length = 8; bytes = new byte[length]; try{ receiverAddress = (Inet4Address) Inet4Address.getLocalHost(); }catch(UnknownHostException e){ } }
/** * @return Your ip. */ public static String getYourIp() throws UnknownHostException { return Inet4Address.getLocalHost().getHostAddress(); }
@SneakyThrows(UnknownHostException.class) private static String getHostAddress() { return Inet4Address.getLocalHost().getHostAddress(); } }
private static String getHostAddress() { if (StringUtils.isEmpty(localHostAddress)) { try { localHostAddress = Inet4Address.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { LOG.warn("failed to get local host address", e); localHostAddress = ""; } } return localHostAddress; }
private static void addHeader(StringBuilder b) { String host = "unknown"; try { host = Inet4Address.getLocalHost().getHostName(); } catch (Exception e) { LOG.log(Level.INFO, "Failed to lookup hostname.", e); } b.append("<html>\n<head><title>System Configuration</title></head>\n" + "<body>\n" + "<h1>System Configuration</h1>\n" + "<p>This view shows the system configuration of " + host + " at " + new Date() + ".</p>"); }
private static final String generateOwnerNameFromLocalhost() { try { return Inet4Address.getLocalHost().getHostName() + UUID.randomUUID().toString(); } catch (final UnknownHostException e) { return UUID.randomUUID().toString(); } }
private AppInstance(String deploymentId, int instanceNumber, int port) throws IOException { this.deploymentId = deploymentId; this.instanceNumber = instanceNumber; this.port = port; attributes.put("port", Integer.toString(port)); attributes.put("guid", Integer.toString(port)); this.baseUrl = new URL("http", Inet4Address.getLocalHost().getHostAddress(), port, ""); attributes.put("url", baseUrl.toString()); }
private boolean isHost() { try { return (mGateway.equals(Inet4Address.getLocalHost()) || mGateway.equals(Inet6Address.getLocalHost())); } catch (UnknownHostException e) { // TODO Auto-generated catch block return false; } }
private static boolean comeFromSameHost(String host) { try { String ipStr = Inet4Address.getLocalHost().getHostAddress(); return ipStr.equals(host); } catch (UnknownHostException e) { logger.error("unknown host exception : " + e.toString()); throw new RuntimeException("unknown host exception : " + e.toString()); } }
protected static AmsNetId generateAMSNetId() { try { return AmsNetId.of(Inet4Address.getLocalHost().getHostAddress() + ".1.1"); } catch (UnknownHostException e) { throw new PlcRuntimeException(e); } }
@SneakyThrows(UnknownHostException.class) private static String getHostAddress() { return Inet4Address.getLocalHost().getHostAddress(); }
@SneakyThrows(UnknownHostException.class) private static String getHostAddress() { return Inet4Address.getLocalHost().getHostAddress(); }
private int allocateLocalPort(int port) { try { try (ServerSocket serverSocket = new ServerSocket(port, 0, Inet4Address.getLocalHost())) { return serverSocket.getLocalPort(); } } catch (Throwable t) { throw new IllegalStateException("Could not allocate local port for forwarding proxy", t); } } }