These actions are called whenever your PBX is restarted and allow you to do any startup processes such as scheduling recurring events.
The System Startup Script has two entry points:
The constructor of you Action Script and a shutdown method:
public void shutdown()
Your startup script will start shortly after the PBX starts.
Code changes
If you make any changes to the script the script needs to be reload. To allow you to manage this in a graceful manner the 'shutdown' method is called as part of the reload. The scripts constructor will then be called with the newly compiled version of your script.
Example:
Code Block |
---|
package script;
import au.com.noojee.actionscript.api.v1.ActionScriptUtils;
import idatam.common.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ScheduledFuture;
import java.util.Date;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Future;
import com.google.gson.Gson;
import au.com.noojee.actionscript.api.v1.dto.TeamApiDto;
import au.com.noojee.actionscript.api.v1.dto.UserSpaceApiDto;
import au.com.noojee.actionscript.api.v1.dto.AgentRosterDto;
import au.com.noojee.actionscript.api.v1.StartUpScript;
import au.com.noojee.actionscript.api.v1.CallLogger;
/**
*
* Checks through UserSpace variables for active tickets.
*
* If an active ticket exists that hasn't been accepted by an engineer it will
* initiate a call.
*
* The ticket data is stored as a json object (see class Ticket below).
*
* The tickets are stored in users space under a common key format:
* CriticalTicket.<ticketNo>
*/
public class StartupMonitorTickets implements Runnable, StartUpScript
{
CallLogger logger = ActionScriptUtils.getLogger(StartupMonitorTickets.class);
Future future;
Future rosterFuture;
MonitorTickets monitor = new MonitorTickets();
public StartupMonitorTickets()
{
try
{
logger.info("Monitor of Tickets and Rosters starting.");
// initiate regular schedule to monitor tickets every minute.
this.future = Executor.scheduler.scheduleAtFixedRate(this, 10, 20, TimeUnit.SECONDS);
this.rosterFuture = Executor.scheduler.scheduleAtFixedRate(new MonitorRoster(), 5, 240, TimeUnit.MINUTES);
}
catch(Throwable e)
{
logger.error(e,e);
}
}
public void run()
{
logger.info("Ticket Monitor Running");
if (!monitor.run())
future.cancel(false);
}
// this gets called every time a route is recompiled!
public void shutdown()
{
logger.info("Monitor of Tickets and Rosters shutdown called.");
// avoid dangling schedules.
future.cancel(false);
rosterFuture.cancel(false);
}
}
|