Help to implement OperationListener interface.

Discussion in 'Java' started by mike, Oct 30, 2007.

  1. mike

    mike Guest

    Hi,

    I have the following interface OperationListener interface ( it's for
    an open source project I helping out with). Well the idea behind the
    interface is to monitor operations taking place simlair to the
    eclipse IProgressMonitor.

    Then I have an operation like:

    myApp.operationDel( file, operationListener);

    I don't know how to implement the interface.

    Any ideas ?

    cheers,

    mike

    public interface OperationListener {

    /**
    * Notifies the receiver that the specified operation has started.
    *
    * @param amountOfWork
    * the amount of expected work
    */
    void startedOperation(int amountOfWork);

    /** /**
    * Notifies the receiver that the specified operation finished.
    * <p>
    * Note that t
    * Notifies the receiver about progress of the specified
    operation.
    *
    * @param ticks
    * the progress
    */
    void worked(int ticks);

    /**
    * Notifies the receiver that an operation is still ongoing but
    * that no progress information is available.
    *
    */
    void ping();

    /**
    * Notifies the receiver that the specified operation finished.
    * <p>
    * Note that the listener may not be notified if an exeception
    occurs while
    * performing the operation.
    * </p>
    */
    void finishedOperation();

    /**
    * Notifies the caller if the operation should be canceled.
    *
    * @return <code>true</code> if the caller (the ClearCase
    interface)
    * should cancel the current operation, <code>false</code>
    * otherwise
    */
    boolean isCanceled();
    }
     
    mike, Oct 30, 2007
    #1
    1. Advertising

  2. On Oct 30, 10:54 am, mike <> wrote:
    > Hi,
    >
    > I have the following interface OperationListener interface ( it's for
    > an open source project I helping out with). Well the idea behind the
    > interface is to monitor operations taking place simlair to the
    > eclipse IProgressMonitor.
    >
    > Then I have an operation like:
    >
    > myApp.operationDel( file, operationListener);
    >
    > I don't know how to implement the interface.
    >
    > Any ideas ?
    >


    If I understood the problem statement correctly, I do not think you
    have to implement the interface - you will need to call the interface
    methods as you progress through the operationDel. The *caller* will
    give you an implementation of this interface, which you will use as a
    callback to notify the caller of various events, and the caller (I
    suppose) will use this information to render a progressbar, or report
    status via messages, etc.

    For example, you will invoke operationListener.startedOperation(100);
    where 100 is the % remaining. At the end, you will invoke
    operationListener.finishedOperation().

    Hope this helps!

    -cheers,
    Manish
     
    Manish Pandit, Oct 30, 2007
    #2
    1. Advertising

  3. mike

    mike Guest

    On 30 Okt, 19:04, Manish Pandit <> wrote:
    > On Oct 30, 10:54 am, mike <> wrote:
    >
    > > Hi,

    >
    > > I have the following interface OperationListener interface ( it's for
    > > an open source project I helping out with). Well the idea behind the
    > > interface is to monitor operations taking place simlair to the
    > > eclipse IProgressMonitor.

    >
    > > Then I have an operation like:

    >
    > > myApp.operationDel( file, operationListener);

    >
    > > I don't know how to implement the interface.

    >
    > > Any ideas ?

    >
    > If I understood the problem statement correctly, I do not think you
    > have to implement the interface - you will need to call the interface
    > methods as you progress through the operationDel. The *caller* will
    > give you an implementation of this interface, which you will use as a
    > callback to notify the caller of various events, and the caller (I
    > suppose) will use this information to render a progressbar, or report
    > status via messages, etc.
    >
    > For example, you will invoke operationListener.startedOperation(100);
    > where 100 is the % remaining. At the end, you will invoke
    > operationListener.finishedOperation().


    Ok!

    I am calling the interface as my task, operationDel, makes progress or
    isCanceled.
    Shall the class where I have my call:

    myApp.operationDel( file, operationListener);

    implement the interface. Seems like I cannot figure out how the
    callback is working!
    Or am I missing something here?

    cheers,

    mike



    >
    > Hope this helps!
    >
    > -cheers,
    > Manish
     
    mike, Oct 30, 2007
    #3
  4. On Oct 30, 11:18 am, mike <> wrote:
    > Ok!
    >
    > I am calling the interface as my task, operationDel, makes progress or
    > isCanceled.
    > Shall the class where I have my call:
    >
    > myApp.operationDel( file, operationListener);
    >
    > implement the interface. Seems like I cannot figure out how the
    > callback is working!
    > Or am I missing something here?
    >


    Either the caller, or any other class can implement this interface.
    Whoever implements it needs to be passed to the method call. The
    interface methods wil be called by the method call at various points,
    and the implementation will receive these callbacks (it is also called
    a hook), and can use that to perform any operation. For now, you can
    log a message or do a System.out.println() to understand the flow and
    the callback mechanism, later you can tie it to more complex solution,
    like rendering a progressbar or something similar.

    -cheers,
    Manish
     
    Manish Pandit, Oct 30, 2007
    #4
  5. mike

    mike Guest

    On 30 Okt, 19:47, Manish Pandit <> wrote:
    > On Oct 30, 11:18 am, mike <> wrote:
    >
    > > Ok!

    >
    > > I am calling the interface as my task, operationDel, makes progress or
    > > isCanceled.
    > > Shall the class where I have my call:

    >
    > > myApp.operationDel( file, operationListener);

    >
    > > implement the interface. Seems like I cannot figure out how the
    > > callback is working!
    > > Or am I missing something here?

    >
    > Either the caller, or any other class can implement this interface.
    > Whoever implements it needs to be passed to the method call. The
    > interface methods wil be called by the method call at various points,
    > and the implementation will receive these callbacks (it is also called
    > a hook), and can use that to perform any operation. For now, you can
    > log a message or do a System.out.println() to understand the flow and
    > the callback mechanism, later you can tie it to more complex solution,
    > like rendering a progressbar or something similar.
    >
    > -cheers,
    > Manish


    Thanks Manish,

    I get it now :)
     
    mike, Oct 30, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. frank

    Implement IList Interface

    frank, Jul 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    584
    frank
    Jul 11, 2003
  2. Marco Vasquez
    Replies:
    0
    Views:
    399
    Marco Vasquez
    Dec 30, 2003
  3. Martin
    Replies:
    0
    Views:
    1,143
    Martin
    May 19, 2005
  4. beau
    Replies:
    2
    Views:
    325
    E.C. B├Ąck
    Aug 30, 2003
  5. Bruce Sam
    Replies:
    5
    Views:
    7,908
    Mike Schilling
    Jan 13, 2005
Loading...

Share This Page