Question

Our Java application makes background file transfer to a server. When the user wish to add a bunch of documents to the server and do something else with other applications, App Nap becomes active and slow down the window with the progress bar and the network transfert speed.

One solution is too opt out the entire application from App Nap, but it would be great if we could exclude some Java threads from being slowed down.

I am not sure how we could integrate the functionality of NSProcessInfo into Java...

Anybody have tried to do such thing from Java? Any ideas?

Thanks!

Was it helpful?

Solution

The following class From here uses the Java-Objective-C Bridge to integrate NSProcessInfo functionality from Java.

import ca.weblite.objc.Client;
import ca.weblite.objc.Proxy;

/**
 * From https://github.com/shannah/Java-Objective-C-Bridge/blob/master/java/test/ca/weblite/objc/NSProcessInfoUtils.java
 */
public class NSProcessInfoUtils {

    private final static long NSActivityUserInitiated = (0x00FFFFFFL | (1L << 20));

    /**
     * To ensure Mac OS X doesn't slow down your app because of App Nap, call this method 
     * @param reason the reason for allowing the app to work at full speed
     * @return the activity id as a Proxy object
     */
    public static Proxy beginActivityWithOptions(String reason) {

        Client c = Client.getInstance();
        Proxy processInfo = c.sendProxy("NSProcessInfo", "processInfo");
        return processInfo.sendProxy("beginActivityWithOptions:reason:", NSActivityUserInitiated, reason);
    }

    /**
     * When the activity is finished, to re-enable app napping call this method 
     * @param activity previously returned by beginActivityWithOptions()
     */
    public static void endActivity(Proxy activity) {

        if (activity != null) {
            Client c = Client.getInstance();
            Proxy processInfo = c.sendProxy("NSProcessInfo", "processInfo");
            processInfo.send("endActivity:", activity);
        }
    }
}

Disclaimer: I'm the author of the Java-objective-c bridge

OTHER TIPS

I am the author of the referenced app nap post, found this via track back analytics. I am not familiar with Java development, however the link below may provide a method to access NSProcessInfo in the recommended manner. Interested to see what you find.

https://code.google.com/p/rococoa/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top