PhilipsHue / PhilipsHueSDK-Java-MultiPlatform-Android

The Software Development Kit for Philips Hue Java Mulfi-Platform and Android (beta)
273 stars 214 forks source link

Program Dangling? (Thread still active) #21

Closed xander-io closed 9 years ago

xander-io commented 9 years ago

Hello,

I think this is going back to a previous issue listed here - https://github.com/PhilipsHue/PhilipsHueSDK-Java-MultiPlatform-Android/issues/13.

I have built a java program where I want to change a few configurations on the lights. To keep it as relevant as possible, here is the following code I altered from the original Java Desktop App:

 private PHSDKListener listener = new PHSDKListener() {

        @Override
        public void onAccessPointsFound(List<PHAccessPoint> accessPointsList) {
            System.out.println("INFO: Found Access Points! Using the first one");

            // Get the first Access Point listed
            phHueSDK.connect(accessPointsList.get(0));
        }

        @Override
        public void onAuthenticationRequired(PHAccessPoint accessPoint) {
            // Start the Pushlink Authentication.
            System.out.println("INFO: Press the link button on the bridge to authenticate");
            phHueSDK.startPushlinkAuthentication(accessPoint);
        }

        @Override
        public void onBridgeConnected(PHBridge bridge, String username) {           
            phHueSDK.stopPushlinkAuthentication();

            System.out.println("Connected to the bridge!");

            phHueSDK.setSelectedBridge(bridge);
            phHueSDK.enableHeartbeat(bridge, PHHueSDK.HB_INTERVAL);
            String lastIpAddress =  bridge.getResourceCache().getBridgeConfiguration().getIpAddress();   
            HueProperties.storeUsername(username);
            HueProperties.storeLastIPAddress(lastIpAddress);
            HueProperties.saveProperties();

            randomLights();

            phHueSDK.disableAllHeartbeat();
            phHueSDK.destroySDK();
        }

        ...

As you can see in the "onBridgeConnected()", I want to run the "randomLights()" method as soon as I am connected to the bridge and then immediately close the SDK and exit the program. I found that if the properties are saved in a separate file, this works completely fine. However, if I run this for the very first time where I have to to push the link button for authentication, the program dangles and does not exit. Any suggestions on how to fix this issue? I know I can use System.exit() but feel that this is the unclean version of how to fix the issue.

Thank you, Zack

SteveyO commented 9 years ago

Hi Zack,

Thanks for reporting this in detail. I have just written a little test program and I was able to reproduce the issue. It looks like a bug in the SDK as when you run the above code for the first time, the destroySDK method is not killing off the pushlink thread. So very similar issue to #13.

I will raise an internal ticket to get this fixed, and let you know when I have more detail on the expected fix date.

Thanks Steve

xander-io commented 9 years ago

Steve,

If I can be of any more assistance please feel free to reach out to me!

Thank you for fixing the issue and I look forward to hearing back from you with the solution.

Sincerely, Zack On Aug 17, 2015 9:23 AM, "Steve" notifications@github.com wrote:

Hi Zack,

Thanks for reporting this in detail. I have just written a little test program and I was able to reproduce the issue. It looks like a bug in the SDK as when you run the above code for the first time, the destroySDK method is not killing off the pushlink thread. So very similar issue to

13

https://github.com/PhilipsHue/PhilipsHueSDK-Java-MultiPlatform-Android/issues/13 .

I will raise an internal ticket to get this fixed, and let you know when I have more detail on the expected fix date.

Thanks Steve

— Reply to this email directly or view it on GitHub https://github.com/PhilipsHue/PhilipsHueSDK-Java-MultiPlatform-Android/issues/21#issuecomment-131817294 .

xander-io commented 9 years ago

Hi Steve,

Any updates on when this bug will be fixed?

Thanks, Zack

SteveyO commented 9 years ago

Hi Zack, I will have an in-depth look this afternoon and get back to you. I have been away for a few days and just clearing the backlog of tasks. I should know some more a bit later or tomorrow. Steve

Edit - I have managed to fixed this internally. The Push Linking thread is now killed after the user is authenticated on the bridge (and Destroy SDK now works). Will need to go through a little internal QA before we can release it, I will let you know.

SteveyO commented 9 years ago

Hi Zack,

I have just committed a fix in the new SDK (v. 1.8.2). If you pull in the huelocalsdk.jar (from either QuickStart or JavaDesktop libs folder) the SDK should now be killed correctly if Pushlinking has been run.

I will close the issue, so let me know if you have any issues, in which case I will re-open it.

Steve