package com.codingchili.router;

import com.codingchili.router.configuration.ListenerSettings;
import com.codingchili.router.configuration.RouterContext;
import com.codingchili.router.controller.RouterHandler;
import com.codingchili.router.controller.transport.*;
import io.vertx.core.*;

import com.codingchili.core.protocol.ClusterNode;

/**
 * @author Robin Duda
 *         root game server, deploys realmName servers.
 */
public class Service extends ClusterNode {
    private RouterContext context;

    public Service(RouterContext context) {
        this.context = context;
    }

    @Override
    public void init(Vertx vertx, Context context) {
        super.init(vertx, context);

        if (context == null) {
            this.context = new RouterContext(vertx);
        }
    }

    @Override
    public void start(Future<Void> start) {
        for (int i = 0; i < settings.getHandlers(); i++) {

            for (ListenerSettings listener : context.transports()) {
                RouterHandler<RouterContext> handler = new RouterHandler<>(context);

                switch (listener.getType()) {
                    case UDP:
                        context.deploy(new UdpListener(handler));
                        break;
                    case TCP:
                        context.deploy(new TcpListener(handler));
                        break;
                    case WEBSOCKET:
                        context.deploy(new WebsocketListener(handler));
                        break;
                    case REST:
                        context.deploy(new RestListener(handler));
                        break;
                }
            }
        }
        start.complete();
    }
}

@@ -848,72 +848,8 @@
 ) %7B%0A
-        for (int i = 0; i %3C settings.getHandlers(); i++) %7B%0A%0A    
     
@@ -905,28 +905,24 @@
 sports()) %7B%0A
-    
             
@@ -983,32 +983,204 @@
 er%3C%3E(context);%0A%0A
+            for (int i = 0; i %3C settings.getHandlers(); i++) %7B%0A                boolean singleHandlerOnly = false;%0A                Future%3CString%3E future = Future.future();%0A%0A
                 
@@ -1294,33 +1294,91 @@
 istener(handler)
-)
+, future);%0A                        singleHandlerOnly = true
 ;%0A              
@@ -1799,32 +1799,118 @@
               %7D%0A
+                if (singleHandlerOnly) %7B%0A                    break;%0A                %7D%0A
             %7D%0A  

Deploy a single listener for UDP as port reuse is not supported.