/*
 * Copyright 2014 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.internal.state;

import net.kuujo.copycat.CopycatState;
import net.kuujo.copycat.protocol.*;

import java.util.concurrent.CompletableFuture;

/**
 * Non-existent state.<p>
 *
 * The <code>None</code> state is used to represent a non-existent
 * state in a CopyCat context.
 *
 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
 */
public class NoneController extends StateController {

  @Override
  CopycatState state() {
    return CopycatState.NONE;
  }

  @Override
  public void init(StateContext context) {
    // Don't call super.init() here so that server handlers won't be registered.
    context.currentLeader(null);
  }

  @Override
  public CompletableFuture<SyncResponse> sync(SyncRequest request) {
    return CompletableFuture.completedFuture(new SyncResponse(request.id(), "Replica is not alive"));
  }

  @Override
  public CompletableFuture<PollResponse> poll(PollRequest request) {
    return CompletableFuture.completedFuture(new PollResponse(request.id(), "Replica is not alive"));
  }

  @Override
  public CompletableFuture<SubmitResponse> submit(SubmitRequest request) {
    return CompletableFuture.completedFuture(new SubmitResponse(request.id(), "Replica is not alive"));
  }

  @Override
  void destroy() {
    // Do nothing.
  }

  @Override
  public String toString() {
    return "None[context=null]";
  }

}

@@ -719,16 +719,73 @@
 tocol.*;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -1083,16 +1083,102 @@
 roller %7B
+%0A  private static final Logger LOGGER = LoggerFactory.getLogger(NoneController.class);
 %0A%0A  @Ove
@@ -1239,24 +1239,80 @@
 .NONE;%0A  %7D%0A%0A
+  @Override%0A  Logger logger() %7B%0A    return LOGGER;%0A  %7D%0A%0A
   @Override%0A
@@ -1465,32 +1465,245 @@
 der(null);%0A  %7D%0A%0A
+  @Override%0A  public CompletableFuture%3CPingResponse%3E ping(PingRequest request) %7B%0A    return CompletableFuture.completedFuture(logResponse(new PingResponse(logRequest(request).id(), %22Replica is not alive%22)));%0A  %7D%0A%0A
   @Override%0A  pu
@@ -1808,24 +1808,36 @@
 letedFuture(
+logResponse(
 new SyncResp
@@ -1833,39 +1833,51 @@
 ew SyncResponse(
+logRequest(
 request
+)
 .id(), %22Replica 
@@ -1883,32 +1883,33 @@
  is not alive%22))
+)
 ;%0A  %7D%0A%0A  @Overri
@@ -2021,24 +2021,36 @@
 letedFuture(
+logResponse(
 new PollResp
@@ -2046,39 +2046,51 @@
 ew PollResponse(
+logRequest(
 request
+)
 .id(), %22Replica 
@@ -2096,32 +2096,33 @@
  is not alive%22))
+)
 ;%0A  %7D%0A%0A  @Overri
@@ -2244,16 +2244,28 @@
 dFuture(
+logResponse(
 new Subm
@@ -2275,23 +2275,35 @@
 esponse(
+logRequest(
 request
+)
 .id(), %22
@@ -2325,16 +2325,17 @@
 alive%22))
+)
 ;%0A  %7D%0A%0A 

Add missing NoneController methods.