*/
public void lockSone(Sone sone) {
synchronized (lockedSones) {
- lockedSones.add(sone);
+ if (lockedSones.add(sone)) {
+ coreListenerManager.fireSoneLocked(sone);
+ }
}
}
*/
public void unlockSone(Sone sone) {
synchronized (lockedSones) {
- lockedSones.remove(sone);
+ if (lockedSones.remove(sone)) {
+ coreListenerManager.fireSoneUnlocked(sone);
+ }
}
}
}
}
+ /**
+ * Notifies all listeners that the given Sone was locked.
+ *
+ * @see CoreListener#soneLocked(Sone)
+ * @param sone
+ * The Sone that was locked
+ */
+ void fireSoneLocked(Sone sone) {
+ for (CoreListener coreListener : getListeners()) {
+ coreListener.soneLocked(sone);
+ }
+ }
+
+ /**
+ * Notifies all listeners that the given Sone was unlocked.
+ *
+ * @see CoreListener#soneUnlocked(Sone)
+ * @param sone
+ * The Sone that was unlocked
+ */
+ void fireSoneUnlocked(Sone sone) {
+ for (CoreListener coreListener : getListeners()) {
+ coreListener.soneUnlocked(sone);
+ }
+ }
+
}
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
/** The “Sone rescued” notification. */
private final ListNotification<Sone> sonesRescuedNotification;
+ /** Sone locked notification ticker objects. */
+ private final Map<Sone, Object> lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap<Sone, Object>());
+
+ /** The “Sone locked” notification. */
+ private final ListNotification<Sone> lockedSonesNotification;
+
/**
* Creates a new web interface.
*
Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html"));
sonesRescuedNotification = new ListNotification<Sone>("sones-rescued-notification", "sones", sonesRescuedTemplate);
+
+ Template lockedSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/lockedSonesNotification.html"));
+ lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
}
//
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public void soneLocked(final Sone sone) {
+ Object tickerObject = Ticker.getInstance().registerEvent(System.currentTimeMillis() + (5 * 60) * 1000, new Runnable() {
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ lockedSonesNotification.add(sone);
+ notificationManager.addNotification(lockedSonesNotification);
+ }
+ }, "Sone Locked Notification");
+ lockedSonesTickerObjects.put(sone, tickerObject);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void soneUnlocked(Sone sone) {
+ Object tickerObject = lockedSonesTickerObjects.remove(sone);
+ if (tickerObject == null) {
+ return;
+ }
+ lockedSonesNotification.remove(sone);
+ Ticker.getInstance().deregisterEvent(tickerObject);
+ }
+
+ /**
* Template provider implementation that uses
* {@link WebInterface#createReader(String)} to load templates for
* inclusion.