?
Solved

DataQueueListener

Posted on 2006-04-11
5
Medium Priority
?
640 Views
Last Modified: 2012-08-13
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.


0
Comment
Question by:stevebeech
  • 4
5 Comments
 
LVL 13

Expert Comment

by:Webstorm
ID: 16428238
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
 
LVL 13

Expert Comment

by:Webstorm
ID: 16428246
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
 

Author Comment

by:stevebeech
ID: 16434149
Will this just sit and listen continuously for events? Or will it run and close?
0
 
LVL 13

Accepted Solution

by:
Webstorm earned 1000 total points
ID: 16434303
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
 
LVL 13

Expert Comment

by:Webstorm
ID: 16434429
:-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question