|
From: <dgl...@us...> - 2003-08-10 18:01:18
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/processor In directory sc8-pr-cvs1:/tmp/cvs-serv13403/modules/core/src/com/babeldoc/core/pipeline/processor Modified Files: SyncPipelineStageProcessor.java Log Message: Show ticket id after completed processing pipeline Index: SyncPipelineStageProcessor.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/processor/SyncPipelineStageProcessor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SyncPipelineStageProcessor.java 8 Aug 2003 23:43:11 -0000 1.2 --- SyncPipelineStageProcessor.java 10 Aug 2003 18:01:15 -0000 1.3 *************** *** 1,320 **** ! /* ==================================================================== ! * The Apache Software License, Version 1.1 ! * ! * Copyright (c) 2000 The Apache Software Foundation. All rights ! * reserved. ! * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted provided that the following conditions ! * are met: ! * ! * 1. Redistributions of source code must retain the above copyright ! * notice, this list of conditions and the following disclaimer. ! * ! * 2. Redistributions in binary form must reproduce the above copyright ! * notice, this list of conditions and the following disclaimer in ! * the documentation and/or other materials provided with the ! * distribution. ! * ! * 3. The end-user documentation included with the redistribution, ! * if any, must include the following acknowledgment: ! * "This product includes software developed by the ! * Apache Software Foundation (http://www.apache.org/)." ! * Alternately, this acknowledgment may appear in the software itself, ! * if and wherever such third-party acknowledgments normally appear. ! * ! * 4. The names "Apache" and "Apache Software Foundation" must ! * not be used to endorse or promote products derived from this ! * software without prior written permission. For written ! * permission, please contact ap...@ap.... ! * ! * 5. Products derived from this software may not be called "Apache", ! * nor may "Apache" appear in their name, without prior written ! * permission of the Apache Software Foundation. ! * ! * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ! * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ! * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ! * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ! * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ! * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ! * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ! * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ! * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! * SUCH DAMAGE. ! * ==================================================================== ! * ! * This software consists of voluntary contributions made by many ! * individuals on behalf of the Apache Software Foundation. For more ! * information on the Apache Software Foundation, please see ! * <http://www.apache.org/>. ! * ! * Portions of this software are based upon public domain software ! * originally written at the National Center for Supercomputing Applications, ! * University of Illinois, Urbana-Champaign. ! * ==================================================================== ! * ! * Babeldoc: The Universal Document Processor ! * ! * $Header$ ! * $DateTime$ ! * $Author$ ! * ! */ ! package com.babeldoc.core.pipeline.processor; ! ! import com.babeldoc.core.pipeline.*; ! import com.babeldoc.core.journal.IJournalTicket; ! import com.babeldoc.core.journal.JournalFactory; ! import com.babeldoc.core.journal.JournalException; ! import com.babeldoc.core.I18n; ! import com.babeldoc.core.LogService; ! import com.babeldoc.core.option.IConfigInfo; ! ! import java.util.*; ! ! /** ! * The default pipline stage processor executes ***EVERYTHING*** serialially. ! * This is of concern when a pipeline returns a number of results. Most of this ! * code used to live in the pipeline stage factory. ! */ ! public class SyncPipelineStageProcessor ! implements IPipelineStageProcessor { ! ! private IPipelineStageFactory stageFactory; ! ! // this is put in a ThreadLocal, since with Threads the same stage can be called by several Threads at once ! private ThreadLocal localStages = new ThreadLocal() { ! protected synchronized Object initialValue() { ! LogService.getInstance().logDebug(I18n.get("019005", "new")); ! return new HashMap(); ! } ! }; ! ! ! /** ! * Get the "owning" pipeline stage factory. ! * ! * @return ! */ ! public IPipelineStageFactory getStageFactory() { ! return stageFactory; ! } ! ! /** ! * Returns the pipeline stage type for this particular pipeline ! * ! * @param stageName ! * ! * @return ! * ! * @throws PipelineException ! */ ! public PipelineStageType getPipelineStageType(String stageName) ! throws PipelineException { ! return getStageFactory().getResolver().getPipelineStageType(stageName); ! } ! ! /** ! * Get and instantiate the named pipeline stage. ! * ! * @param stageName the unique name of the stage ! * ! * @return a reference to the pipeline stage ! * ! * @throws PipelineException DOCUMENT ME! ! */ ! public IPipelineStage getPipelineStage(String stageName) ! throws PipelineException { ! Map stages = (Map)localStages.get(); ! ! if (!stages.containsKey(stageName)) { ! LogService.getInstance().logDebug(I18n.get("019005", stageName)); ! ! try { ! PipelineStageType pipelineStageType = getPipelineStageType(stageName); ! Class stage = pipelineStageType.getTypeClass(); ! ! if (stage != null) { ! IPipelineStage pstage = (IPipelineStage) (stage.newInstance()); ! pstage.setName(stageName); ! pstage.setResolver(getStageFactory().getResolver()); ! pstage.setPipelineName(getStageFactory().getName()); ! stages.put(stageName, pstage); ! } else { ! throw new PipelineException(I18n.get("019010", ! pipelineStageType.getTypeName())); ! } ! } catch (InstantiationException ie) { ! throw new PipelineException(ie.getMessage(), ie); ! } catch (IllegalAccessException iae) { ! throw new PipelineException(iae.getMessage(), iae); ! } ! } ! ! return (IPipelineStage) stages.get(stageName); ! } ! ! ! /** ! * Process documents - this is the entry point for pipeline processing. If ! * the name of the next stage is not null, then process normally, otherwise ! * add them to the finalResults collection if the finalResults collection is not null. ! * ! * @param name of the next stage ! * @param document to process ! * @param ticket the tracker ticket ! * @param finalResults the resulting processed documents after all processing is completed ! * ! * @throws com.babeldoc.core.pipeline.PipelineException DOCUMENT ME! ! */ ! public void process(String name, PipelineDocument document, ! IJournalTicket ticket, Collection finalResults) throws PipelineException { ! if ((name != null) && !name.equals("null") && (document != null)) { ! LogService.getInstance().logInfo(I18n.get("019008", name)); ! ! // Get the pipeline stage for this name ! IPipelineStage pstage = getPipelineStage(name); ! ! if (pstage != null) { ! try { ! pstage.initialize(); ! } catch (Exception e) { ! throw new PipelineException("Exception while initializing", e); ! } ! pstage.setDocument(document); ! pstage.setTicket(ticket); ! trackDocument(pstage); ! ! processPipelineStage(pstage, finalResults); ! } else { ! LogService.getInstance().logError(I18n.get("019008", name), null); ! } ! } else { ! if (finalResults != null) { ! finalResults.add(new PipelineStageResult(null, document, ticket)); ! } ! } ! } ! ! /** ! * This method is call prior to any processing - it is a necessary configuration ! * prequisite. ! * ! * @param stageFactory set the associated stage factory for this processor ! */ ! public void configure(IPipelineStageFactory stageFactory, Map config) { ! this.stageFactory = stageFactory; ! } ! ! /** ! * Process the pipeline stage and then defer to eithe the multithreaded or single threaded ! * implementation - this needs to be extracted. ! * ! * @param pstage The pipeline stage to process ! * @param finalResults collection of documents after all processing is completed. ! * @throws com.babeldoc.core.pipeline.PipelineException ! */ ! protected void processPipelineStage(IPipelineStage pstage, Collection finalResults) ! throws PipelineException { ! ! // Process the pipeline stage, get the results of the processing ! PipelineStageResult [] psResults = pstage.processStage(); ! ! if(psResults!=null && psResults.length>0) { ! processPipelineStageResults(psResults, finalResults); ! } ! } ! ! /** ! * Process the pipeline stage finalResults. The gets called from process and ! * handles the finalResults from the processing. ! * ! * @param psResults The results of running the current stage on this document ! * @param finalResults Collection of documents after all processing done (after null) ! * ! * @throws com.babeldoc.core.pipeline.PipelineException ! */ ! protected void processPipelineStageResults(PipelineStageResult[] psResults, ! Collection finalResults) throws PipelineException { ! ! int numResults = psResults.length; ! for (int i = 0; i < numResults; ++i) { ! processPipelineStageResult(psResults[i], finalResults); ! } ! } ! ! /** ! * Process a single PipelineStageResult. ! * ! * @param psResult The pipeline stage result to process ! * @param finalResults the collection of processed documents. ! * @throws com.babeldoc.core.pipeline.PipelineException ! */ ! protected void processPipelineStageResult(PipelineStageResult psResult, Collection finalResults) ! throws PipelineException { ! String name = psResult.getNamePipelineStage(); ! PipelineDocument document = psResult.getDocument(); ! IJournalTicket ticket = psResult.getTicket(); ! ! this.process(name, document, ticket, finalResults); ! } ! ! /** ! * Track the document on the pipeline stage ! * ! * @param pstage ! * ! * @throws PipelineException DOCUMENT ME! ! */ ! protected void trackDocument(IPipelineStage pstage) ! throws PipelineException { ! if (pstage.isTracked()) { ! try { ! JournalFactory.getJournal().updateDocument(pstage.getTicket(), ! pstage.getDocument(), getStageFactory().getName() + "." + pstage.getName()); ! } catch (JournalException e) { ! LogService.getInstance().logError(e); ! throw new PipelineException(e.getMessage(), e); ! } ! } ! } ! ! /** ! * Get the configuration information for this processor ! * ! * @return IConfigInfo object ! */ ! public IConfigInfo getInfo() { ! return new ProcessorConfigInfo() { ! /** ! * This method returns type specific options ! * ! * @return comments ! */ ! public Collection getTypeSpecificOptions() { ! return new ArrayList(); ! } ! ! /** ! * Return description of this worker ! * ! * @return description ! */ ! public String getDescription() { ! return I18n.get("core.pipeline.processor.sync.desc"); ! } ! ! /** ! * return the name ! * ! * @return ! */ ! public String getName() { ! return "sync"; ! } ! }; ! } ! } --- 1,321 ---- ! /* ==================================================================== ! * The Apache Software License, Version 1.1 ! * ! * Copyright (c) 2000 The Apache Software Foundation. All rights ! * reserved. ! * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted provided that the following conditions ! * are met: ! * ! * 1. Redistributions of source code must retain the above copyright ! * notice, this list of conditions and the following disclaimer. ! * ! * 2. Redistributions in binary form must reproduce the above copyright ! * notice, this list of conditions and the following disclaimer in ! * the documentation and/or other materials provided with the ! * distribution. ! * ! * 3. The end-user documentation included with the redistribution, ! * if any, must include the following acknowledgment: ! * "This product includes software developed by the ! * Apache Software Foundation (http://www.apache.org/)." ! * Alternately, this acknowledgment may appear in the software itself, ! * if and wherever such third-party acknowledgments normally appear. ! * ! * 4. The names "Apache" and "Apache Software Foundation" must ! * not be used to endorse or promote products derived from this ! * software without prior written permission. For written ! * permission, please contact ap...@ap.... ! * ! * 5. Products derived from this software may not be called "Apache", ! * nor may "Apache" appear in their name, without prior written ! * permission of the Apache Software Foundation. ! * ! * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ! * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ! * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ! * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ! * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ! * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ! * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ! * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ! * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! * SUCH DAMAGE. ! * ==================================================================== ! * ! * This software consists of voluntary contributions made by many ! * individuals on behalf of the Apache Software Foundation. For more ! * information on the Apache Software Foundation, please see ! * <http://www.apache.org/>. ! * ! * Portions of this software are based upon public domain software ! * originally written at the National Center for Supercomputing Applications, ! * University of Illinois, Urbana-Champaign. ! * ==================================================================== ! * ! * Babeldoc: The Universal Document Processor ! * ! * $Header$ ! * $DateTime$ ! * $Author$ ! * ! */ ! package com.babeldoc.core.pipeline.processor; ! ! import com.babeldoc.core.pipeline.*; ! import com.babeldoc.core.journal.IJournalTicket; ! import com.babeldoc.core.journal.JournalFactory; ! import com.babeldoc.core.journal.JournalException; ! import com.babeldoc.core.I18n; ! import com.babeldoc.core.LogService; ! import com.babeldoc.core.option.IConfigInfo; ! ! import java.util.*; ! ! /** ! * The default pipline stage processor executes ***EVERYTHING*** serialially. ! * This is of concern when a pipeline returns a number of results. Most of this ! * code used to live in the pipeline stage factory. ! */ ! public class SyncPipelineStageProcessor ! implements IPipelineStageProcessor { ! ! private IPipelineStageFactory stageFactory; ! ! // this is put in a ThreadLocal, since with Threads the same stage can be called by several Threads at once ! private ThreadLocal localStages = new ThreadLocal() { ! protected synchronized Object initialValue() { ! LogService.getInstance().logDebug(I18n.get("019005", "new")); ! return new HashMap(); ! } ! }; ! ! ! /** ! * Get the "owning" pipeline stage factory. ! * ! * @return ! */ ! public IPipelineStageFactory getStageFactory() { ! return stageFactory; ! } ! ! /** ! * Returns the pipeline stage type for this particular pipeline ! * ! * @param stageName ! * ! * @return ! * ! * @throws PipelineException ! */ ! public PipelineStageType getPipelineStageType(String stageName) ! throws PipelineException { ! return getStageFactory().getResolver().getPipelineStageType(stageName); ! } ! ! /** ! * Get and instantiate the named pipeline stage. ! * ! * @param stageName the unique name of the stage ! * ! * @return a reference to the pipeline stage ! * ! * @throws PipelineException DOCUMENT ME! ! */ ! public IPipelineStage getPipelineStage(String stageName) ! throws PipelineException { ! Map stages = (Map)localStages.get(); ! ! if (!stages.containsKey(stageName)) { ! LogService.getInstance().logDebug(I18n.get("019005", stageName)); ! ! try { ! PipelineStageType pipelineStageType = getPipelineStageType(stageName); ! Class stage = pipelineStageType.getTypeClass(); ! ! if (stage != null) { ! IPipelineStage pstage = (IPipelineStage) (stage.newInstance()); ! pstage.setName(stageName); ! pstage.setResolver(getStageFactory().getResolver()); ! pstage.setPipelineName(getStageFactory().getName()); ! stages.put(stageName, pstage); ! } else { ! throw new PipelineException(I18n.get("019010", ! pipelineStageType.getTypeName())); ! } ! } catch (InstantiationException ie) { ! throw new PipelineException(ie.getMessage(), ie); ! } catch (IllegalAccessException iae) { ! throw new PipelineException(iae.getMessage(), iae); ! } ! } ! ! return (IPipelineStage) stages.get(stageName); ! } ! ! ! /** ! * Process documents - this is the entry point for pipeline processing. If ! * the name of the next stage is not null, then process normally, otherwise ! * add them to the finalResults collection if the finalResults collection is not null. ! * ! * @param name of the next stage ! * @param document to process ! * @param ticket the tracker ticket ! * @param finalResults the resulting processed documents after all processing is completed ! * ! * @throws com.babeldoc.core.pipeline.PipelineException DOCUMENT ME! ! */ ! public void process(String name, PipelineDocument document, ! IJournalTicket ticket, Collection finalResults) throws PipelineException { ! if ((name != null) && !name.equals("null") && (document != null)) { ! LogService.getInstance().logInfo(I18n.get("019008", name)); ! ! // Get the pipeline stage for this name ! IPipelineStage pstage = getPipelineStage(name); ! ! if (pstage != null) { ! try { ! pstage.initialize(); ! } catch (Exception e) { ! throw new PipelineException("Exception while initializing", e); ! } ! pstage.setDocument(document); ! pstage.setTicket(ticket); ! trackDocument(pstage); ! ! processPipelineStage(pstage, finalResults); ! } else { ! LogService.getInstance().logError(I18n.get("019008", name), null); ! } ! } else { ! LogService.getInstance().logInfo(I18n.get("019013", ticket.getId())); ! if (finalResults != null) { ! finalResults.add(new PipelineStageResult(null, document, ticket)); ! } ! } ! } ! ! /** ! * This method is call prior to any processing - it is a necessary configuration ! * prequisite. ! * ! * @param stageFactory set the associated stage factory for this processor ! */ ! public void configure(IPipelineStageFactory stageFactory, Map config) { ! this.stageFactory = stageFactory; ! } ! ! /** ! * Process the pipeline stage and then defer to eithe the multithreaded or single threaded ! * implementation - this needs to be extracted. ! * ! * @param pstage The pipeline stage to process ! * @param finalResults collection of documents after all processing is completed. ! * @throws com.babeldoc.core.pipeline.PipelineException ! */ ! protected void processPipelineStage(IPipelineStage pstage, Collection finalResults) ! throws PipelineException { ! ! // Process the pipeline stage, get the results of the processing ! PipelineStageResult [] psResults = pstage.processStage(); ! ! if(psResults!=null && psResults.length>0) { ! processPipelineStageResults(psResults, finalResults); ! } ! } ! ! /** ! * Process the pipeline stage finalResults. The gets called from process and ! * handles the finalResults from the processing. ! * ! * @param psResults The results of running the current stage on this document ! * @param finalResults Collection of documents after all processing done (after null) ! * ! * @throws com.babeldoc.core.pipeline.PipelineException ! */ ! protected void processPipelineStageResults(PipelineStageResult[] psResults, ! Collection finalResults) throws PipelineException { ! ! int numResults = psResults.length; ! for (int i = 0; i < numResults; ++i) { ! processPipelineStageResult(psResults[i], finalResults); ! } ! } ! ! /** ! * Process a single PipelineStageResult. ! * ! * @param psResult The pipeline stage result to process ! * @param finalResults the collection of processed documents. ! * @throws com.babeldoc.core.pipeline.PipelineException ! */ ! protected void processPipelineStageResult(PipelineStageResult psResult, Collection finalResults) ! throws PipelineException { ! String name = psResult.getNamePipelineStage(); ! PipelineDocument document = psResult.getDocument(); ! IJournalTicket ticket = psResult.getTicket(); ! ! this.process(name, document, ticket, finalResults); ! } ! ! /** ! * Track the document on the pipeline stage ! * ! * @param pstage ! * ! * @throws PipelineException DOCUMENT ME! ! */ ! protected void trackDocument(IPipelineStage pstage) ! throws PipelineException { ! if (pstage.isTracked()) { ! try { ! JournalFactory.getJournal().updateDocument(pstage.getTicket(), ! pstage.getDocument(), getStageFactory().getName() + "." + pstage.getName()); ! } catch (JournalException e) { ! LogService.getInstance().logError(e); ! throw new PipelineException(e.getMessage(), e); ! } ! } ! } ! ! /** ! * Get the configuration information for this processor ! * ! * @return IConfigInfo object ! */ ! public IConfigInfo getInfo() { ! return new ProcessorConfigInfo() { ! /** ! * This method returns type specific options ! * ! * @return comments ! */ ! public Collection getTypeSpecificOptions() { ! return new ArrayList(); ! } ! ! /** ! * Return description of this worker ! * ! * @return description ! */ ! public String getDescription() { ! return I18n.get("core.pipeline.processor.sync.desc"); ! } ! ! /** ! * return the name ! * ! * @return ! */ ! public String getName() { ! return "sync"; ! } ! }; ! } ! } |