public class PooledGMService extends Object implements GMService
GMService
that manages and uses a pool of GraphicsMagick instances. This implementation uses
GenericObjectPool
from Apache Commons
Pool project.Constructor and Description |
---|
PooledGMService(GMConnectionPoolConfig config)
Construct a new instance of PooledGMService with given pool configuration.
|
Modifier and Type | Method and Description |
---|---|
String |
execute(List<String> command)
Executes the command using the underlying GraphicsMagick process.
|
String |
execute(String command,
String... arguments)
Executes the GraphisMagick command and return the result.
|
GMConnection |
getConnection()
Gets an instance of
GMConnection . |
public PooledGMService(@Nonnull GMConnectionPoolConfig config)
config
- configuration of the GraphicsMagick process poolpublic String execute(@Nonnull String command, String... arguments) throws IOException, GMException, GMServiceException
This is a convenient method to get the connection
,
execute
the command once and close
it. It is functionally equivalent to code below, but actual implementation may optimize this for better
efficiency.
final GMConnection connection = gmService.getConnection(); try { return connection.execute(command, argument1, argument2, ...); } finally { connection.close(); }
This method is thread safe.
execute
in interface GMExecutor
execute
in interface GMService
command
- the command to be executedarguments
- arguments of the command.IOException
- when GM encounter IO error executing the commandGMException
- when GraphicsMagick returns non-IO error executing the commandGMServiceException
- when there is error communicating with the underlying GraphicsMagick processGMExecutor.execute(List)
public String execute(List<String> command) throws IOException, GMException, GMServiceException
GMService
This is a convenient method to get the connection
, execute
the command once and close
it. It is functionally equivalent to code below,
but actual implementation may optimize this for better efficiency.
final GMConnection connection = gmService.getConnection(); try { return connection.execute(command); } finally { connection.close(); }
This method is thread safe.
execute
in interface GMExecutor
execute
in interface GMService
command
- the command and arguments to be executedIOException
- when GM encounter IO error executing the commandGMException
- when GraphicsMagick returns non-IO error executing the commandGMServiceException
- when there is error communicating with the underlying GraphicsMagick processGMService.execute(String, String...)
@Nonnull public GMConnection getConnection() throws GMServiceException
GMConnection
. Depends on the implementation, the instance can be newly created or
from a pool.
This method is thread safe.
This implementation returns an instance from pool.
getConnection
in interface GMService
GMServiceException
- when communicate error occurs between the physical GraphicsMagick process.Copyright © 2013. All Rights Reserved.