コード例 #1
0
 /**
  * Checks if this started server has already a configured proxy and returns the associated port if
  * it is still free, or associate a new port if the previous port is not avaiable anymore, or
  * create a new port if none existed before.
  *
  * @param startedServer
  * @return the proxy port
  * @throws CoreException
  */
 private int getProxyPort(final IServer startedServer) throws CoreException {
   final IServer liveReloadServer = getServer();
   @SuppressWarnings("unchecked")
   final Map<String, Integer> proxyPorts =
       liveReloadServer.getAttribute(PROXY_PORTS, new HashMap<String, Integer>());
   final String startedServerId = startedServer.getId();
   if (proxyPorts.containsKey(startedServerId)) {
     final int port = proxyPorts.get(startedServerId);
     if (!SocketUtil.isPortInUse(port)) {
       return port;
     }
   }
   final IServerWorkingCopy swc = getServer().createWorkingCopy();
   final int port = SocketUtil.findUnusedPort(50000, 60000);
   proxyPorts.put(startedServerId, port);
   swc.setAttribute(PROXY_PORTS, proxyPorts);
   swc.saveAll(true, null);
   return port;
 }
 @Before
 public void setup() throws IOException, CoreException {
   // remove all servers
   for (final IServer server : ServerCore.getServers()) {
     server.stop(true);
     TaskMonitor monitor =
         new TaskMonitor() {
           @Override
           public boolean isComplete() {
             return !(server.canStop().isOK());
           }
         };
     TimeoutUtils.timeout(monitor, 2, TimeUnit.SECONDS);
     server.delete();
   }
   //
   EventService.getInstance().resetSubscribers();
   liveReloadServerPort = SocketUtil.findUnusedPort(50000, 55000);
 }