|
|
|
@@ -5,6 +5,7 @@ import java.io.FileInputStream; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.io.StringReader; |
|
|
|
import java.time.LocalTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.Enumeration; |
|
|
|
@@ -22,6 +23,8 @@ import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import org.apache.log4j.Logger; |
|
|
|
import org.apache.log4j.PropertyConfigurator; |
|
|
|
import org.json.simple.JSONObject; |
|
|
|
import org.json.simple.parser.JSONParser; |
|
|
|
|
|
|
|
import altk.comm.engine.Broadcast.BroadcastState; |
|
|
|
|
|
|
|
@@ -29,6 +32,10 @@ import altk.comm.engine.Broadcast.BroadcastState; |
|
|
|
public abstract class CommEngine extends HttpServlet |
|
|
|
{ |
|
|
|
|
|
|
|
private static final String CLOCK_24HR_PAUSE_KEY = "clock_24hr_pause"; |
|
|
|
|
|
|
|
private static final String CLOCK_24HR_RESUME_KEY = "clock_24hr_resume"; |
|
|
|
|
|
|
|
static final String REQUEST_TOP_ELEMENT_NAME_DEFAULT = "Request"; |
|
|
|
|
|
|
|
private static final long DEAD_BROADCAST_VIEWING_PERIOD_DEFAULT = 60; |
|
|
|
@@ -104,16 +111,16 @@ public abstract class CommEngine extends HttpServlet |
|
|
|
// Check for pause |
|
|
|
if (broadcast.clock_24hr_pause != null && broadcast.clock_24hr_pause.length() > 0) |
|
|
|
{ |
|
|
|
if (timeOfDay.equals(broadcast.clock_24hr_pause)) broadcast.pause(null); |
|
|
|
if (timeOfDay.equals(broadcast.clock_24hr_pause)) broadcast.pause("clock", null); |
|
|
|
} |
|
|
|
else if (clock_24hr_pause.equals(timeOfDay)) broadcast.pause(null); |
|
|
|
else if (clock_24hr_pause.equals(timeOfDay)) broadcast.pause("clock", null); |
|
|
|
|
|
|
|
// Check for resume |
|
|
|
if (broadcast.clock_24hr_resume != null && broadcast.clock_24hr_resume.length() > 0) |
|
|
|
{ |
|
|
|
if (timeOfDay.equals(broadcast.clock_24hr_resume)) broadcast.resume(null); |
|
|
|
if (timeOfDay.equals(broadcast.clock_24hr_resume)) broadcast.resume("clock", null); |
|
|
|
} |
|
|
|
else if (clock_24hr_resume.equals(timeOfDay)) broadcast.resume(null); |
|
|
|
else if (clock_24hr_resume.equals(timeOfDay)) broadcast.resume("clock", null); |
|
|
|
} |
|
|
|
|
|
|
|
// Wakes up every 1/2 minute to provide minute resolution |
|
|
|
@@ -247,8 +254,8 @@ public abstract class CommEngine extends HttpServlet |
|
|
|
// Set up periodic purge of stale broadcasts, based on deadBroadcastViewingMinutes |
|
|
|
String periodStr = config.getProperty("dead_broadcast_viewing_period", Long.toString(DEAD_BROADCAST_VIEWING_PERIOD_DEFAULT)); |
|
|
|
deadBroadcastViewingMinutes = Long.parseLong(periodStr); |
|
|
|
clock_24hr_resume = config.getProperty("clock_24hr_resume", ""); |
|
|
|
clock_24hr_pause = config.getProperty("clock_24hr_pause", ""); |
|
|
|
clock_24hr_resume = config.getProperty(CLOCK_24HR_RESUME_KEY, ""); |
|
|
|
clock_24hr_pause = config.getProperty(CLOCK_24HR_PAUSE_KEY, ""); |
|
|
|
Thread clock_24hr; |
|
|
|
|
|
|
|
CommonLogger.startup.info(String.format("Dead broadcast viewing period: %d minutes", deadBroadcastViewingMinutes)); |
|
|
|
@@ -417,6 +424,10 @@ public abstract class CommEngine extends HttpServlet |
|
|
|
{ |
|
|
|
resumeBroadcast(request, out); |
|
|
|
} |
|
|
|
else if (get.equalsIgnoreCase("configure")) |
|
|
|
{ |
|
|
|
configure(request, out); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
out.write(get + " not supported"); |
|
|
|
@@ -429,12 +440,13 @@ public abstract class CommEngine extends HttpServlet |
|
|
|
// Get broadcastId from request |
|
|
|
String broadcastId = getBroadcastId(request); |
|
|
|
Broadcast broadcast = broadcasts.get(broadcastId); |
|
|
|
String reason = request.getParameter("reason"); |
|
|
|
if (broadcast == null) |
|
|
|
{ |
|
|
|
out.format("Broadcast %s does not exist", broadcastId); |
|
|
|
return; |
|
|
|
} |
|
|
|
broadcast.cancel(out); |
|
|
|
broadcast.cancel(reason, out); |
|
|
|
} |
|
|
|
|
|
|
|
protected void pauseBroadcast(HttpServletRequest request, PrintWriter out) |
|
|
|
@@ -442,12 +454,13 @@ public abstract class CommEngine extends HttpServlet |
|
|
|
// Get broadcastId from request |
|
|
|
String broadcastId = getBroadcastId(request); |
|
|
|
Broadcast broadcast = broadcasts.get(broadcastId); |
|
|
|
String reason = request.getParameter("reason"); |
|
|
|
if (broadcast == null) |
|
|
|
{ |
|
|
|
out.format("Broadcast %s does not exist", broadcastId); |
|
|
|
return; |
|
|
|
} |
|
|
|
broadcast.pause(out); |
|
|
|
broadcast.pause(reason, out); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@@ -456,12 +469,43 @@ public abstract class CommEngine extends HttpServlet |
|
|
|
// Get broadcastId from request |
|
|
|
String broadcastId = getBroadcastId(request); |
|
|
|
Broadcast broadcast = broadcasts.get(broadcastId); |
|
|
|
String reason = request.getParameter("reason"); |
|
|
|
if (broadcast == null) |
|
|
|
{ |
|
|
|
out.format("Broadcast %s does not exist", broadcastId); |
|
|
|
return; |
|
|
|
} |
|
|
|
broadcast.resume(out); |
|
|
|
broadcast.resume(reason, out); |
|
|
|
} |
|
|
|
|
|
|
|
protected void configure(HttpServletRequest request, PrintWriter out) { |
|
|
|
String jsonData = request.getParameter("data"); |
|
|
|
System.out.println("jsonData: " + jsonData); |
|
|
|
JSONParser parser = new JSONParser(); |
|
|
|
try { |
|
|
|
JSONObject jsonObject = (JSONObject) parser.parse(new StringReader(jsonData)); |
|
|
|
System.out.println(jsonObject); |
|
|
|
|
|
|
|
String valueStr; |
|
|
|
|
|
|
|
// clock_24hr_pause |
|
|
|
valueStr = (String) jsonObject.get(CLOCK_24HR_PAUSE_KEY); |
|
|
|
if (valueStr != null && valueStr.length() == 5) { |
|
|
|
clock_24hr_pause = valueStr; |
|
|
|
out.println("clock_24hr_pause updated."); |
|
|
|
} |
|
|
|
|
|
|
|
// clock_24hr_pause |
|
|
|
valueStr = (String) jsonObject.get(CLOCK_24HR_RESUME_KEY); |
|
|
|
if (valueStr != null && valueStr.length() == 5) { |
|
|
|
clock_24hr_resume = valueStr; |
|
|
|
out.println("clock_24hr_resume updated."); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
out.println("Error - " + e.getMessage()); |
|
|
|
myLogger.error(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -516,7 +560,11 @@ public abstract class CommEngine extends HttpServlet |
|
|
|
{ |
|
|
|
out.write(broadcast.mkStatusReport()); |
|
|
|
} |
|
|
|
out.write("<job_summary completed='" + getCompletedJobCount() + "' pending='" + getPendingJobCount() + "' active='" + getActiveJobCount() + "'/>"); |
|
|
|
out.write("<job_summary completed='" + getCompletedJobCount() + "' pending='" + getPendingJobCount() + "' active='" + getActiveJobCount() + "'/>\n"); |
|
|
|
out.write("<configuration>\n"); |
|
|
|
out.write("<" + CLOCK_24HR_PAUSE_KEY + ">" + clock_24hr_pause + "</" + CLOCK_24HR_PAUSE_KEY + ">\n"); |
|
|
|
out.write("<" + CLOCK_24HR_RESUME_KEY + ">" + clock_24hr_resume + "</" + CLOCK_24HR_RESUME_KEY + ">\n"); |
|
|
|
out.write("</configuration>\n"); |
|
|
|
out.write("</" + tag + ">"); |
|
|
|
} |
|
|
|
} |
|
|
|
|