From cf655be3048cf1f9123af661455983f17f4ae5bc Mon Sep 17 00:00:00 2001 From: rtrimana Date: Wed, 22 Feb 2017 09:13:19 -0800 Subject: [PATCH] Reverting back the first benchmark (now works with less threads); synchronization problems with too many threads with arbitrary calls of callbacks at times --- .../CameraCallback_Skeleton.java | 27 ++----------- .../MotionDetection.java | 22 +++++------ .../Java/AmcrestCamera/AmcrestCamera.java | 4 +- .../CameraSmartCallback_Stub.java | 38 ++----------------- benchmarks/interfaces/CameraCallback.java | 4 +- .../interfaces/CameraSmartCallback.java | 4 +- 6 files changed, 24 insertions(+), 75 deletions(-) diff --git a/benchmarks/Java/SmartLightsController/CameraCallback_Skeleton.java b/benchmarks/Java/SmartLightsController/CameraCallback_Skeleton.java index 0e4b30d..7410368 100644 --- a/benchmarks/Java/SmartLightsController/CameraCallback_Skeleton.java +++ b/benchmarks/Java/SmartLightsController/CameraCallback_Skeleton.java @@ -66,33 +66,15 @@ public class CameraCallback_Skeleton implements CameraCallback { return didAlreadyInitWaitInvoke.get(); } - public void newCameraFrameAvailable(CameraSmart _camera) { - mainObj.newCameraFrameAvailable(_camera); + public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) { + mainObj.newCameraFrameAvailable(latestFrame, timeStamp); } public void ___newCameraFrameAvailable() { byte[] localMethodBytes = methodBytes; rmiComm.setGetMethodBytes(); - Object[] paramObj = rmiComm.getMethodParams(new Class[] { int[].class }, new Class[] { null }, localMethodBytes); - try { - int[] stubIdArray0 = (int[]) paramObj[0]; - int objIdRecv0 = stubIdArray0[0]; - CameraSmart newStub0 = null; - if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) { - newStub0 = new CameraSmart_Stub(rmiComm, objIdRecv0); - IoTRMIUtil.mapStub.put(objIdRecv0, newStub0); - rmiComm.setObjectIdCounter(objIdRecv0); - rmiComm.decrementObjectIdCounter(); - } - else { - newStub0 = (CameraSmart_Stub) IoTRMIUtil.mapStub.get(objIdRecv0); - } - CameraSmart stub0 = newStub0; - newCameraFrameAvailable(stub0); - } catch(Exception ex) { - ex.printStackTrace(); - throw new Error("Exception from callback object instantiation!"); - } + Object[] paramObj = rmiComm.getMethodParams(new Class[] { byte[].class, long.class }, new Class[] { null, null }, localMethodBytes); + newCameraFrameAvailable((byte[]) paramObj[0], (long) paramObj[1]); } public void ___waitRequestInvokeMethod() throws IOException { @@ -123,7 +105,6 @@ public class CameraCallback_Skeleton implements CameraCallback { catch (Exception ex) { ex.printStackTrace(); } - //System.out.println("Thread done!"); } }.start(); break; diff --git a/benchmarks/Java/SmartLightsController/MotionDetection.java b/benchmarks/Java/SmartLightsController/MotionDetection.java index 4aa0dc8..3c9567f 100644 --- a/benchmarks/Java/SmartLightsController/MotionDetection.java +++ b/benchmarks/Java/SmartLightsController/MotionDetection.java @@ -257,16 +257,16 @@ class MotionDetection implements CameraCallback { * * @return [void] None. */ - //public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) { - public void newCameraFrameAvailable(CameraSmart _camera) { + public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) { + //public void newCameraFrameAvailable(CameraSmart _camera) { BufferedImage img = null; - // Parse the byte array into a Buffered Image - byte[] newImg = _camera.getLatestFrame(); + //byte[] newImg = _camera.getLatestFrame(); try { //InputStream in = new ByteArrayInputStream(_camera.getLatestFrame()); - //InputStream in = new ByteArrayInputStream(latestFrame); - InputStream in = new ByteArrayInputStream(newImg); + //InputStream in = new ByteArrayInputStream(newImg); + // Parse the byte array into a Buffered Image + InputStream in = new ByteArrayInputStream(latestFrame); img = ImageIO.read(in); } catch (RemoteException e) { @@ -284,8 +284,8 @@ class MotionDetection implements CameraCallback { latestImage = img; // image into image buffer // timestamp from camera into timestamp buffer - //long dateLong = timeStamp; - long dateLong = _camera.getTimestamp(); + long dateLong = timeStamp; + //long dateLong = _camera.getTimestamp(); //System.out.println("dateLong: " + dateLong + " - newImage size: " + newImg.length); possibleDate = new Date(dateLong); @@ -372,9 +372,9 @@ class MotionDetection implements CameraCallback { // calculate the percentage of the image that was in motion double percentMotion = (countMotion / count) * 100.0; - System.out.println("countMotion: " + countMotion); - System.out.println("count: " + count); - System.out.println("Percent motion: " + percentMotion); + //System.out.println("countMotion: " + countMotion); + //System.out.println("count: " + count); + //System.out.println("Percent motion: " + percentMotion); // Check if a high enough percentage of the image was in motion to say that there was motion in this frame of data if (percentMotion > MOTION_DETECTED_THRESHOLD_PERCENTAGE) { diff --git a/benchmarks/drivers/Java/AmcrestCamera/AmcrestCamera.java b/benchmarks/drivers/Java/AmcrestCamera/AmcrestCamera.java index 7d2bb47..ffa92d0 100644 --- a/benchmarks/drivers/Java/AmcrestCamera/AmcrestCamera.java +++ b/benchmarks/drivers/Java/AmcrestCamera/AmcrestCamera.java @@ -464,8 +464,8 @@ public class AmcrestCamera implements Camera { for (CameraSmartCallback c : callbackList) { - //c.newCameraFrameAvailable(this.getLatestFrame(), this.getTimestamp()); - c.newCameraFrameAvailable(this); + c.newCameraFrameAvailable(this.getLatestFrame(), this.getTimestamp()); + //c.newCameraFrameAvailable(this); } } else { diff --git a/benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_Stub.java b/benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_Stub.java index f5270a2..0610f84 100644 --- a/benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_Stub.java +++ b/benchmarks/drivers/Java/AmcrestCamera/CameraSmartCallback_Stub.java @@ -36,43 +36,11 @@ public class CameraSmartCallback_Stub implements CameraSmartCallback { objectId = _objectId; } - public void newCameraFrameAvailable(Camera _camera) { - int[] objIdSent0 = new int[1]; - try { - if (!IoTRMIUtil.mapSkel.containsKey(_camera)) { - int newObjIdSent = rmiComm.getObjectIdCounter(); - objIdSent0[0] = newObjIdSent; - rmiComm.decrementObjectIdCounter(); - Camera_Skeleton skel0 = new Camera_Skeleton(_camera, rmiComm, newObjIdSent); - IoTRMIUtil.mapSkel.put(_camera, skel0); - IoTRMIUtil.mapSkelId.put(_camera, newObjIdSent); - Thread thread = new Thread() { - public void run() { - try { - skel0.___waitRequestInvokeMethod(); - } catch (Exception ex) { - ex.printStackTrace(); - throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for Camera_Skeleton!"); - } - } - }; - thread.start(); - while(!skel0.didAlreadyInitWaitInvoke()); - } - else - { - int newObjIdSent = IoTRMIUtil.mapSkelId.get(_camera); - objIdSent0[0] = newObjIdSent; - } - } catch (Exception ex) { - ex.printStackTrace(); - throw new Error("Exception when generating skeleton objects!"); - } - + public void newCameraFrameAvailable(byte latestFrame[], long timeStamp) { int methodId = 0; Class retType = void.class; - Class[] paramCls = new Class[] { int[].class }; - Object[] paramObj = new Object[] { objIdSent0 }; + Class[] paramCls = new Class[] { byte[].class, long.class }; + Object[] paramObj = new Object[] { latestFrame, timeStamp }; rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); } diff --git a/benchmarks/interfaces/CameraCallback.java b/benchmarks/interfaces/CameraCallback.java index d7b225c..5d5377d 100644 --- a/benchmarks/interfaces/CameraCallback.java +++ b/benchmarks/interfaces/CameraCallback.java @@ -1,6 +1,6 @@ package iotcode.interfaces; public interface CameraCallback { - //public void newCameraFrameAvailable(byte latestFrame[], long timeStamp); - public void newCameraFrameAvailable(CameraSmart _camera); + public void newCameraFrameAvailable(byte latestFrame[], long timeStamp); + //public void newCameraFrameAvailable(CameraSmart _camera); } diff --git a/benchmarks/interfaces/CameraSmartCallback.java b/benchmarks/interfaces/CameraSmartCallback.java index 1f10ecb..3c78a7b 100644 --- a/benchmarks/interfaces/CameraSmartCallback.java +++ b/benchmarks/interfaces/CameraSmartCallback.java @@ -2,6 +2,6 @@ package iotcode.interfaces; public interface CameraSmartCallback { - //public void newCameraFrameAvailable(byte latestFrame[], long timeStamp); - public void newCameraFrameAvailable(Camera _camera); + public void newCameraFrameAvailable(byte latestFrame[], long timeStamp); + //public void newCameraFrameAvailable(Camera _camera); } -- 2.34.1