PDA

View Full Version : Dataqueue aktuelle größe in Java herrausfinden.



Deficiency
19-03-12, 14:20
Hallo.

Ich habe ein Problem, dass sich ab und an ein paar Java Programme im Batch einfach verabschieben. Ich will deshalb die DTAQ überwachen, auf die die Java Programme hören. z.B. wenn die DTAQ mehr als 20 Einträge hat, dann benachrichtige mich.
Ich finde aber in der IBM Hilfe nichts.

mit hilfe des Code unten, bekomme ich nur die Info, ob sie leer ist.

Hat jemand einen Tipp?




public class DataQueueDocumentExample {
private static DataQueueDocument dqDocument;

private static JTextField text;

private static boolean rw;

public static void main(String[] args) {
// If a system or read|write was not specified, then display
// help text and exit.


String mode = "READ";
System.out.println(rw + " " + mode);

try {
// Create two frames.
JFrame f = new JFrame("Data queue document example - " + mode);

// Create an error dialog adapter. This will display
// any errors to the user.
ErrorDialogAdapter errorHandler = new ErrorDialogAdapter(f);

// Create a working cursor adapter. This will adjust
// the cursor whenever a data queue is read or written.
WorkingCursorAdapter cursorAdapter = new WorkingCursorAdapter(f);

// Create an AS400 object. The system name was passed
// as the first command line argument.
AS400 system = new AS400("dach041a");

// Create the data queue path name.
QSYSObjectPathName dqName = new QSYSObjectPathName("LIB", "DTAQNAME", "DTAQ");

// Make sure the the data queue exists.
DataQueue dq = new DataQueue(system, dqName.getPath());
try {
dq.create(200);
} catch (Exception e) {
// Ignore exceptions. Most likely, the data queue
// already exists.
}

// Create a DataQueueDocument object.
dqDocument = new DataQueueDocument(system, dqName.getPath());
dqDocument.addErrorListener(errorHandler);
dqDocument.addWorkingListener(cursorAdapter);
dqDocument.getProperty("size");
if (dq.peek() == null) {
System.out.println("EMPTY");
}

// Create a text field used to present the document.
text = new JTextField(dqDocument, "", 40);
text.setEditable(!rw);

// When the program runs, we need a way to control when
// the reads and writes take place. We will let the
// use control this with a button.
Button button = new Button(mode);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (rw) {
dqDocument.read();
} else {
dqDocument.write();
text.setText("");
}
}
});

// When the the frame closes, exit.
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent event) {
System.exit(0);
}
});

// Layout the frame.
f.getContentPane().setLayout(new FlowLayout());
f.getContentPane().add(text);
f.getContentPane().add(button);
f.pack();
f.show();
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
System.exit(0);
}
}
}

Fuerchau
19-03-12, 14:46
Die Anzahl der Sätze lässt sich tatsächlich nur heruasfinden, wenn man sie ausliest.
Danach sind sie allerdings auch weg.
Man muss also die ausgelesenen Sätze wieder reinschreiben.

KM
19-03-12, 16:09
Hallo,

erstelle evtl. noch einen weiteres Java-Programm, das die Dataqueue in bestimmten Zeit-Intervallen nur liest ohne die Einträge zu löschen. Wenn Du statt read() die Methode peek() verwendest, um die Dataqueue nur auszulesen, sollte das funktionieren.

Gruß,
KM

BenderD
19-03-12, 16:19
QMHQRDQD ist dein Freund.

D*B

Fuerchau
19-03-12, 16:20
Zu bedenken ist halt nur, dass peek() den 1. Satz liest.
Ein weiterer peek() liest also den selben Satz noch mal!