/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.kuujo.copycat.examples.server;

import java.net.InetAddress;

import net.kuujo.copycat.Copycat;
import net.kuujo.copycat.CopycatServer;
import net.kuujo.copycat.cluster.NettyCluster;
import net.kuujo.copycat.cluster.NettyMember;
import net.kuujo.copycat.raft.log.Log;
import net.kuujo.copycat.raft.log.StorageLevel;

/**
 * Server example.
 *
 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
 */
public class ServerExample {

  /**
   * Starts the server.
   */
  public static void main(String[] args) throws Exception {
    if (args.length < 2)
      throw new IllegalArgumentException("must supply a serverId:port and at least one remoteId:host:port triple");

    String[] parts = args[0].split(":");
    int serverId = Integer.valueOf(parts[0]);
    int port = Integer.valueOf(parts[1]);

    NettyCluster.Builder builder = NettyCluster.builder()
      .withMemberId(serverId)
      .withHost(InetAddress.getLocalHost().getHostName())
      .withPort(port);

    for (int i = 1; i < args.length; i++) {
      parts = args[i].split(":");
      builder.addMember(NettyMember.builder()
        .withId(1)
        .withId(Integer.valueOf(parts[0]))
        .withHost(InetAddress.getByName(parts[1]).getHostName())
        .withPort(Integer.valueOf(parts[2]))
        .build());
    }

    Copycat copycat = CopycatServer.builder()
      .withCluster(builder.build())
      .withLog(Log.builder().withStorageLevel(StorageLevel.MEMORY).build())
      .build();

    copycat.open().join();

    while (copycat.isOpen()) {
      Thread.sleep(1000);
    }
  }

}

@@ -652,38 +652,8 @@
 r;%0A%0A
-import java.net.InetAddress;%0A%0A
 impo
@@ -903,16 +903,46 @@
 Level;%0A%0A
+import java.net.InetAddress;%0A%0A
 /**%0A * S
@@ -1515,16 +1515,83 @@
 rverId)%0A
+      .addMember(NettyMember.builder()%0A        .withId(serverId)%0A  
       .w
@@ -1642,24 +1642,26 @@
 me())%0A      
+  
 .withPort(po
@@ -1663,16 +1663,34 @@
 rt(port)
+%0A        .build())
 ;%0A%0A    f
@@ -1758,24 +1758,24 @@
 split(%22:%22);%0A
+
       builde
@@ -1812,27 +1812,8 @@
 r()%0A
-        .withId(1)%0A
     

Fix server example.