@PublicAPI public class ConcurrentReactorProcessor extends java.lang.Object
See the documentation for details.
An example usage of the API:
MolExporter exporter = new MolExporter(System.out, "smiles"); Molecule rxnmol = new MolImporter("reaction.rxn").read(); MolImporter[] importers = new MolImporter[] { new MolImporter("reactants1.smiles"), new MolImporter("reactants2.smiles") }; // create Reactor Reactor reactor = new Reactor(); // set reactor properties reactor.setIgnoreRules(Reactor.IGNORE_REACTIVITY | Reactor.IGNORE_SELECTIVITY); // set the reaction ('rxnmol' is the reaction molecule) // reaction rules are read from RDF/MRV tags reactor.setReaction(rxnmol); // create ConcurrentReactorProcessor ConcurrentReactorProcessor crp = new ConcurrentReactorProcessor(); // set the reactor for ConcurrentReactorProcessor crp.setReactor(reactor); // set the reactant iterators and the processing mode for ConcurrentReactorProcessor crp.setReactantIterators(MoleculeIteratorFactory.getMoleculeIterators(importers), ConcurrentReactorProcessor.MODE_COMBINATORIAL); // react the reactants and export the output (reactions are performed in concurrent mode) Molecule[] products; while ((products = crp.react()) != null) { for (Molecule product : products) { exporter.write(product); } }
Modifier and Type | Field and Description |
---|---|
static int |
MODE_COMBINATORIAL
Mode constant: combinatorial mode.
|
static int |
MODE_SEQUENTIAL
Mode constant: sequential mode.
|
Constructor and Description |
---|
ConcurrentReactorProcessor() |
Modifier and Type | Method and Description |
---|---|
void |
cleanup(long joinTimeout)
Cancels work currently executed, awaits termination of associated
worker threads and releases any resource this processor has reserved.
|
double |
getProgress()
Estimates the progress.
|
Molecule[] |
getReactants()
Returns the input reactants of the last processed reaction.
|
void |
initialize()
For internal use only.
|
static void |
main(java.lang.String[] args)
Command line entry point.
|
Molecule[] |
react()
Generates the product list(s) for all reactant sets.
|
java.util.List<Molecule[]> |
reactNext()
Reacts the next reactant set and returns all product sets in a list.
|
void |
setReactantIterators(MoleculeIterator[] reactantIterators,
int mode)
Sets the reactant iterators.
|
void |
setReactantIterators(MoleculeIterator[] reactantIterators,
int mode,
java.lang.String cacheFormat,
double reservedMemorySize,
boolean ignoreError)
Sets the reactant iterators.
|
void |
setReactantSetEnumerator(ReactantSetEnumeration e)
Sets the reactant set enumerator.
|
void |
setReactor(Reactor reactor)
Sets the Reactor object that will be used for reaction processing.
|
void |
setWorkerThreadCount(int workerThreadCount)
Sets the number of worker threads.
|
public static final int MODE_SEQUENTIAL
public static final int MODE_COMBINATORIAL
public void setReactor(Reactor reactor)
reactor
- is the reactor objectpublic void setReactantIterators(MoleculeIterator[] reactantIterators, int mode) throws ReactionException, java.io.IOException
mode
parameter.reactantIterators
- is the MoleculeIterator array from which the input molecules are readmode
- is the enumeration mode: MODE_SEQUENTIAL
or MODE_COMBINATORIAL
ReactionException
- if read error occurredjava.io.IOException
- in case of I/O errorpublic void setReactantIterators(MoleculeIterator[] reactantIterators, int mode, java.lang.String cacheFormat, double reservedMemorySize, boolean ignoreError) throws ReactionException, java.io.IOException
mode
parameter.reactantIterators
- is the MoleculeIterator array from which the input molecules are readmode
- is the enumeration mode: MODE_SEQUENTIAL
or MODE_COMBINATORIAL
cacheFormat
- the format for storing molecules in cachereservedMemorySize
- the memory size in MB that should be reservedignoreError
- is true
if import errors should be ignoredReactionException
- if read error occurredjava.io.IOException
- in case of I/O errorpublic void setReactantSetEnumerator(ReactantSetEnumeration e)
Molecule
[] returned be ReactantSetEnumeration.next()
will be used as
input reactant array for Reactor.e
- is the reactant enumerator which enumerates the input reactantsReactor.setReactants(Molecule[])
public void initialize() throws ReactionException
ReactionException
- on reaction processing errorpublic Molecule[] react() throws ReactionException
Reactor.react()
method for all reactant
sets
and returns the next product list, or null
if there are no more product lists.
The reactor and the reactant iterators or the reactant set enumerator should be set beforehand.
ReactionException
- on reaction processing errorgetReactants()
public java.util.List<Molecule[]> reactNext() throws ReactionException
null
is returned if there are no more reactant sets to process.ReactionException
- on reaction processing errorgetReactants()
public Molecule[] getReactants()
react()
or
reactNext()
.public void setWorkerThreadCount(int workerThreadCount)
0
: worker thread count = number of available CPU cores
0
)workerThreadCount
- number of worker threadspublic double getProgress()
0
and 1
, or returns -1
.
0
: none of the input molecules are processed,
1
: all of the input molecules are processed,
-1
: information about progress can not be provided.public void cleanup(long joinTimeout) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
joinTimeout
- specifies in milliseconds at most how long this method is
allowed to await the termination of each the worker threads.
'0' means don't wait at all. This parameter is relevant when
the worker threads have been cancelled as a result of the
processor having been cancelled either explicitly by the user
or internally reacting on an execution error.java.lang.InterruptedException
- if the current thread has been interrupted.java.util.concurrent.ExecutionException
- if any of the worker threads encountered an error during
execution.java.util.concurrent.TimeoutException
public static void main(java.lang.String[] args) throws java.lang.Exception
args
- is the command line argument arrayjava.lang.Exception
- in the case of error