1 /***
2 *
3 */
4 package de.cohesion.bssh.impl;
5
6 import java.util.HashSet;
7 import java.util.Random;
8 import java.util.Set;
9
10 /***
11 * @author schulzs
12 */
13 public class Ports {
14
15 private static final Random RANDOM = new Random();
16
17 private static final Set<Integer> portsInUse = new HashSet<Integer>();
18
19 public static synchronized int getPort() {
20 int port;
21 while (true) {
22 port = 15000 + RANDOM.nextInt(1000);
23 if (!portsInUse.contains(port)) {
24 portsInUse.add(port);
25 break;
26 }
27 }
28 return port;
29 }
30
31 }