Changeset 7413


Ignore:
Timestamp:
12/13/10 12:47:48 (9 years ago)
Author:
aivar
Message:

More documentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/maven/projects/deep-zoom-plugin/src/main/java/loci/multiinstanceplugin/PluginLauncher.java

    r7377 r7413  
     1// 
     2// PluginLauncher.java 
     3// 
     4 
    15/* 
    2  * To change this template, choose Tools | Templates 
    3  * and open the template in the editor. 
    4  */ 
     6Multiple instance chainable plugin framework. 
     7 
     8Copyright (c) 2010, UW-Madison LOCI 
     9All rights reserved. 
     10 
     11Redistribution and use in source and binary forms, with or without 
     12modification, are permitted provided that the following conditions are met: 
     13  * Redistributions of source code must retain the above copyright 
     14    notice, this list of conditions and the following disclaimer. 
     15  * Redistributions in binary form must reproduce the above copyright 
     16    notice, this list of conditions and the following disclaimer in the 
     17    documentation and/or other materials provided with the distribution. 
     18  * Neither the name of the UW-Madison LOCI nor the 
     19    names of its contributors may be used to endorse or promote products 
     20    derived from this software without specific prior written permission. 
     21 
     22THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
     23AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
     24IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
     25ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 
     26LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
     27CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
     28SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
     29INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
     30CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
     31ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
     32POSSIBILITY OF SUCH DAMAGE. 
     33*/ 
    534 
    635package loci.multiinstanceplugin; 
     
    1443 
    1544/** 
     45 * The PluginLauncher talks to the PluginScheduler and launches new instances of 
     46 * the plugin as needed. 
    1647 * 
    1748 * @author Aivar Grislis 
     
    2657    Map<String, String> m_outputNames = new HashMap(); 
    2758 
     59    /** 
     60     * Creates a launcher for a given class, that has the given input and 
     61     * output image name annotations. 
     62     * 
     63     * @param pluginClass 
     64     * @param annotations 
     65     */ 
    2866    public PluginLauncher(Class pluginClass, PluginAnnotations annotations) { 
    2967        m_pluginClass = pluginClass; 
     
    3472    } 
    3573 
     74    /** 
     75     * Chains this launcher to next one. 
     76     * 
     77     * @param outName 
     78     * @param next 
     79     * @param inName 
     80     */ 
    3681    public void chainNext(String outName, IPluginLauncher next, String inName) { 
    3782        PluginScheduler.getInstance().chain(this, outName, next, inName); 
    3883    } 
    39      
     84 
     85    /** 
     86     * Chains this launcher to previous one. 
     87     * 
     88     * @param inName 
     89     * @param previous 
     90     * @param outName 
     91     */ 
    4092    public void chainPrevious(String inName, IPluginLauncher previous, String outName) { 
    4193        PluginScheduler.getInstance().chain(previous, outName, this, inName); 
    4294    } 
    4395 
     96    /** 
     97     * Initiates a plugin chain by feeding a named image to this launcher's plugin. 
     98     * 
     99     * @param name 
     100     * @param image 
     101     */ 
    44102    public void externalPut(String name, ImageWrapper image) { 
    45103        String fullInName = uniqueName(name); 
     
    47105    } 
    48106 
     107    /** 
     108     * Generates a unique input image name for this launcher. 
     109     * 
     110     * @param name 
     111     * @return 
     112     */ 
    49113    public String uniqueName(String name) { 
    50114        return m_id.toString() + '-' + name; 
    51115    } 
    52116 
     117    /** 
     118     * Associates a unique input image name for some other launcher to our 
     119     * output image name. 
     120     * 
     121     * @param outName 
     122     * @param fullInName 
     123     */ 
    53124    public void associate(String outName, String fullInName) { 
    54125        m_outputNames.put(outName, fullInName); 
    55126    } 
    56127 
     128    /** 
     129     * Quits processing the chain. 
     130     */ 
    57131    public void quit() { 
    58132        m_quit = true; 
    59133    } 
    60134 
     135    /** 
     136     * Processing thread for launcher.  Waits for a complete set of input 
     137     * images, then spawns a thread with a new instance of the plugin to 
     138     * process them. 
     139     */ 
    61140    private class LauncherThread extends Thread { 
     141 
     142        @Override 
    62143        public void run() { 
    63144            Set<String> inputNames = m_annotations.getInputNames(); 
     
    78159                pluginThread.start(); 
    79160 
    80                 if (s_singleInstance) { 
     161                // Only run one plugin instance at a time? 
     162                if (s_singleInstance) { //TODO implemented in a quick & dirty way 
     163                    // wait for plugin to finish 
     164                    // (Note: this is all a kludge for now:  you might as well just run the plugin 
     165                    //  on this launcher thread.) 
    81166                    try { 
    82167                        pluginThread.join(); 
     
    90175    } 
    91176 
     177    /** 
     178     * Processing thread for a plugin instance.  Instantiates and runs the plugin. 
     179     */ 
    92180    private class PluginThread extends Thread { 
    93181        Map<String, ImageWrapper> m_inputImages; 
     
    101189            } 
    102190            catch (InstantiationException e) { 
    103                 System.out.println("m_pluginClass " + m_pluginClass); 
    104191                System.out.println("Problem instantiating plugin " + m_pluginClass.getSimpleName() + ' ' + e.getMessage()); 
    105192            } 
     
    109196        } 
    110197 
     198        @Override 
    111199        public void run() { 
    112200            if (null != m_pluginInstance) { 
Note: See TracChangeset for help on using the changeset viewer.