package com.orbekk.same;

import org.eclipse.jetty.server.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.googlecode.jsonrpc4j.JsonRpcServer;
import com.orbekk.net.HttpUtil;
import com.orbekk.same.http.RpcHandler;

public class ClientApp {
    private Logger logger = LoggerFactory.getLogger(getClass());
    private Server server;
    private static final int timeout = 1000;
    
    @Deprecated
    public SameInterface getClient(int port, String networkName,
            String masterUrl) {
        logger.info("Starting client with port:{}, networkName:{}, masterUrl:{}",
                new Object[]{port, networkName, masterUrl});
        ConnectionManagerImpl connections = new ConnectionManagerImpl(timeout,
                timeout);
        State state = new State(networkName);
        Broadcaster broadcaster =
                BroadcasterImpl.getDefaultBroadcastRunner();
        MasterServiceImpl master = new MasterServiceImpl(state, connections,
                broadcaster);
        ClientServiceImpl client = new ClientServiceImpl(state, connections);
        
        JsonRpcServer jsonServer = new JsonRpcServer(client, ClientService.class);
        server = new Server(port);
        RpcHandler rpcHandler = new RpcHandler(client);
        rpcHandler.addRpcServer("/ClientService.json", jsonServer);
        server.setHandler(rpcHandler);
        
        try {
            server.start();
        } catch (Exception e) {
            logger.error("Could not start jetty server: {}", e);
        }
        
        while (client.getUrl() == null) {
            HttpUtil.sendHttpRequest(masterUrl + "ping?port=" + port);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                // Ignore interrupt in wait loop.
            }
        }
        
        client.joinNetwork(masterUrl + "MasterService.json");
        return Same.createSame(client);
    }
    
    public void run(int port, String networkName,
            String masterUrl) {
        SameController controller = SameController.create(null);
        try {
            controller.start();
        } catch (Exception e) {
            logger.error("Failed to start Same", e);
        }
        controller.joinNetwork(masterUrl);
        controller.join();
    }
    
    public static void main(String[] args) {
        if (args.length < 3) {
            System.err.println("Usage: port networkName masterUrl");
            System.exit(1);
        }
        int port = Integer.parseInt(args[0]);
        String networkName = args[1];
        String masterUrl = args[2];
        (new ClientApp()).run(port, networkName, masterUrl);
        
    }
}

@@ -408,1561 +408,8 @@
    %0A
-    @Deprecated%0A    public SameInterface getClient(int port, String networkName,%0A            String masterUrl) %7B%0A        logger.info(%22Starting client with port:%7B%7D, networkName:%7B%7D, masterUrl:%7B%7D%22,%0A                new Object%5B%5D%7Bport, networkName, masterUrl%7D);%0A        ConnectionManagerImpl connections = new ConnectionManagerImpl(timeout,%0A                timeout);%0A        State state = new State(networkName);%0A        Broadcaster broadcaster =%0A                BroadcasterImpl.getDefaultBroadcastRunner();%0A        MasterServiceImpl master = new MasterServiceImpl(state, connections,%0A                broadcaster);%0A        ClientServiceImpl client = new ClientServiceImpl(state, connections);%0A        %0A        JsonRpcServer jsonServer = new JsonRpcServer(client, ClientService.class);%0A        server = new Server(port);%0A        RpcHandler rpcHandler = new RpcHandler(client);%0A        rpcHandler.addRpcServer(%22/ClientService.json%22, jsonServer);%0A        server.setHandler(rpcHandler);%0A        %0A        try %7B%0A            server.start();%0A        %7D catch (Exception e) %7B%0A            logger.error(%22Could not start jetty server: %7B%7D%22, e);%0A        %7D%0A        %0A        while (client.getUrl() == null) %7B%0A            HttpUtil.sendHttpRequest(masterUrl + %22ping?port=%22 + port);%0A            try %7B%0A                Thread.sleep(500);%0A            %7D catch (InterruptedException e) %7B%0A                // Ignore interrupt in wait loop.%0A            %7D%0A        %7D%0A        %0A        client.joinNetwork(masterUrl + %22MasterService.json%22);%0A        return Same.createSame(client);%0A    %7D%0A    %0A
     

Remove old code from ClientApp.