/** * Constructs an {@link AvailablePortIterator}. * <p> * Defaults to using the wildcard address and full port range. */ public AvailablePortIterator() { this(MINIMUM_PORT, MAXIMUM_PORT, NetworkHelper.getWildcardAddress()); }
this.address = NetworkHelper.getFeasibleLocalHost(); this.address = NetworkHelper.getFeasibleLocalHost(); List<InetAddress> bindableAddresses = NetworkHelper.getInetAddresses(NetworkHelper.BINDABLE_ADDRESS);
/** * Construct a new {@link JavaVirtualMachine}. * This constructor is private as the {@link JavaVirtualMachine} * platform is a singleton as there is only one local JVM. */ private JavaVirtualMachine() { super("Java Virtual Machine"); // ----- establish InetAddress of the LocalPlatform ----- // attempt to use the system property that may have been defined // (in the future we may use a PlatformAddress Option to achieve this) String addressSystemProperty = System.getProperty("bedrock.runtime.address"); if (addressSystemProperty == null) { this.address = NetworkHelper.getFeasibleLocalHost(); } else { try { this.address = InetAddress.getByName(addressSystemProperty); } catch (UnknownHostException e) { // TODO: log that the specified address can't be resolved, defaulting to the feasible localhost this.address = NetworkHelper.getFeasibleLocalHost(); } } }
/** * Acquires the first {@link InetAddress} (of the machine on which this code is executing) * that matches the specified {@link Predicate}. * * @param predicate the {@link InetAddress} {@link Predicate} * * @return an {@link InetAddress} or <code>null</code> if no matching {@link InetAddress} * * @throws SocketException when an {@link InetAddress} is not available */ public static InetAddress getInetAddress(Predicate<? super InetAddress> predicate) throws SocketException { for (NetworkInterface networkInterface : getNetworkInterfaces(Predicates.<NetworkInterface>always())) { for (Enumeration addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements(); ) { InetAddress address = (InetAddress) addresses.nextElement(); if (predicate.test(address)) { return address; } } } return null; }
/** * Constructs a local {@link TransportAddress}, choosing a port from the * {@link AvailablePortIterator}. * * @param ports the available ports */ public TransportAddress(AvailablePortIterator ports) { // NOTE: Currently Java Debugging only supports IPv4 on the server-side so we must // filter the AvailablePortIterator addresses into those that are IPv4 this(NetworkHelper.getInetAddresses(ports.getInetAddresses(), NetworkHelper.IPv4_ADDRESS).iterator().next(), new Capture<>(ports)); }
/** * Obtains the {@link InetAddress} on which the {@link SocketBasedRemoteChannelServer} * will accept connections (based on a specific {@link Predicate}) * * @param predicate the {@link Predicate} to filter {@link InetAddress}es * (or <code>null</code> indicating the default is acceptable) * * @return the {@link InetAddress} */ public synchronized InetAddress getInetAddress(Predicate<InetAddress> predicate) { if (serverSocket != null) { try { predicate = predicate == null ? NetworkHelper.DEFAULT_ADDRESS : predicate; InetAddress inetAddress = NetworkHelper.getInetAddress(predicate); // when the specific inetAddess is not available, use the server socket return inetAddress == null ? serverSocket.getInetAddress() : inetAddress; } catch (SocketException e) { return serverSocket.getInetAddress(); } } else { throw new IllegalStateException("Server is closed"); } }
this.address = NetworkHelper.getFeasibleLocalHost(); this.address = NetworkHelper.getFeasibleLocalHost(); List<InetAddress> bindableAddresses = NetworkHelper.getInetAddresses(NetworkHelper.BINDABLE_ADDRESS);
/** * Construct a new {@link JavaVirtualMachine}. * This constructor is private as the {@link JavaVirtualMachine} * platform is a singleton as there is only one local JVM. */ private JavaVirtualMachine() { super("Java Virtual Machine"); // ----- establish InetAddress of the LocalPlatform ----- // attempt to use the system property that may have been defined // (in the future we may use a PlatformAddress Option to achieve this) String addressSystemProperty = System.getProperty("bedrock.runtime.address"); if (addressSystemProperty == null) { this.address = NetworkHelper.getFeasibleLocalHost(); } else { try { this.address = InetAddress.getByName(addressSystemProperty); } catch (UnknownHostException e) { // TODO: log that the specified address can't be resolved, defaulting to the feasible localhost this.address = NetworkHelper.getFeasibleLocalHost(); } } }
/** * Acquires the first {@link InetAddress} (of the machine on which this code is executing) * that matches the specified {@link Predicate}. * * @param predicate the {@link InetAddress} {@link Predicate} * * @return an {@link InetAddress} or <code>null</code> if no matching {@link InetAddress} * * @throws SocketException when an {@link InetAddress} is not available */ public static InetAddress getInetAddress(Predicate<? super InetAddress> predicate) throws SocketException { for (NetworkInterface networkInterface : getNetworkInterfaces(Predicates.<NetworkInterface>always())) { for (Enumeration addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements(); ) { InetAddress address = (InetAddress) addresses.nextElement(); if (predicate.test(address)) { return address; } } } return null; }
/** * Constructs a local {@link TransportAddress}, choosing a port from the * {@link AvailablePortIterator}. * * @param ports the available ports */ public TransportAddress(AvailablePortIterator ports) { // NOTE: Currently Java Debugging only supports IPv4 on the server-side so we must // filter the AvailablePortIterator addresses into those that are IPv4 this(NetworkHelper.getInetAddresses(ports.getInetAddresses(), NetworkHelper.IPv4_ADDRESS).iterator().next(), new Capture<>(ports)); }
/** * Obtains the {@link InetAddress} on which the {@link SocketBasedRemoteChannelServer} * will accept connections (based on a specific {@link Predicate}) * * @param predicate the {@link Predicate} to filter {@link InetAddress}es * (or <code>null</code> indicating the default is acceptable) * * @return the {@link InetAddress} */ public synchronized InetAddress getInetAddress(Predicate<InetAddress> predicate) { if (serverSocket != null) { try { predicate = predicate == null ? NetworkHelper.DEFAULT_ADDRESS : predicate; InetAddress inetAddress = NetworkHelper.getInetAddress(predicate); // when the specific inetAddess is not available, use the server socket return inetAddress == null ? serverSocket.getInetAddress() : inetAddress; } catch (SocketException e) { return serverSocket.getInetAddress(); } } else { throw new IllegalStateException("Server is closed"); } }
/** * Start the HTTP server that will be used to serve the artifacts * to be deployed. * * @param executor the {@link Executor} to pass to the {@link HttpServer} * @param artifacts a {@link Map} of {@link DeploymentArtifact}s to deploy * keyed by the URL path for each artifact * * @return the {@link HttpServer} */ protected HttpServer createServer(ExecutorService executor, Map<String, DeploymentArtifact> artifacts) { try { LocalPlatform platform = LocalPlatform.get(); InetAddress address = NetworkHelper.getFeasibleLocalHost(); int port = platform.getAvailablePorts().next(); HttpServer server = HttpServer.create(new InetSocketAddress(address, port), 0); server.createContext("/", new ArtifactsHandler(artifacts, optionsByType.asArray())); server.setExecutor(executor); server.start(); return server; } catch (IOException e) { throw new RuntimeException("Unable to create HTTP server", e); } }
/** * Constructs an {@link AvailablePortIterator} * <p> * Defaults to using the wildcard address and a starting port. * * @param portRangeStart the port at which to start scanning (inclusive) */ public AvailablePortIterator(int portRangeStart) { this(portRangeStart, MAXIMUM_PORT, NetworkHelper.getWildcardAddress()); }
for (NetworkInterface networkInterface : getNetworkInterfaces(Predicates.<NetworkInterface>always()))
/** * Constructs an {@link AvailablePortIterator}. * <p> * Defaults to using the wildcard address with the specified port range. * * @param portRangeStart the port at which to start scanning (inclusive) * @param portRangeEnd the port at which to destroy scanning (inclusive) */ public AvailablePortIterator(int portRangeStart, int portRangeEnd) { this(portRangeStart, portRangeEnd, NetworkHelper.getWildcardAddress()); }
for (NetworkInterface networkInterface : getNetworkInterfaces(Predicates.<NetworkInterface>always()))
/** * Constructs an {@link AvailablePortIterator} * <p> * Defaults to using the wildcard address and a starting port. * * @param portRangeStart the port at which to start scanning (inclusive) */ public AvailablePortIterator(int portRangeStart) { this(portRangeStart, MAXIMUM_PORT, NetworkHelper.getWildcardAddress()); }
for (NetworkInterface networkInterface : getNetworkInterfaces(Predicates.<NetworkInterface>always()))
/** * Constructs an {@link AvailablePortIterator}. * <p> * Defaults to using the wildcard address and full port range. */ public AvailablePortIterator() { this(MINIMUM_PORT, MAXIMUM_PORT, NetworkHelper.getWildcardAddress()); }
for (NetworkInterface networkInterface : getNetworkInterfaces(Predicates.<NetworkInterface>always()))