The im4java Library, Version 1.4.0

org.im4java.utils
Class BatchConverter

java.lang.Object
  extended by java.util.concurrent.AbstractExecutorService
      extended by java.util.concurrent.ThreadPoolExecutor
          extended by org.im4java.process.ProcessExecutor
              extended by org.im4java.utils.BatchConverter
All Implemented Interfaces:
java.util.concurrent.Executor, java.util.concurrent.ExecutorService, ProcessEventListener

public class BatchConverter
extends ProcessExecutor

This class implements various batch-conversion methods.

Note that not every mode will work with every operation. The batch-mode will typically fail with all operations using ImageMagick's image-sequence operators (e.g. -clone).

Sequential and parallel-mode will convert all images and will save the indices of failed conversions. You can query these indices with the method getFailedConversions(). The batch mode behaves differently: it is a all-or-nothing conversion.

Since:
1.1.0
Version:
$Revision: 1.8 $
Author:
$Author: bablokb $

Nested Class Summary
 class BatchConverter.ConvertException
          This nested exception wraps the original exception of failed conversions.
static class BatchConverter.Mode
          Enumeration-type for the conversion mode: SEQUENTIAL: run commands sequentially for all images (this mode is mainly for debugging and benchmarking) PARALLEL: run commands in parallel using a ProcessExecutor BATCH: convert images at once with a single command.
 
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
 
Constructor Summary
BatchConverter(BatchConverter.Mode pMode)
          The constructor.
 
Method Summary
 java.util.List<BatchConverter.ConvertException> getFailedConversions()
          Return the list of exceptions.
 BatchConverter.Mode getMode()
          Return the current run-mode
 void processTerminated(ProcessEvent pEvent)
          This method is called at normal or abnormal process termination.
 void run(Operation pOp, java.util.List<java.lang.String> pImages, java.lang.String pTargetPattern)
          Convert the given images with the given Operation.
 
Methods inherited from class org.im4java.process.ProcessExecutor
afterExecute, beforeExecute, destroy, processInitiated, processStarted, shutdownNow
 
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, terminated
 
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchConverter

public BatchConverter(BatchConverter.Mode pMode)
The constructor.

Parameters:
pMode - The conversion mode of this BatchConverter
Method Detail

run

public void run(Operation pOp,
                java.util.List<java.lang.String> pImages,
                java.lang.String pTargetPattern)
         throws java.lang.Exception,
                java.io.IOException,
                java.lang.InterruptedException,
                IM4JavaException
Convert the given images with the given Operation.

Parameters:
pOp - the conversion-operation
pImages - List of images to convert
pTargetPattern - Pattern for the target-files. See FilenamePatternResolver for details
Throws:
java.lang.Exception
java.io.IOException
java.lang.InterruptedException
IM4JavaException

processTerminated

public void processTerminated(ProcessEvent pEvent)
This method is called at normal or abnormal process termination. This method is called at normal or abnormal process termination. In case of error, we will save the PID of the process (in our case, the PID is the index of the image causing the problem).

Specified by:
processTerminated in interface ProcessEventListener
Overrides:
processTerminated in class ProcessExecutor

getFailedConversions

public java.util.List<BatchConverter.ConvertException> getFailedConversions()
Return the list of exceptions.

Returns:
the list of exceptions (might be null)

getMode

public BatchConverter.Mode getMode()
Return the current run-mode

Returns:
the run-mode

The im4java Library, Version 1.4.0

Released under the LGPL, (c) Bernhard Bablok 2008-2010
Homepage: http://im4java.sourceforge.net/