/** * Returns array of unique randomly available tcp ports of specified count. */ public static int getRandomAvailablePortForDUnitSite() { int site = 1; String hostName = System.getProperty("hostName"); if(hostName != null && hostName.startsWith("host")) { if (hostName.length() > 4) { site = Integer.parseInt(hostName.substring(4)); } } int port = AvailablePort.getRandomAvailablePortWithMod(AvailablePort.SOCKET,site); return port; }
/** * Returns array of unique randomly available tcp ports of specified count. */ public static int getRandomAvailablePortForDUnitSite() { int site = 1; String hostName = System.getProperty("hostName"); if(hostName != null && hostName.startsWith("host")) { if (hostName.length() > 4) { site = Integer.parseInt(hostName.substring(4)); } } int port = AvailablePort.getRandomAvailablePortWithMod(AvailablePort.SOCKET,site); return port; }
/** * Returns a randomly selected available port in the range 5001 to * 32767 that satisfies a modulus * * @param protocol * The protocol to check (either {@link #SOCKET} or {@link * #MULTICAST}). * * @throws IllegalArgumentException * <code>protocol</code> is unknown */ public static int getRandomAvailablePortWithMod(int protocol,int mod) { return getRandomAvailablePortWithMod(protocol, getAddress(protocol),mod); }
/** * Returns a randomly selected available port in the range 5001 to * 32767 that satisfies a modulus * * @param protocol * The protocol to check (either {@link #SOCKET} or {@link * #JGROUPS}). * * @throws IllegalArgumentException * <code>protocol</code> is unknown */ public static int getRandomAvailablePortWithMod(int protocol,int mod) { return getRandomAvailablePortWithMod(protocol, getAddress(protocol),mod); }
/** * Returns array of unique randomly available tcp ports of specified count. */ public static int[] getRandomAvailableTCPPortsForDUnitSite(int count) { int site = 1; String hostName = System.getProperty("hostName"); if(hostName.startsWith("host") && hostName.length() > 4) { site = Integer.parseInt(hostName.substring(4)); } Set set = new HashSet(); while (set.size() < count) { int port = AvailablePort.getRandomAvailablePortWithMod(AvailablePort.SOCKET,site); set.add(new Integer(port)); } int[] ports = new int[set.size()]; int i = 0; for (Iterator iter = set.iterator(); iter.hasNext();) { ports[i] = ((Integer) iter.next()).intValue(); i++; } return ports; }
/** * Returns array of unique randomly available tcp ports of specified count. */ public static int[] getRandomAvailableTCPPortsForDUnitSite(int count) { int site = 1; String hostName = System.getProperty("hostName"); if(hostName != null && hostName.startsWith("host") && hostName.length() > 4) { site = Integer.parseInt(hostName.substring(4)); } Set set = new HashSet(); while (set.size() < count) { int port = AvailablePort.getRandomAvailablePortWithMod(AvailablePort.SOCKET,site); set.add(new Integer(port)); } int[] ports = new int[set.size()]; int i = 0; for (Iterator iter = set.iterator(); iter.hasNext();) { ports[i] = ((Integer) iter.next()).intValue(); i++; } return ports; }