// Path: src/org/gearman/GearmanLostConnectionPolicy.java
// public final static class Action {
// 		
// 	static final Action RECONNECT = new Action(0);
// 	static final Action DROP = new Action(0);
// 		
// 	private final long nanoTime;
// 		
// 	private Action(final long nanoTime) {
// 		this.nanoTime = nanoTime;
// 	}
// 		
// 	/**
// 	 * Tells the calling service to reconnect at it's own discretion
// 	 */
// 	public static Action reconnectServer() {
// 		return RECONNECT;
// 	}
// 		
// 	/**
// 	 * Tells the calling service to reconnect no earlier then the the specified delay
// 	 * 
// 	 * @param time
// 	 * 		The amount of time that must pass before any attempts to reconnect can occur
// 	 * @param unit
// 	 * 		The unit time
// 	 */
// 	public static Action reconnectServer(long time, final TimeUnit unit) {
// 		if(time<0) time=0;
// 		return new Action(unit.toNanos(time));
// 	}
// 		
// 	/**
// 	 * Tells the calling service to drop the server from its control
// 	 */
// 	public static Action dropServer() {
// 		return DROP;
// 	}
// 		
// 	/**
// 	 * Returns the amount of time the gearman service must wait before attempting
// 	 * to reconnect
// 	 * 
// 	 * @return
// 	 * 		The amount of time the gearman service must wait before attempting
// 	 * 		to reconnect
// 	 */
// 	long getNanoTime() {
// 		return nanoTime;
// 	}
// }
// 
// Path: src/org/gearman/GearmanLostConnectionPolicy.java
// public static enum Grounds {
// 		
// 	/**
// 	 * The server in question unexpectedly disconnected.
// 	 */
// 	UNEXPECTED_DISCONNECT,
// 		
// 	/**
// 	 * The gearman service failed to connect to a server registed with the service  
// 	 */
// 	FAILED_CONNECTION,
// 		
// 	/** 
// 	 * The connection was closed due to a server failing to respond
// 	 */
// 	RESPONCE_TIMEOUT,
// };
// 
// Path: src/org/gearman/core/GearmanCallbackResult.java
// public interface GearmanCallbackResult {
// 	
// 	/**
// 	 * Tests if the operation completed successfully
// 	 * @return
// 	 * 		<code>true</code> if and only if the operation was successful
// 	 */
// 	public boolean isSuccessful();
// }


import java.net.InetSocketAddress;
import java.util.Deque;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.gearman.GearmanLostConnectionPolicy.Action;
import org.gearman.GearmanLostConnectionPolicy.Grounds;
import org.gearman.core.GearmanCallbackResult;
			/*
			 * Open a new local connection. This connection controller is both
			 * the GearmanConnectionHandler and GearmanFailureHandler
			 */
			super.getKey().createGearmanConnection(this, this);
		}
	}
	
	private final class RemoteConnectionController extends InnerConnectionController<InetSocketAddress, org.gearman.core.GearmanConnectionManager.ConnectCallbackResult> implements Runnable{
		RemoteConnectionController(InetSocketAddress key) {
			super(key);
		}
		
		@Override
		protected void onLostConnection(GearmanLostConnectionPolicy policy, Grounds grounds) {
			super.onLostConnection(policy, grounds);
			
			Action action = null;
			
			try {
				action = policy.lostRemoteServer(this.getKey(), ClientImpl.this, grounds);
			} catch (Throwable t) {
				action = null;
			}
			
			if(action==null) {
				action = ClientImpl.this.getDefaultPolicy().lostRemoteServer(this.getKey(), ClientImpl.this, grounds);
				assert action!=null;
			}
			
// Path: src/org/gearman/GearmanLostConnectionPolicy.java
// public final static class Action {
// 		
// 	static final Action RECONNECT = new Action(0);
// 	static final Action DROP = new Action(0);
// 		
// 	private final long nanoTime;
// 		
// 	private Action(final long nanoTime) {
// 		this.nanoTime = nanoTime;
// 	}
// 		
// 	/**
// 	 * Tells the calling service to reconnect at it's own discretion
// 	 */
// 	public static Action reconnectServer() {
// 		return RECONNECT;
// 	}
// 		
// 	/**
// 	 * Tells the calling service to reconnect no earlier then the the specified delay
// 	 * 
// 	 * @param time
// 	 * 		The amount of time that must pass before any attempts to reconnect can occur
// 	 * @param unit
// 	 * 		The unit time
// 	 */
// 	public static Action reconnectServer(long time, final TimeUnit unit) {
// 		if(time<0) time=0;
// 		return new Action(unit.toNanos(time));
// 	}
// 		
// 	/**
// 	 * Tells the calling service to drop the server from its control
// 	 */
// 	public static Action dropServer() {
// 		return DROP;
// 	}
// 		
// 	/**
// 	 * Returns the amount of time the gearman service must wait before attempting
// 	 * to reconnect
// 	 * 
// 	 * @return
// 	 * 		The amount of time the gearman service must wait before attempting
// 	 * 		to reconnect
// 	 */
// 	long getNanoTime() {
// 		return nanoTime;
// 	}
// }
// 
// Path: src/org/gearman/GearmanLostConnectionPolicy.java
// public static enum Grounds {
// 		
// 	/**
// 	 * The server in question unexpectedly disconnected.
// 	 */
// 	UNEXPECTED_DISCONNECT,
// 		
// 	/**
// 	 * The gearman service failed to connect to a server registed with the service  
// 	 */
// 	FAILED_CONNECTION,
// 		
// 	/** 
// 	 * The connection was closed due to a server failing to respond
// 	 */
// 	RESPONCE_TIMEOUT,
// };
// 
// Path: src/org/gearman/core/GearmanCallbackResult.java
// public interface GearmanCallbackResult {
// 	
// 	/**
// 	 * Tests if the operation completed successfully
// 	 * @return
// 	 * 		<code>true</code> if and only if the operation was successful
// 	 */
// 	public boolean isSuccessful();
// }


// Path: src/org/gearman/ClientImpl.java
import java.net.InetSocketAddress;
import java.util.Deque;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.gearman.GearmanLostConnectionPolicy.Action;
import org.gearman.GearmanLostConnectionPolicy.Grounds;
import org.gearman.core.GearmanCallbackResult;

			/*
			 * Open a new local connection. This connection controller is both
			 * the GearmanConnectionHandler and GearmanFailureHandler
			 */
			super.getKey().createGearmanConnection(this, this);
		}
	}
	
	private final class RemoteConnectionController extends InnerConnectionController<InetSocketAddress, org.gearman.core.GearmanConnectionManager.ConnectCallbackResult> implements Runnable{
		RemoteConnectionController(InetSocketAddress key) {
			super(key);
		}
		
		@Override
		protected void onLostConnection(GearmanLostConnectionPolicy policy, Grounds grounds) {
			super.onLostConnection(policy, grounds);
			
			Action action = null;
			
			try {
				action = policy.lostRemoteServer(this.getKey(), ClientImpl.this, grounds);
			} catch (Throwable t) {
				action = null;
			}
			
			if(action==null) {
				action = ClientImpl.this.getDefaultPolicy().lostRemoteServer(this.getKey(), ClientImpl.this, grounds);
				assert action!=null;
			}
			
			if(action.equals(Action.DROP)) {