// Path: src/main/java/org/gm4java/engine/GMConnection.java
// public interface GMConnection extends GMExecutor {
//     /**
//      * Close {@linkplain GMConnection} and destroy the underlying GraphicsMagick process.
//      * 
//      * @throws GMServiceException
//      *             when there is error communicating with the underlying GraphicsMagick process
//      */
//     void close() throws GMServiceException;
// }
// 
// Path: src/main/java/org/gm4java/engine/GMException.java
// public class GMException extends Exception {
// 
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * Construct a new instance of exception.
//      * 
//      * @param message
//      *            the detailed message returned by GraphicsMagick
//      */
//     public GMException(String message) {
//         super(message);
//     }
// 
// }
// 
// Path: src/main/java/org/gm4java/engine/GMService.java
// public interface GMService extends GMExecutor {
//     /**
//      * Executes the GraphisMagick command and return the result.
//      * <p>
//      * This is a convenient method to {@link #getConnection() get the connection},
//      * {@link GMConnection#execute(String, String...) execute} the command once and {@link GMConnection#close() close}
//      * it. It is functionally equivalent to code below, but actual implementation may optimize this for better
//      * efficiency.
//      * 
//      * <pre>
//      * final GMConnection connection = gmService.getConnection();
//      * try {
//      *     return connection.execute(command, argument1, argument2, ...);
//      * } finally {
//      *     connection.close();
//      * }
//      * </pre>
//      * <p>
//      * This method is thread safe.
//      * 
//      * @param command
//      *            the command to be executed
//      * @param arguments
//      *            arguments of the command.
//      * @return the output from GraphicsMagick as the result of executing the command
//      * @throws NullPointerException
//      *             when command is null
//      * @throws IOException
//      *             when GM encounter IO error executing the command
//      * @throws GMException
//      *             when GraphicsMagick returns non-IO error executing the command
//      * @throws GMServiceException
//      *             when there is error communicating with the underlying GraphicsMagick process
//      */
//     @Override
//     String execute(@Nonnull String command, String... arguments) throws IOException, GMException, GMServiceException;
// 
//     /**
//      * Executes the command using the underlying GraphicsMagick process. GraphicsMagick command and its arguments are
//      * passed in as a list of strings.
//      * <p>
//      * This is a convenient method to {@link #getConnection() get the connection}, {@link GMConnection#execute(List)
//      * execute} the command once and {@link GMConnection#close() close} it. It is functionally equivalent to code below,
//      * but actual implementation may optimize this for better efficiency.
//      * 
//      * <pre>
//      * final GMConnection connection = gmService.getConnection();
//      * try {
//      *     return connection.execute(command);
//      * } finally {
//      *     connection.close();
//      * }
//      * </pre>
//      * <p>
//      * This method is thread safe.
//      * 
//      * @param command
//      *            the command and arguments to be executed
//      * @return the output from GraphicsMagick as the result of executing the command
//      * @throws NullPointerException
//      *             when command is null
//      * @throws IllegalArgumentException
//      *             when command is an empty list.
//      * @throws IOException
//      *             when GM encounter IO error executing the command
//      * @throws GMException
//      *             when GraphicsMagick returns non-IO error executing the command
//      * @throws GMServiceException
//      *             when there is error communicating with the underlying GraphicsMagick process
//      * @see #execute(String, String...)
//      */
//     @Override
//     String execute(@Nonnull List<String> command) throws IOException, GMException, GMServiceException;
// 
//     /**
//      * Gets an instance of {@link GMConnection}. Depends on the implementation, the instance can be newly created or
//      * from a pool.
//      * <p>
//      * This method is thread safe.
//      * 
//      * @return an instance of {@linkplain GMConnection}
//      * @throws GMServiceException
//      *             when communicate error occurs between the physical GraphicsMagick process.
//      */
//     @Nonnull
//     GMConnection getConnection() throws GMServiceException;
// }
// 
// Path: src/main/java/org/gm4java/engine/GMServiceException.java
// public class GMServiceException extends Exception {
// 
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * Constructs a new exception with given message.
//      * 
//      * @param message
//      *            the detailed message of the exception.
//      */
//     public GMServiceException(String message) {
//         super(message);
//     }
// 
//     /**
//      * Constructs a new exception with given message and cause.
//      * 
//      * @param message
//      *            the detailed message of the exception.
//      * @param cause
//      *            the cause of the error.
//      */
//     public GMServiceException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
// }


import org.gm4java.engine.GMConnection;
import org.gm4java.engine.GMException;
import org.gm4java.engine.GMService;
import org.gm4java.engine.GMServiceException;
import java.io.IOException;
import java.util.List;
import javax.annotation.Nonnull;
        } finally {
            pool.returnObject(connection);
        }
    }

    @Override
    public String execute(List<String> command) throws IOException, GMException, GMServiceException {
        PooledGMConnection connection = pool.borrowObject();
        try {
            return connection.execute(command);
        } finally {
            pool.returnObject(connection);
        }
    }

    /**
     * {@inheritDoc}
     * <p>
     * This implementation returns an instance from pool.
     */
    @Override
    @Nonnull
    public GMConnection getConnection() throws GMServiceException {
        return new ConnectionWrapper(pool);
    }

    void setProcessFactoryBuilder(GMProcessFactory.Builder builder) {
        pool.setProcessFactoryBuilder(builder);
    }

