charly.client
Class ChTask

java.lang.Object
  extended bycharly.client.ChTask

public class ChTask
extends java.lang.Object

This class manages the ressources needed for a task. First add resources through addResource( ChConnect, String). Then call start(boolean). After performing the task call stop(); this frees the ressources in order to allow other users to get access.


Nested Class Summary
(package private)  class ChTask.ChClientTaskRepresentation
          This class is for intern use only.
 
Field Summary
protected  ChConnect conn
           
protected  java.lang.String name
           
(package private)  ChTask.ChClientTaskRepresentation representation
           
protected  java.util.Set rsrcs
           
protected  boolean starting
          This variable is used to wait for the start.
protected  java.lang.String taskID
           
protected  java.util.LinkedList taskListeners
           
 
Constructor Summary
ChTask(ChConnect conn, java.lang.String taskName)
          Constructor.
ChTask(java.lang.String taskName)
           
 
Method Summary
 void addResource(ChConnect conn, java.lang.String rsrc)
          adds a resource to the task.
 void addResource(ChResource rsrc)
          adds a resource to the task.
 void addTaskListener(ChTaskListener l)
           
private  void assertConn(ChConnect conn)
          this method only exists until more than one ChConnect is supported.
private static boolean compare(java.lang.Object cmp1, java.lang.Object cmp2)
           
protected  void finalize()
          calls stop()
protected  void fireTaskAbortedEvent()
           
protected  void fireTaskStartedEvent()
           
protected  void fireTaskStoppedEvent()
           
 java.lang.String getName()
          returns the name of the task
 java.lang.String getTaskID()
          returns the taskID, the task got from the server.
 boolean isStarted()
          returns true, if the task has been started and not yet stopped or aborted.
 void removeResource(ChConnect conn, java.lang.String rsrc)
          removes a resource to the task.
 void removeTaskListener(ChTaskListener l)
           
protected  void setTaskID(java.lang.String taskID)
          is called by ChTask.ChClientTaskRepresentation.taskStarted(String)
 void start(boolean wait)
          Before using the resources this method should be called.
 void stop()
          normal end of task.
protected  void waitForAcceptance()
          it simply calls this.wait().
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

rsrcs

protected java.util.Set rsrcs

conn

protected ChConnect conn

taskListeners

protected java.util.LinkedList taskListeners

representation

ChTask.ChClientTaskRepresentation representation

starting

protected volatile boolean starting
This variable is used to wait for the start.

See Also:
waitForAcceptance(), start(boolean)

taskID

protected java.lang.String taskID
Constructor Detail

ChTask

public ChTask(ChConnect conn,
              java.lang.String taskName)
Constructor.

Parameters:
conn - - connection to the server. If this parameter is omitted, the connection is taken from the first added resource
taskName - - name of the task

ChTask

public ChTask(java.lang.String taskName)
Method Detail

fireTaskStartedEvent

protected void fireTaskStartedEvent()

fireTaskAbortedEvent

protected void fireTaskAbortedEvent()

fireTaskStoppedEvent

protected void fireTaskStoppedEvent()

addTaskListener

public void addTaskListener(ChTaskListener l)

removeTaskListener

public void removeTaskListener(ChTaskListener l)

compare

private static final boolean compare(java.lang.Object cmp1,
                                     java.lang.Object cmp2)

setTaskID

protected void setTaskID(java.lang.String taskID)
is called by ChTask.ChClientTaskRepresentation.taskStarted(String)


getTaskID

public java.lang.String getTaskID()
returns the taskID, the task got from the server. After the task has been stopped or aborted the taskID is reset to null.


isStarted

public boolean isStarted()
returns true, if the task has been started and not yet stopped or aborted.


getName

public java.lang.String getName()
returns the name of the task


start

public void start(boolean wait)
           throws java.rmi.RemoteException,
                  java.net.MalformedURLException,
                  ChAlreadyStartingException,
                  java.rmi.NotBoundException,
                  ChAlreadyStartedException,
                  ChNoRsrcsAddedException
Before using the resources this method should be called.

Parameters:
wait - if true the method waits until the task is started on the server.
Throws:
java.rmi.RemoteException
java.net.MalformedURLException
ChAlreadyStartingException
java.rmi.NotBoundException
ChAlreadyStartedException
ChNoRsrcsAddedException

waitForAcceptance

protected void waitForAcceptance()
it simply calls this.wait(). A standard task listener will call this.notify().

See Also:
ChTask(String)

stop

public void stop()
normal end of task.


finalize

protected void finalize()
                 throws java.lang.Throwable
calls stop()

Throws:
java.lang.Throwable

addResource

public void addResource(ChConnect conn,
                        java.lang.String rsrc)
adds a resource to the task. E.g. "GPIB/7". Currently, only resources of a single conn are supported, which means that in every call to addRsrc of a certain task the parameter conn should be the same.

See Also:
addResource(ChResource)

addResource

public void addResource(ChResource rsrc)
adds a resource to the task. Calls rsrc.ChResource.setTask(ChTask). Currently, only resources of a single conn are supported, which means that in every call to addRsrc of a certain task the parameter conn should be the same.

See Also:
addResource(ChConnect,String)

removeResource

public void removeResource(ChConnect conn,
                           java.lang.String rsrc)
removes a resource to the task. E.g. "GPIB/7".


assertConn

private void assertConn(ChConnect conn)
this method only exists until more than one ChConnect is supported.