diff --git a/README b/README index 5160d54..e387dba 100644 --- a/README +++ b/README @@ -20,3 +20,7 @@ then browse to: http://localhost:9090/jee6webapp +------------------------------------------------ +NB at the current time you will need to obtain the unreleased DWR JAR from http://java.net/projects/dwr/downloads/download/DWR_3.x/3.0_RC2/dwr.jar and set it up in your local repository as it appears in the POM. + + diff --git a/pom.xml b/pom.xml index cfe767a..2a2fdd9 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ The Pond Ian Smith m4r35n357@gmail.com - http://server:6060/nexus/content/repositories + http://sumo:8080/nexus/content/repositories 1.6 3.1 2.7.1 @@ -53,13 +53,13 @@ site - file:///net/qnap/Public/JavaEe6WebApp/ + file:///net/nas/Public/JavaEe6WebApp/ - Hudson - http://server:7070/job/JEE%206%20Web%20App/ + Jenkins + http://sumo:8080/jenkins/job/JavaEe6WebApp/ @@ -157,26 +157,26 @@ - - - - - - - - - - - - - - - - - - - - + + commons-logging + commons-logging + 1.1.1 + api + + + + commons-logging + commons-logging + 1.1.1 + adapters + + + + org.directwebremoting + dwr + 3.0.RC2 + compile + org.glassfish.extras diff --git a/populateDb b/populateDb index 18d4a44..56ec388 100755 --- a/populateDb +++ b/populateDb @@ -2,7 +2,7 @@ host="${1:-localhost}" port="${2:-9090}" -contentRoot="${3:-/home/*/QNAP/Public/Freecom400GB/jukebox/playlist}" +contentRoot="${3:-/home/*/SHARED/nas/Public/Freecom400GB/jukebox/playlist}" resources="http://$host:$port/jee6webapp/resources" content='Content-Type: application/json' diff --git a/settings.xml b/settings.xml deleted file mode 100644 index 0c3e44a..0000000 --- a/settings.xml +++ /dev/null @@ -1,408 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - org.jboss.maven.plugins - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - jboss-public-repository - - - jboss-public-repository-group - JBoss Public Maven Repository Group - https://repository.jboss.org/nexus/content/groups/public/ - default - - true - never - - - true - never - - - - - - jboss-public-repository-group - JBoss Public Maven Repository Group - https://repository.jboss.org/nexus/content/groups/public/ - default - - true - never - - - true - never - - - - - - - java-ee-6 - - - maven2-repository.dev.java.net - Java.net Repository for Maven - http://download.java.net/maven/2/ - default - - - maven2-glassfish-repository.dev.java.net - Java.net Repository for Maven - http://download.java.net/maven/glassfish/ - - - maven-repository.dev.java.net - Java.net Maven 1 Repository (legacy) - http://download.java.net/maven/1 - legacy - - - - - - maven-repository.dev.java.net - Java.net Maven 1 Repository (legacy) - http://download.java.net/maven/1 - legacy - - - glassfish-repository - Java.net Repository for Glassfish - http://download.java.net/maven/glassfish - - - maven2-repository.dev.java.net - Java.net Repository for Maven - http://download.java.net/maven/2/ - default - - - java.net - GlassFish Maven Repository - http://download.java.net/maven/glassfish - - - java.net2 - Repository hosting the jee6 artifacts - http://download.java.net/maven/2 - - - Eclipse Repo - http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo - - - prime-repo - Prime Technology Maven Repository - http://repository.prime.com.tr - default - - - - - - google - - - gson - http://google-gson.googlecode.com/svn/mavenrepo - - true - - - true - - - - - - - - - java-ee-6 - jboss-public-repository - google - - - diff --git a/src/main/java/uk/me/doitto/webapp/util/Clock.java b/src/main/java/uk/me/doitto/webapp/util/Clock.java index 9e743a8..01fa3f8 100644 --- a/src/main/java/uk/me/doitto/webapp/util/Clock.java +++ b/src/main/java/uk/me/doitto/webapp/util/Clock.java @@ -4,54 +4,117 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -//import org.directwebremoting.Browser; -//import org.directwebremoting.ServerContextFactory; -//import org.directwebremoting.ui.dwr.Util; +import org.directwebremoting.Browser; +import org.directwebremoting.ScriptSession; +import org.directwebremoting.ScriptSessionFilter; +import org.directwebremoting.ScriptSessions; +import org.directwebremoting.WebContextFactory; +import org.directwebremoting.impl.DaemonThreadFactory; +import org.directwebremoting.ui.dwr.Util; /** * Created by DWR + * * @author super - * + * */ public class Clock implements Runnable { - - protected transient boolean active = false; - - public Clock () { - new ScheduledThreadPoolExecutor(1).scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS); + /** + * Create a schedule to update the clock every second. + */ + public Clock() { + ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory()); + executor.scheduleAtFixedRate(this, 1, 50, TimeUnit.MILLISECONDS); } - @Override - public synchronized void run () { + /* + * (non-Javadoc) + * + * @see java.lang.Runnable#run() + */ + public void run() { if (active) { - setClockDisplay(new Date().toString()); + String newTimeString = new Date().toString(); + // We check this has not already been sent to avoid duplicate + // transmissions + if (!newTimeString.equals(timeString)) { + setClockDisplay(newTimeString); + timeString = newTimeString; + } } } /** * Called from the client to turn the clock on/off */ - public synchronized void toggle () { + public synchronized void toggle() { active = !active; - if (active) { - setClockDisplay("Started"); - } else { - setClockDisplay("Stopped"); + setClockStatus(); + } + + private class UpdatesEnabledFilter implements ScriptSessionFilter { + private String attrName; + + public UpdatesEnabledFilter(String attrName) { + this.attrName = attrName; + } + + public boolean match(ScriptSession ss) { + Object check = ss.getAttribute(attrName); + return (check != null && check.equals(Boolean.TRUE)); } } /** - * Actually alter the clients. + * Call a function on the client for each ScriptSession. passing the clock's + * status for display. * * @param output * The string to display. */ - public void setClockDisplay (final String output) { -// Browser.withPage(ServerContextFactory.get().getContextPath() + "/", new Runnable() { -// @Override -// public void run() { -// Util.setValue("clockDisplay", output); -// } -// }); + public void setClockStatus() { + Browser.withAllSessions(new Runnable() { + public void run() { + ScriptSessions.addFunctionCall("setClockStatus()", active); +// ScriptSessions.addFunctionCall("updatePollStatus()", active); + } + }); } + + /** + * Send the time String to clients that have an UPDATES_ENABLED_ATTR + * attribute set to true on their ScriptSession. + * + * @param output + * The string to display. + */ + public void setClockDisplay(final String output) { + Browser.withAllSessionsFiltered(new UpdatesEnabledFilter(UPDATES_ENABLED_ATTR), new Runnable() { + public void run() { + Util.setValue("clockDisplay", output); + } + }); + } + + /** + * + * @param enabled + */ + public void setEnabledAttribute(Boolean enabled) { + ScriptSession scriptSession = WebContextFactory.get().getScriptSession(); + scriptSession.setAttribute(UPDATES_ENABLED_ATTR, enabled); + } + + private static String UPDATES_ENABLED_ATTR = "UPDATES_ENABLED"; + + /** + * Are we updating the clocks on all the pages? + */ + protected transient boolean active = false; + + /** + * The last time string + */ + protected String timeString = ""; + } \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/dwr.xml b/src/main/webapp/WEB-INF/dwr.xml index b23fff8..fae1b71 100644 --- a/src/main/webapp/WEB-INF/dwr.xml +++ b/src/main/webapp/WEB-INF/dwr.xml @@ -2,7 +2,7 @@ - + @@ -17,16 +17,16 @@ - + - + - + - + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index c278b77..8a699b3 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -23,7 +23,7 @@ javax.faces.PROJECT_STAGE - Development + Production @@ -46,39 +46,43 @@ /resources/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + DWR Servlet + dwr-invoker + org.directwebremoting.servlet.DwrServlet + + activeReverseAjaxEnabled + true + + + maxWaitAfterWrite + 1000 + + + crossDomainSessionSecurity + false + + + accessLogLevel + CALL + + + jsonpEnabled + false + + + allowScriptTagRemoting + true + + + debug + true + + + + dwr-invoker + /dwr/* + 30 diff --git a/src/main/webapp/resources/js/clockdwr.js b/src/main/webapp/resources/js/clockdwr.js new file mode 100644 index 0000000..b6df187 --- /dev/null +++ b/src/main/webapp/resources/js/clockdwr.js @@ -0,0 +1,34 @@ +/*jslint white: true, browser: true, safe: true */ + +"use strict"; + +window.onload = function () { + dwr.engine.setActiveReverseAjax(true); + dwr.engine.setErrorHandler(errorHandler); + dwr.engine.setPollStatusHandler(updatePollStatus); + updatePollStatus(true); + Tabs.init('tabList', 'tabContents'); + Clock.setClockStatus(); +} + +function errorHandler (message, ex) { + dwr.util.setValue("error", "Cannot connect to server. Initializing retry logic.", { escapeHtml : false }); + setTimeout(function() { + dwr.util.setValue("error", ""); + }, 5000); +} + +function updatePollStatus (pollStatus) { + dwr.util.setValue("pollStatus", pollStatus ? "Online" : "Offline", { escapeHtml : false }); +} + +function enableUpdates (enabled) { + if (!enabled) { + dwr.util.setValue("clockDisplay", "This tab/window does not have updates enabled."); + } + Clock.setEnabledAttribute(enabled); +} + +function setClockStatus (clockStatus) { + dwr.util.setValue("clockStatus", clockStatus ? "Clock started" : "Clock stopped"); +} diff --git a/src/main/webapp/template.xhtml b/src/main/webapp/template.xhtml index 3dd3db2..cca4ada 100644 --- a/src/main/webapp/template.xhtml +++ b/src/main/webapp/template.xhtml @@ -34,27 +34,28 @@ - - - + + + + Facelets Template - + - +
@@ -97,17 +94,26 @@
- - -
+ + + +