Use Case: Collect lower level Motion events, correlate them to remove duplicates (e.g., a person walked around a house passes in front of one camera then another), then report the correlated Detection event.
Approach: (see pic) I initiate Motion Events from the video analytics and other sensors which are received and correlated by the AwarenessAnalytics component, which then raises a Detection Event to the Home Automation Main. It is similar to Chain-of-Responsibility pattern, though in reverse with events.
I have defined two completely separate event interfaces in separate files in the same package;
public interface MotionEventListener {
public void motionDetected(MotionEvent event);
public void motionLocation (MotionLocation location);
public void motionCeased(MotionEvent event);
public void eventVideoComplete(String eventId);
}
public interface DetectionEventListener {
public void motionIsDetected(DetectionEvent event);
public void motionAtLocation (MotionLocation location);
public void motionHasCeased(DetectionEvent event);
public void eventVideoNowComplete(String eventId);
}
I create the Motion Events in the VideoAnalytic thread;
private synchronized void fireDetectedEvent() {
Object source = new Object();
alertStartTime = getDateTime();
eventId++;
System.out.println("*** Motion Detected! ***" + alertStartTime + ", eventId = " +
eventId);
// Send alert to listener
String details ="";
MotionEvent event = new MotionEvent(source, alertActive, eventId,
Calendar.getInstance(), cameraId, Classification.unknown, details, alertStartTime);
Iterator i = listeners.iterator();
if (alertActive) {
while(i.hasNext()) {
((MotionEventListener) i.next()).motionDetected(event);
}
} else {
while(i.hasNext()) {
((MotionEventListener) i.next()).motionCeased(event);
}
resetVideoStreamEventCounter = 0;// keeps track of how many video resets occur from one
//event to another
}
}
The Motion events are successfully caught in the AwarenessAnalytic layer, where I createa new Detection Event if there is not already an ongoing event;
public void motionDetected(MotionEvent e) {
System.out.println("Motion Detected Listener activated " + e.getCameraId());
if (alertCounter == 0) {
Object source = new Object();
System.out.println("*** Motion Detected! ***" );
// Send alert to listener
alertCounter++;
alertId++;
alertActive = true;
DetectionEvent event = new DetectionEvent(
source,
alertActive,
alertId,
e.getEventDateTime(),
e.getCameraId(),
e.getEventType(),
e.getKnownDetails(),
e.getEventSubdirectory());
Iterator i = listeners.iterator();
if (alertActive) {
while(i.hasNext()) {
((DetectionEventListener) i.next()).motionDetected(event);
}
} else {
alertCounter++;
}
}
System.out.println("Motion Detected event received by AA from " + e.getCameraId());
}
Design pictorial:
Problem:
I've tried to catch the events in Home Automation Main as follows;
AwarenessAnalytics awarenessAnalytic = new AwarenessAnalytics();
// establish the listener set
awarenessAnalytic.addListener(this);
However, this results in a compilation error "Cannot use this in a static context"
Do I need a separate listener class for this? Or something else?