/*
 * DISCLAIMER
 *
 * Copyright 2017 ArangoDB GmbH, Cologne, Germany
 *
 * 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.
 *
 * Copyright holder is ArangoDB GmbH, Cologne, Germany
 */

package com.arangodb.internal.net;

import java.util.List;

import com.arangodb.internal.Host;

/**
 * @author Mark Vollmary
 *
 */
public class RoundRobinHostHandler implements HostHandler {

	private final HostResolver resolver;
	private Host current;

	public RoundRobinHostHandler(final HostResolver resolver) {
		super();
		this.resolver = resolver;
		current = resolver.resolve(true, false).get(0);
	}

	@Override
	public Host get() {
		final List<Host> hosts = resolver.resolve(false, false);
		final int index = hosts.indexOf(current) + 1;
		current = hosts.get(index < hosts.size() ? index : 0);
		return current;
	}

	@Override
	public void success() {
	}

	@Override
	public void fail() {
	}

}

@@ -971,16 +971,37 @@
 urrent;%0D
+%0A%09private int fails;%0D
 %0A%0D%0A%09publ
@@ -1149,16 +1149,30 @@
 et(0);%0D%0A
+%09%09fails = 0;%0D%0A
 %09%7D%0D%0A%0D%0A%09@
@@ -1263,16 +1263,69 @@
 alse);%0D%0A
+%09%09if (fails %3E hosts.size()) %7B%0D%0A%09%09%09return null;%0D%0A%09%09%7D%0D%0A
 %09%09final 
@@ -1482,24 +1482,38 @@
 uccess() %7B%0D%0A
+%09%09fails = 0;%0D%0A
 %09%7D%0D%0A%0D%0A%09@Over
@@ -1510,32 +1510,32 @@
 %0D%0A%0D%0A%09@Override%0D%0A
-
 %09public void fai
@@ -1541,16 +1541,28 @@
 il() %7B%0D%0A
+%09%09fails++;%0D%0A
 %09%7D%0D%0A%0D%0A%7D%0D

Fix RoundRobinHostHandler (add maximum retries)