package net.zoldar.ldap.testserver;

import com.github.trevershick.test.ldap.LdapServerResource;
import com.github.trevershick.test.ldap.annotations.LdapConfiguration;
import py4j.GatewayServer;

public class Server {
    private static GatewayServer gateway;

    private LdapServerResource server;

    public static void main(String[] args) throws Exception {
        gateway = new GatewayServer(new Server());
        gateway.start();
        System.out.println("Gateway server started on port "+gateway.getPort()+"!");
    }

    private Server() {}

    public void stop() {
        server.stop();
    }

    public void start(LdapConfiguration config) throws Exception {
        server = new LdapServerResourceCreator(config).getResource();
        server.start();
    }

    public int port() {
        return server.port();
    }
}

@@ -189,16 +189,43 @@
 erver;%0A%0A
+import java.util.HashMap;%0A%0A
 public c
@@ -292,16 +292,33 @@
  private
+ HashMap%3CInteger,
  LdapSer
@@ -328,23 +328,25 @@
 Resource
+%3E
  server
+s
 ;%0A%0A    p
@@ -596,58 +596,196 @@
 () %7B
-%7D%0A%0A    public void stop() %7B%0A        server.stop();
+%0A        servers = new HashMap%3CInteger, LdapServerResource%3E();%0A    %7D%0A%0A    public void stop() %7B%0A        for (Integer key : servers.keySet()) %7B%0A            servers.get(key).stop();%0A        %7D
 %0A   
@@ -859,24 +859,67 @@
 n %7B%0A        
+LdapServerResource new_server;%0A        new_
 server = new
@@ -972,24 +972,28 @@
 ();%0A        
+new_
 server.start
@@ -991,24 +991,247 @@
 ver.start();
+%0A%0A        // stop any existing servers running and clean them up%0A        stop();%0A        for (Integer key : servers.keySet()) %7B%0A            servers.remove(key);%0A        %7D%0A%0A        servers.put(new_server.port(), new_server);
 %0A    %7D%0A%0A    
@@ -1267,24 +1267,72 @@
 eturn server
+s.values().toArray(new LdapServerResource%5B0%5D)%5B0%5D
 .port();%0A   

Manage the LdapServerResource in a HashMap