JUtility.initEANBarcode();
JLaunchReport.init();
Common.init();
JDBUser user = new JDBUser(getHostID(), getSessionID());
JDBControl ctrl = new JDBControl(getHostID(), getSessionID());
JeMail mail = new JeMail(getHostID(), getSessionID());
user.setUserId("INTERFACE");
user.setPassword("INTERFACE");
Common.userList.addUser(getSessionID(), user);
enableEnterfaceStatusEmails = Boolean.parseBoolean(ctrl.getKeyValueWithDefault("INTERFACE EMAIL NOTIFY", "false", "Email startup and shutdown events :- true or false"));
interfaceEmailAddresses = ctrl.getKeyValueWithDefault("INTERFACE ADMIN EMAIL", "someone@somewhere.com", "Email address for startup and shutdown events.");
StringConverter stringConverter = new StringConverter();
ArrayConverter arrayConverter = new ArrayConverter(String[].class, stringConverter);
arrayConverter.setDelimiter(';');
arrayConverter.setAllowedChars(new char[] { '@','_' });
String[] emailList = (String[]) arrayConverter.convert(String[].class, interfaceEmailAddresses);
siteName = Common.hostList.getHost(getHostID()).getSiteDescription();
if (user.login())
{
if (enableEnterfaceStatusEmails == true)
{
try
{
String subject = "";
if (houseKeeping == true)
{
// subject = "Commander4j "+JVersion.getProgramVersion()+" Interface maintenance restart for [" + siteName + "] on "+JUtility.getClientName();
// mail.postMail(emailList, subject, "Interface service has started.", "", "");
}
else
{
subject = "Commander4j "+JVersion.getProgramVersion()+" Interface startup for [" + siteName + "] on "+JUtility.getClientName();
mail.postMail(emailList, subject, "Interface service has started.", "", "");
}
}
catch (Exception ex)
{
logger.error("InterfaceThread Unable to send emails");
}
}
houseKeeping = false;
logger.debug("Interface Logged on successfully");
logger.debug("Starting Threads....");
secondsBeforeHousekeeping = Integer.valueOf(ctrl.getKeyValueWithDefault("INTERFACE HOUSEKEEPING INTERVAL", "86400", "Frequency in seconds."));
secondsRemaining = secondsBeforeHousekeeping;
startupThreads();
while ((shutdown == false) & (houseKeeping == false))
{
com.commander4j.util.JWait.milliSec(1000);
secondsRemaining--;
// logger.debug("Housekeeping scheduled in "+String.valueOf(secondsRemaining)+" seconds.");
if (secondsRemaining == 0)
{
houseKeeping = true;
}
}
logger.debug("Stopping Threads....");
shutdownThreads();
user.logout();
logger.debug("Interface Logged out successfully");
if (enableEnterfaceStatusEmails == true)
{
try
{
String subject = "";
if (houseKeeping == true)
{
// subject = "Commander4j "+JVersion.getProgramVersion()+" Interface maintenance shutdown for [" + siteName + "] on "+JUtility.getClientName();
// mail.postMail(emailList, subject, "Interface service has stopped.", "", "");
}
else
{
subject = "Commander4j "+JVersion.getProgramVersion()+" Interface shutdown for [" + siteName + "] on "+JUtility.getClientName();
mail.postMail(emailList, subject, "Interface service has stopped.", "", "");
}
}
catch (Exception ex)
{
logger.error("InterfaceThread Unable to send emails");
}
}
}
else
{
logger.debug("Interface routine failed to logon to application using account INTERFACE");
}
try
{
backupMessageRetention =Integer.valueOf(ctrl.getKeyValueWithDefault("INTERFACE BACKUP RETENTION","30","NUMBER OF DAYS TO KEEP BACKUP MESSAGES"));
}
catch (Exception ex)
{
backupMessageRetention = 30;
}