Does anyone know why a scheduled Java agent would just quit working?

Morning all.

I have a java agent that I wrote that is supposed to go through and calculate the amount of drive space we would have if we ran automated archiving from a specific date. I wrote the agent last week in eclipse and copied the code over to the Domino Designer IDE from a simple cut and paste operation. I managed to successfully compile the code and scheduled the agent.

In order to debug the agent I added System.out.println commands to show where my agent is executing in the log. For some reason, however, my agent just quits and never gets to the second println listed below. It doesn’t throw any exceptions, or I assume I would get the stacktrace as called from my catch statement.

Can someone take a look at this code and see what I am doing wrong? This agent worked on our test server, but to be honest it had fewer mail files to process. I am new to java, so I’d like to know what mistakes I’ve made from those of you out there that have some experience in this realm.

thanks.

brandt

here’s the code:

import lotus.domino.*;

import java.util.*;

public class HDCalcAgent extends AgentBase {

public void NotesMain(){		

	

	try {

		Session s = getSession();

		AgentContext ac = s.getAgentContext();

		System.out.println("HDCalc Java agent has started");<--this println displays

		long keepCount = 0;

		long removeCount = 0;

		DateTime dt = s.createDateTime("Today");

		dt.adjustDay(-549);

		DbDirectory dbDir = s.getDbDirectory(null);

		Database db = dbDir.getFirstDatabase(dbDir.DATABASE);

		Database nextdb = null;

		while (db != null) {

			String filePath = db.getFilePath();

			int findString = filePath.lastIndexOf(Consts.MAIL);

			if (findString != -1) {

				System.out.println("About to test for DB access");<--It never makes it to this println

				try {

					db.open();

				} catch (Exception e){

					System.out.println("You do not have access to " + db.getFileName());

				}

				if (db.isOpen()){

					DocumentCollection dc = db.getAllDocuments();

					Document doc = dc.getFirstDocument();

					Document nextdoc = null;

					while (doc != null){

						DateTime cdt = doc.getCreated();

						int timeDiff = cdt.timeDifference(dt);

						if (timeDiff < 0){

							removeCount = removeCount + doc.getSize();

						} else {

							keepCount = keepCount + doc.getSize();

						}

						nextdoc = dc.getNextDocument();

						doc.recycle();

						doc = nextdoc;

					}

				}

				nextdb = dbDir.getNextDatabase();

				db.recycle();

				db = nextdb;

			}

		}

		Database basedb = ac.getCurrentDatabase();

		System.out.println("Calling DB accessed");

		long keepCalc = Math.round(keepCount/Consts.MB);

		long remCalc = Math.round(removeCount/Consts.MB);

		String keepSpace = "" + keepCalc;

		String remSpace = "" + remCalc;

		Document memo = basedb.createDocument();

		System.out.println("Memo has been created.");

		memo.replaceItemValue(Fields.FORM,FValues.MEMO);

		memo.replaceItemValue(Fields.PRINCIPAL,s.getServerName());

		memo.replaceItemValue(Fields.SENDTO,SendTo.RECIPIENTS);

		memo.replaceItemValue(Fields.SUBJECT,FValues.SUBJECT);

		System.out.println("Fields have been created.");

		RichTextItem rtItem = memo.createRichTextItem(Fields.BODY);

		rtItem.appendText(Body.TEXT1);

		rtItem.appendText(dt.getDateOnly());

		rtItem.appendText(Body.TEXT2);

		rtItem.addNewLine(2);

		rtItem.appendText(Body.TEXT3);

		rtItem.appendText(keepSpace);

		System.out.println("HD Space maintained: " + keepSpace + " MB");

		rtItem.addNewLine(2);

		rtItem.appendText(Body.TEXT4);

		rtItem.appendText(remSpace);

		System.out.println("HD Space reclaimed: " + remSpace + " MB");

		System.out.println("Memo about to be sent.");

		memo.send(false);

		System.out.println("HDCalc agent finished.");

	} catch (Exception e) {

		e.printStackTrace();

	}

}

}

final class Consts {

public static final String MAIL = "mail\\";

public static final int MB = 1048576;

}

final class Fields {

public static final String FORM = "Form";

public static final String PRINCIPAL = "Principal";

public static final String SENDTO = "SendTo";

public static final String SUBJECT = "Subject";

public static final String BODY = "Body";

}

final class FValues {

public static final String MEMO = "Memo";

public static final String SUBJECT = "Notes Archiving Hard Drive Calculations";

}

final class Body {

public static final String TEXT1 = "The following calculations have been made to determine the amount of space needed if automated archiving was institued to archive all documents received prior to ";

public static final String TEXT2 = ". All values are in megabytes.";

public static final String TEXT3 = "Amount of space still necessary for non-archived documents: ";

public static final String TEXT4 = "Amount of space recovered by potential archive process: ";

}

final class SendTo {

private static final String[] PRIVATE_RECIPIENTS = {"User1","User2"};

private static final List RECIPIENT_LIST = Collections.unmodifiableList(Arrays.asList(PRIVATE_RECIPIENTS));

public static final Vector RECIPIENTS = new Vector(RECIPIENT_LIST);

}

Subject: No, but…

You might try moving that second println up, so that it’s not inside you if-statement.

All the lines look good to me, but if it’s not working after it moved into a Notes db, it might be the directory path. Did you try it inside a Notes db in the test environment?

Hope this helps?

Dave

Chub Toad

Subject: RE: No, but…

Dave,

The agent was tested in a test environment and worked. I moved it to our production server and it doesn’t.

However, I took your suggestion and moved the println up…the while loop is working perfectly. However, I added another println where the old one was like so:

String filePath = db.getFilePath();

			int findString = filePath.lastIndexOf(Consts.MAIL);

			System.out.println("About to test for DB access");

			System.out.println("Database accessed: " + db.getFileName());

The first println is all over my log. The second one never appears. The agent will not show me what database it is accessing. So in my estimation, it never gets to the if statement.

Any ideas? I am totally baffled.

brandt

Subject: oh dear…

It turns out that i was caught in an infinite loop…the next db would only be called if I managed to find an nsf in the mail directory…since the first database I accessed would never be found there, i was caught in an infinite loop…

oops. thanks for the suggestion Dave. that was how I caught it.

brandt

Subject: Does anyone know why a scheduled Java agent would just quit working?

It works for me.

Are you sure the mail files are in the 'mail' directory?

Try forgetting about the loop for the time being and just hardcode a getDatabase( …, “mail\fbrandt.nsf” ) and see if that works.

Frunobulax