joj_123
asked on
Java mail agent thowing exception
Hi,
I have a problem with a mail agent written in java. It is used for sending mails for pending items. The agent is scheduled for every 15 minutes. The number of pending records are between 50-120 per day. The code was working fine in the production server for 3 months. But one month back it started throwing "lotus.domino.notes exception" and the application hangs every two days. From the log I couldn't get more details of the error.
My code is pasted below, where've I gone wrong? Could anyone help me.?
Thanks in advance
Joj
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session vNotesSession = getSession();
AgentContext vNotesAgentContext = vNotesSession.getAgentCont ext();
Document vNotesDocument;
DateTime now = null;
boolean bSent = false;
String sErrorMessage = "";
now = vNotesSession.createDateTi me("today" );
now.setNow();
Database vNotesDatabase = vNotesAgentContext.getCurr entDatabas e();
View vNotesView = vNotesDatabase.getView( "ScheduleMailForPending" );
View vSettingsView = vNotesDatabase.getView("Ap pSetting") ;
sleep(1000);
vSettingsView.refresh();
vNotesView.refresh();
Document vSettingDoc = vSettingsView.getFirstDocu ment();
String sSupervisor = null;
int sPendingHrs = 0;
int sUnattendHr = 0;
boolean stopMail = false ;
String status = null;
String statusFlag = null;
if (vSettingDoc != null) {
sSupervisor = vSettingDoc.getItemValueSt ring("Setu pSuperviso r");
String sUnattendHrs = vSettingDoc.getItemValueSt ring("Setu pUnattende d");
String sPendingHr = vSettingDoc.getItemValueSt ring("Setu pPending") ;
if (sPendingHr != null)
sPendingHrs = Integer.parseInt(sPendingH r.trim());
String stopM = vSettingDoc.getItemValueSt ring("Setu pStopMail" );
boolean sm = (stopM != null && stopM.equals("false") );
if (sm && sPendingHrs != 0 && sSupervisor != null)
stopMail = true;
} else {
stopMail = false;
}
//loop through all the documents in the All view and mail them and then remove them
vNotesDocument = vNotesView.getFirstDocumen t();
Item tempItem = null;
int noOfHours = 0;
DateTime tempDate = null;
String ticketNo = null;
int counter = 1;
while ( stopMail && vNotesDocument != null) {
status = vNotesDocument.getItemValu eString("S tatus");
ticketNo = vNotesDocument.getItemValu eString("L ogCallTick etNo");
Document vDominoDocument = null;
try {
tempItem = vNotesDocument.getFirstIte m("AttendD ate");
tempDate = tempItem.getDateTimeValue( );
noOfHours = now.timeDifference(tempDat e);
if (noOfHours > 0 && (noOfHours/3600) >= sPendingHrs) {
vDominoDocument = vNotesDatabase.createDocum ent();
vDominoDocument.replaceIte mValue("Su bject", "HelpDesk Application : Pending Calls");
vDominoDocument.replaceIte mValue("Bo dy", "This mail has been originated by Helpdesk Application. Call is pending for more than " + sPendingHrs + " Hours \n Ticket Numer is " + ticketNo);
vDominoDocument.send(false , sSupervisor);
bSent = true;
} else {
bSent = false;
}
} catch (Exception ex) {
bSent = false;
System.out.println("Except ion " + ex.getMessage());
} finally {
//Complete fields on the mail document.
if ( bSent ) {
vNotesDocument.replaceItem Value("Sta tusFlag", "Escalated");
vNotesDocument.replaceItem Value("Esc alatedStat us", "None");
vNotesDocument.replaceItem Value("Mes sageStatus ", now + " : Message Sent Ok!");
vNotesDocument.save ( true, false, false );
}
} //try inside while loop
++counter;
vNotesDocument = vNotesView.getNthDocument( counter );
} //while loop
} catch(Exception e) {
e.printStackTrace();
}
}
}
I have a problem with a mail agent written in java. It is used for sending mails for pending items. The agent is scheduled for every 15 minutes. The number of pending records are between 50-120 per day. The code was working fine in the production server for 3 months. But one month back it started throwing "lotus.domino.notes exception" and the application hangs every two days. From the log I couldn't get more details of the error.
My code is pasted below, where've I gone wrong? Could anyone help me.?
Thanks in advance
Joj
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session vNotesSession = getSession();
AgentContext vNotesAgentContext = vNotesSession.getAgentCont
Document vNotesDocument;
DateTime now = null;
boolean bSent = false;
String sErrorMessage = "";
now = vNotesSession.createDateTi
now.setNow();
Database vNotesDatabase = vNotesAgentContext.getCurr
View vNotesView = vNotesDatabase.getView( "ScheduleMailForPending" );
View vSettingsView = vNotesDatabase.getView("Ap
sleep(1000);
vSettingsView.refresh();
vNotesView.refresh();
Document vSettingDoc = vSettingsView.getFirstDocu
String sSupervisor = null;
int sPendingHrs = 0;
int sUnattendHr = 0;
boolean stopMail = false ;
String status = null;
String statusFlag = null;
if (vSettingDoc != null) {
sSupervisor = vSettingDoc.getItemValueSt
String sUnattendHrs = vSettingDoc.getItemValueSt
String sPendingHr = vSettingDoc.getItemValueSt
if (sPendingHr != null)
sPendingHrs = Integer.parseInt(sPendingH
String stopM = vSettingDoc.getItemValueSt
boolean sm = (stopM != null && stopM.equals("false") );
if (sm && sPendingHrs != 0 && sSupervisor != null)
stopMail = true;
} else {
stopMail = false;
}
//loop through all the documents in the All view and mail them and then remove them
vNotesDocument = vNotesView.getFirstDocumen
Item tempItem = null;
int noOfHours = 0;
DateTime tempDate = null;
String ticketNo = null;
int counter = 1;
while ( stopMail && vNotesDocument != null) {
status = vNotesDocument.getItemValu
ticketNo = vNotesDocument.getItemValu
Document vDominoDocument = null;
try {
tempItem = vNotesDocument.getFirstIte
tempDate = tempItem.getDateTimeValue(
noOfHours = now.timeDifference(tempDat
if (noOfHours > 0 && (noOfHours/3600) >= sPendingHrs) {
vDominoDocument = vNotesDatabase.createDocum
vDominoDocument.replaceIte
vDominoDocument.replaceIte
vDominoDocument.send(false
bSent = true;
} else {
bSent = false;
}
} catch (Exception ex) {
bSent = false;
System.out.println("Except
} finally {
//Complete fields on the mail document.
if ( bSent ) {
vNotesDocument.replaceItem
vNotesDocument.replaceItem
vNotesDocument.replaceItem
vNotesDocument.save ( true, false, false );
}
} //try inside while loop
++counter;
vNotesDocument = vNotesView.getNthDocument(
} //while loop
} catch(Exception e) {
e.printStackTrace();
}
}
}
You say several things:
1. the agent used to work (3 months production, no problems)
2. now, the agent comes with errors in the log
3. somehow, you assume it's your code
I think that thinking #3 is jumping to conclusions, but only if you haven't touched the agent in the meantime, of course. Let's do this step by step:
1. what caused the sudden change in the agent's execution, why are there errors?
When you know this, we'll have a clear picture if it has always been your agent or that there might be something else in the environment that caused the problem. It is more than likely that there was an upgrade of the server or some other change in the server's configuration.
1. the agent used to work (3 months production, no problems)
2. now, the agent comes with errors in the log
3. somehow, you assume it's your code
I think that thinking #3 is jumping to conclusions, but only if you haven't touched the agent in the meantime, of course. Let's do this step by step:
1. what caused the sudden change in the agent's execution, why are there errors?
When you know this, we'll have a clear picture if it has always been your agent or that there might be something else in the environment that caused the problem. It is more than likely that there was an upgrade of the server or some other change in the server's configuration.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot everybody. Just after posting the question I came across two useful links which illustrates the importance of the recycle method.(infact we were using the recycle method everywhere in the code, but missed out in this particular agent)
The links are,
http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/afc77a0cb5e49e3a85256a76006b5183/$FILE/JMP106.pdf (page 20-26)
http://www-1.ibm.com/support/docview.wss?rs=203&uid=swg21097861&loc=en_US&cs=utf-8&lang=en
I've added the recycle method in the agent and awaiting its result.
The links are,
http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/afc77a0cb5e49e3a85256a76006b5183/$FILE/JMP106.pdf (page 20-26)
http://www-1.ibm.com/support/docview.wss?rs=203&uid=swg21097861&loc=en_US&cs=utf-8&lang=en
I've added the recycle method in the agent and awaiting its result.
I'd love to learn what the real solution was to the problem...
ASKER
Sorry, I made a mistake while selecting the answers. Assisted answers are supposed to be the accepted ones and vice versa.
The recycle method worked. I had added a method to my controller servlet, which was accessed by everypage, on which I left the session without recycling.
Thanks everybody, for your help.
The recycle method worked. I had added a method to my controller servlet, which was accessed by everypage, on which I left the session without recycling.
Thanks everybody, for your help.
ASKER