## org.opencyc.util
Class CycWorker

    java.lang.Object
      |
      +--org.opencyc.util.SwingWorker
            |
            +--org.opencyc.util.CycWorker

public abstract class CycWorker
extends SwingWorker

This is a convenient event callback wrapper around the the SwingWorker class. It's inteded to allow easily running tasks in the background. Users of this class will be notified when the worker is started, interrupted or finished with its work. If finished, the rusults of the work will be made available as well.

Here is some example code:

``

       public static CycWorker evalSubLInBackground(CycAccess conn,
                                                    String subl,
                                                    CycWorkerListener cwl) {
           CycWorker worker = new CycWorker() {
               //The return val of construct() method is considered to be
               //the output for this worker and retrieved with
               //worker.getWork().
               public Object construct() {
                   return evalSubL(conn, subl); //Do work here.
               }
           };
           if(cwl != null) { worker.addListener(cwl); }
           worker.start();
           return worker;
       }

       public class GKETermDialog implements CycWorkerListener {

          private CycWorker specWorker = null;

    	public void notifyWorkerStarted(CycWorkerEvent evt) {}

    	public void notifyWorkerInterrupted(CycWorkerEvent evt) {}

    	public void notifyWorkerFinished(CycWorkerEvent evt) {
    	    CycWorker worker = (CycWorker)evt.getSource();
    	    System.out.println("WORKER FINISHED: " + worker);
    	    System.out.println("WORKER OUTPUT: " + worker.getWork());
    	}
       }
     </PLAINTEXT></CODE>
     <p>
     THIS SOFTWARE AND KNOWLEDGE BASE CONTENT ARE 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 OPENCYC
     ORGANIZATION 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 AND KNOWLEDGE
     BASE CONTENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    <P>
    <DL>
    <DT><B>Author: </B><DD>tbrussea</DD>
    <DT><B>See Also: </B><DD><A HREF="../../../org/opencyc/util/CycWorkerListener.html"><CODE>CycWorkerListener</CODE></A>,
    <A HREF="../../../org/opencyc/util/CycWorkerEvent.html"><CODE>CycWorkerEvent</CODE></A>,
    <A HREF="../../../org/opencyc/util/SwingWorker.html"><CODE>SwingWorker</CODE></A></DL>
    <HR>

    <P>
    <!-- ======== INNER CLASS SUMMARY ======== -->

    <A NAME="inner_classes_inherited_from_class_org.opencyc.util.SwingWorker"><!-- --></A>
    <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
    <TD><B>Inner classes inherited from class org.opencyc.util.<A HREF="../../../org/opencyc/util/SwingWorker.html">SwingWorker</A></B></TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD><CODE><A HREF="../../../org/opencyc/util/SwingWorker.ThreadVar.html">SwingWorker.ThreadVar</A></CODE></TD>
    </TR>
    </TABLE>
    &nbsp;
    <!-- =========== FIELD SUMMARY =========== -->

    <A NAME="fields_inherited_from_class_org.opencyc.util.SwingWorker"><!-- --></A>
    <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
    <TD><B>Fields inherited from class org.opencyc.util.<A HREF="../../../org/opencyc/util/SwingWorker.html">SwingWorker</A></B></TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD><CODE><A HREF="../../../org/opencyc/util/SwingWorker.html#threadVar">threadVar</A></CODE></TD>
    </TR>
    </TABLE>
    &nbsp;
    <!-- ======== CONSTRUCTOR SUMMARY ======== -->

    <A NAME="constructor_summary"><!-- --></A>
    <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
    <TD COLSPAN=2><FONT SIZE="+2">
    <B>Constructor Summary</B></FONT></TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD><CODE><B><A HREF="../../../org/opencyc/util/CycWorker.html#CycWorker()">CycWorker</A></B>()</CODE>

    <BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creates a new instance of CycWorker</TD>
    </TR>
    </TABLE>
    &nbsp;
    <!-- ========== METHOD SUMMARY =========== -->

    <A NAME="method_summary"><!-- --></A>
    <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
    <TD COLSPAN=2><FONT SIZE="+2">
    <B>Method Summary</B></FONT></TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
    <CODE>&nbsp;void</CODE></FONT></TD>
    <TD><CODE><B><A HREF="../../../org/opencyc/util/CycWorker.html#addListener(org.opencyc.util.CycWorkerListener)">addListener</A></B>(<A HREF="../../../org/opencyc/util/CycWorkerListener.html">CycWorkerListener</A>&nbsp;cwl)</CODE>

    <BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Adds a new worker listener to this worker.</TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
    <CODE>&nbsp;void</CODE></FONT></TD>
    <TD><CODE><B><A HREF="../../../org/opencyc/util/CycWorker.html#finished()">finished</A></B>()</CODE>

    <BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This method should be called internally only...public for
     Java related reasons only.</TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
    <CODE>&nbsp;java.lang.Object[]</CODE></FONT></TD>
    <TD><CODE><B><A HREF="../../../org/opencyc/util/CycWorker.html#getListeners()">getListeners</A></B>()</CODE>

    <BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Return a list of all CycWorkerListeners listening to
     this CycWorker.</TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
    <CODE>&nbsp;java.lang.Object</CODE></FONT></TD>
    <TD><CODE><B><A HREF="../../../org/opencyc/util/CycWorker.html#getWork()">getWork</A></B>()</CODE>

    <BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exposed the get() method from SwingWorker class.</TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
    <CODE>&nbsp;void</CODE></FONT></TD>
    <TD><CODE><B><A HREF="../../../org/opencyc/util/CycWorker.html#interrupt()">interrupt</A></B>()</CODE>

    <BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This method interrupts a currently running CycWorker.</TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
    <CODE>&nbsp;void</CODE></FONT></TD>
    <TD><CODE><B><A HREF="../../../org/opencyc/util/CycWorker.html#removeListener(org.opencyc.util.CycWorkerListener)">removeListener</A></B>(<A HREF="../../../org/opencyc/util/CycWorkerListener.html">CycWorkerListener</A>&nbsp;cwl)</CODE>

    <BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Removes a worker listener from this worker.</TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
    <CODE>&nbsp;void</CODE></FONT></TD>
    <TD><CODE><B><A HREF="../../../org/opencyc/util/CycWorker.html#start()">start</A></B>()</CODE>

    <BR>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This method starts the backround processing of a particular
     CycWorker.</TD>
    </TR>
    </TABLE>
    &nbsp;<A NAME="methods_inherited_from_class_org.opencyc.util.SwingWorker"><!-- --></A>
    <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
    <TD><B>Methods inherited from class org.opencyc.util.<A HREF="../../../org/opencyc/util/SwingWorker.html">SwingWorker</A></B></TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD><CODE><A HREF="../../../org/opencyc/util/SwingWorker.html#construct()">construct</A>, <A HREF="../../../org/opencyc/util/SwingWorker.html#get()">get</A>, <A HREF="../../../org/opencyc/util/SwingWorker.html#getValue()">getValue</A></CODE></TD>
    </TR>
    </TABLE>
    &nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
    <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
    <TD><B>Methods inherited from class java.lang.Object</B></TD>
    </TR>
    <TR BGCOLOR="white" CLASS="TableRowColor">
    <TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
    </TR>
    </TABLE>
    &nbsp;
    <P>

    <!-- ============ FIELD DETAIL =========== -->

    <!-- ========= CONSTRUCTOR DETAIL ======== -->

    <A NAME="constructor_detail"><!-- --></A>
    <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
    <TD COLSPAN=1><FONT SIZE="+2">
    <B>Constructor Detail</B></FONT></TD>
    </TR>
    </TABLE>

    <A NAME="CycWorker()"><!-- --></A><H3>
    CycWorker</H3>
    <PRE>
    public <B>CycWorker</B>()</PRE>
    <DL>
    <DD>Creates a new instance of CycWorker</DL>

    <!-- ============ METHOD DETAIL ========== -->

    <A NAME="method_detail"><!-- --></A>
    <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
    <TD COLSPAN=1><FONT SIZE="+2">
    <B>Method Detail</B></FONT></TD>
    </TR>
    </TABLE>

    <A NAME="addListener(org.opencyc.util.CycWorkerListener)"><!-- --></A><H3>
    addListener</H3>
    <PRE>
    public void <B>addListener</B>(<A HREF="../../../org/opencyc/util/CycWorkerListener.html">CycWorkerListener</A>&nbsp;cwl)</PRE>
    <DL>
    <DD>Adds a new worker listener to this worker. Listeners will
     be notified when the worker is started, interrupted or
     finished.<DD><DL>
    <DT><B>Parameters:</B><DD><CODE>cwl</CODE> - The CycWorkerListener that wishes to listen to
     this worker</DL>
    </DD>
    </DL>
    <HR>

    <A NAME="removeListener(org.opencyc.util.CycWorkerListener)"><!-- --></A><H3>
    removeListener</H3>
    <PRE>
    public void <B>removeListener</B>(<A HREF="../../../org/opencyc/util/CycWorkerListener.html">CycWorkerListener</A>&nbsp;cwl)</PRE>
    <DL>
    <DD>Removes a worker listener from this worker.<DD><DL>
    <DT><B>Parameters:</B><DD><CODE>cwl</CODE> - The CycWorkerListener that no longer wishes to
     be notified of this workers events.</DL>
    </DD>
    </DL>
    <HR>

    <A NAME="getListeners()"><!-- --></A><H3>
    getListeners</H3>
    <PRE>
    public java.lang.Object[] <B>getListeners</B>()</PRE>
    <DL>
    <DD>Return a list of all CycWorkerListeners listening to
     this CycWorker.<DD><DL>
    <DT><B>Returns:</B><DD>A non-null array of CycWorkerListener objects.</DL>
    </DD>
    </DL>
    <HR>

    <A NAME="start()"><!-- --></A><H3>
    start</H3>
    <PRE>
    public void <B>start</B>()</PRE>
    <DL>
    <DD>This method starts the backround processing of a particular
     CycWorker. Appropriate listeners are notified when this
     is called.<DD><DL>
    <DT><B>Overrides:</B><DD><CODE><A HREF="../../../org/opencyc/util/SwingWorker.html#start()">start</A></CODE> in class <CODE><A HREF="../../../org/opencyc/util/SwingWorker.html">SwingWorker</A></CODE></DL>
    </DD>
    </DL>
    <HR>

    <A NAME="interrupt()"><!-- --></A><H3>
    interrupt</H3>
    <PRE>
    public void <B>interrupt</B>()</PRE>
    <DL>
    <DD>This method interrupts a currently running CycWorker.
     Appropriate listeners are notified when this is called.<DD><DL>
    <DT><B>Overrides:</B><DD><CODE><A HREF="../../../org/opencyc/util/SwingWorker.html#interrupt()">interrupt</A></CODE> in class <CODE><A HREF="../../../org/opencyc/util/SwingWorker.html">SwingWorker</A></CODE></DL>
    </DD>
    </DL>
    <HR>

    <A NAME="finished()"><!-- --></A><H3>
    finished</H3>
    <PRE>
    public void <B>finished</B>()</PRE>
    <DL>
    <DD>This method should be called internally only...public for
     Java related reasons only. It is automatically called
     then the construct() method finishes.
     Appropriate listeners are notified when this is called.<DD><DL>
    <DT><B>Overrides:</B><DD><CODE><A HREF="../../../org/opencyc/util/SwingWorker.html#finished()">finished</A></CODE> in class <CODE><A HREF="../../../org/opencyc/util/SwingWorker.html">SwingWorker</A></CODE></DL>
    </DD>
    </DL>
    <HR>

    <A NAME="getWork()"><!-- --></A><H3>
    getWork</H3>
    <PRE>
    public java.lang.Object <B>getWork</B>()</PRE>
    <DL>
    <DD>Exposed the get() method from SwingWorker class.
     Returns the result of this CycWorker. Returns
     null if worker not started or worker interrupted before
     processing could be completed. If processing is ongoing,
     will block till finished.<DD><DL>
    <DT><B>Returns:</B><DD>Returns the result of this CycWorker or null if
     CycWorker interrupted or not started.</DL>
    </DD>
    </DL>
    <!-- ========= END OF CLASS DATA ========= -->
    <HR>

    <!-- ========== START OF NAVBAR ========== -->
    <A NAME="navbar_bottom"><!-- --></A>
    <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
    <TR>
    <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
    <A NAME="navbar_bottom_firstrow"><!-- --></A>
    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
      <TR ALIGN="center" VALIGN="top">
      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
      <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
      <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
      </TR>
    </TABLE>
    </TD>
    <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
    </EM>
    </TD>
    </TR>

    <TR>
    <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
    &nbsp;<A HREF="../../../org/opencyc/util/CycUtils.html"><B>PREV CLASS</B></A>&nbsp;
    &nbsp;<A HREF="../../../org/opencyc/util/CycWorkerEvent.html"><B>NEXT CLASS</B></A></FONT></TD>
    <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
      <A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;
    &nbsp;<A HREF="CycWorker.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
    </TR>
    <TR>
    <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
      SUMMARY: &nbsp;<A HREF="#inner_classes_inherited_from_class_org.opencyc.util.SwingWorker">INNER</A>&nbsp;|&nbsp;<A HREF="#fields_inherited_from_class_org.opencyc.util.SwingWorker">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
    <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
    DETAIL: &nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
    </TR>
    </TABLE>
    <!-- =========== END OF NAVBAR =========== -->

    <HR>

    </BODY>
    </HTML>