// Path: src/main/java/org/gm4java/engine/GMConnection.java
// public interface GMConnection extends GMExecutor {
//     /**
//      * Close {@linkplain GMConnection} and destroy the underlying GraphicsMagick process.
//      * 
//      * @throws GMServiceException
//      *             when there is error communicating with the underlying GraphicsMagick process
//      */
//     void close() throws GMServiceException;
// }
// 
// Path: src/main/java/org/gm4java/engine/GMException.java
// public class GMException extends Exception {
// 
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * Construct a new instance of exception.
//      * 
//      * @param message
//      *            the detailed message returned by GraphicsMagick
//      */
//     public GMException(String message) {
//         super(message);
//     }
// 
// }
// 
// Path: src/main/java/org/gm4java/engine/GMService.java
// public interface GMService extends GMExecutor {
//     /**
//      * Executes the GraphisMagick command and return the result.
//      * <p>
//      * This is a convenient method to {@link #getConnection() get the connection},
//      * {@link GMConnection#execute(String, String...) execute} the command once and {@link GMConnection#close() close}
//      * it. It is functionally equivalent to code below, but actual implementation may optimize this for better
//      * efficiency.
//      * 
//      * <pre>
//      * final GMConnection connection = gmService.getConnection();
//      * try {
//      *     return connection.execute(command, argument1, argument2, ...);
//      * } finally {
//      *     connection.close();
//      * }
//      * </pre>
//      * <p>
//      * This method is thread safe.
//      * 
//      * @param command
//      *            the command to be executed
//      * @param arguments
//      *            arguments of the command.
//      * @return the output from GraphicsMagick as the result of executing the command
//      * @throws NullPointerException
//      *             when command is null
//      * @throws IOException
//      *             when GM encounter IO error executing the command
//      * @throws GMException
//      *             when GraphicsMagick returns non-IO error executing the command
//      * @throws GMServiceException
//      *             when there is error communicating with the underlying GraphicsMagick process
//      */
//     @Override
//     String execute(@Nonnull String command, String... arguments) throws IOException, GMException, GMServiceException;
// 
//     /**
//      * Executes the command using the underlying GraphicsMagick process. GraphicsMagick command and its arguments are
//      * passed in as a list of strings.
//      * <p>
//      * This is a convenient method to {@link #getConnection() get the connection}, {@link GMConnection#execute(List)
//      * execute} the command once and {@link GMConnection#close() close} it. It is functionally equivalent to code below,
//      * but actual implementation may optimize this for better efficiency.
//      * 
//      * <pre>
//      * final GMConnection connection = gmService.getConnection();
//      * try {
//      *     return connection.execute(command);
//      * } finally {
//      *     connection.close();
//      * }
//      * </pre>
//      * <p>
//      * This method is thread safe.
//      * 
//      * @param command
//      *            the command and arguments to be executed
//      * @return the output from GraphicsMagick as the result of executing the command
//      * @throws NullPointerException
//      *             when command is null
//      * @throws IllegalArgumentException
//      *             when command is an empty list.
//      * @throws IOException
//      *             when GM encounter IO error executing the command
//      * @throws GMException
//      *             when GraphicsMagick returns non-IO error executing the command
//      * @throws GMServiceException
//      *             when there is error communicating with the underlying GraphicsMagick process
//      * @see #execute(String, String...)
//      */
//     @Override
//     String execute(@Nonnull List<String> command) throws IOException, GMException, GMServiceException;
// 
//     /**
//      * Gets an instance of {@link GMConnection}. Depends on the implementation, the instance can be newly created or
//      * from a pool.
//      * <p>
//      * This method is thread safe.
//      * 
//      * @return an instance of {@linkplain GMConnection}
//      * @throws GMServiceException
//      *             when communicate error occurs between the physical GraphicsMagick process.
//      */
//     @Nonnull
//     GMConnection getConnection() throws GMServiceException;
// }
// 
// Path: src/main/java/org/gm4java/engine/GMServiceException.java
// public class GMServiceException extends Exception {
// 
//     private static final long serialVersionUID = 1L;
// 
//     /**
//      * Constructs a new exception with given message.
//      * 
//      * @param message
//      *            the detailed message of the exception.
//      */
//     public GMServiceException(String message) {
//         super(message);
//     }
// 
//     /**
//      * Constructs a new exception with given message and cause.
//      * 
//      * @param message
//      *            the detailed message of the exception.
//      * @param cause
//      *            the cause of the error.
//      */
//     public GMServiceException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
// }


// Path: src/main/java/org/gm4java/engine/support/PooledGMService.java
import org.gm4java.engine.GMConnection;
import org.gm4java.engine.GMException;
import org.gm4java.engine.GMService;
import org.gm4java.engine.GMServiceException;
import java.io.IOException;
import java.util.List;
import javax.annotation.Nonnull;

        } finally {
            pool.returnObject(connection);
        }
    }

    @Override
    public String execute(List<String> command) throws IOException, GMException, GMServiceException {
        PooledGMConnection connection = pool.borrowObject();
        try {
            return connection.execute(command);
        } finally {
            pool.returnObject(connection);
        }
    }

    /**
     * {@inheritDoc}
     * <p>
     * This implementation returns an instance from pool.
     */
    @Override
    @Nonnull
    public GMConnection getConnection() throws GMServiceException {
        return new ConnectionWrapper(pool);
    }

    void setProcessFactoryBuilder(GMProcessFactory.Builder builder) {
        pool.setProcessFactoryBuilder(builder);
    }

    private static final class ConnectionWrapper implements GMConnection {