DataQueueListener

I've written a DataQueueListener class:

class DQListener implements DataQueueListener {

      public void read(DataQueueEvent event) {
            System.out.println("Read occurred");
            System.out.println("ID: " + event.getID());
      }

        public void written(DataQueueEvent event) {
            System.out.println("Write occurred");
            System.out.println("ID: " + event.getID());
      }

      public void peeked(DataQueueEvent event) { }

      public void cleared(DataQueueEvent event) { }
}

And I want to listen to a DataQueue constantly, waiting to detect writes to the data queue.

How to I add this code to a Java class which just sits listening?

I know I have to add the Listener to the DataQueue like so:

AS400 sys = new AS400("system", "username", "password");
DataQueue dq1 = new DataQueue(sys, "/QSYS.LIB/STEVE.DTAQ");
DQListener dqlist = new DQListener();
dq1.addDataQueueListener(dqlist);

but am not sure how the class is organised.


stevebeechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WebstormCommented:
you can do:


public class TestListener extends DQListener
{
   public TestListener()
   {
      AS400 sys = new AS400("system", "username", "password");
      DataQueue dq1 = new DataQueue(sys, "/QSYS.LIB/STEVE.DTAQ");
      DQListener dqlist = new DQListener();
      dq1.addDataQueueListener(dqlist);
      ...
   }
   ...
}
0
WebstormCommented:
Forget the coment above:

public class TestListener extends DQListener
{
   public TestListener()
   {
      AS400 sys = new AS400("system", "username", "password");
      DataQueue dq1 = new DataQueue(sys, "/QSYS.LIB/STEVE.DTAQ");
      dq1.addDataQueueListener(this);
      ...
   }
   ...
}
0
stevebeechAuthor Commented:
Will this just sit and listen continuously for events? Or will it run and close?
0
WebstormCommented:
Your application should then use the DataQueue (calling read,write,peek methods).

http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/rzahh/javadoc/com/ibm/as400/access/DataQueue.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WebstormCommented:
:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.