kyawsanhtoowin / roottools

Automatically exported from code.google.com/p/roottools
1 stars 0 forks source link

The method waitForFinish() is undefined for the type Command #51

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Get this source code: 
https://github.com/MohammadAG/galaxy-usb-mass-storage-enabler

2. Add RootTools 3.3

3. Observe the errors: 

- Description   Resource    Path    Location    Type
The method waitForFinish() is undefined for the type 
Command MainActivity.java   /SamsungUSBMassStorageEnabler/src/com/mohammadag/samsu
ngusbmassstorageenabler line 71 Java Problem

- Description   Resource    Path    Location    Type
The method exitCode() is undefined for the type 
CommandCapture  MainActivity.java   /SamsungUSBMassStorageEnabler/src/com/mohammada
g/samsungusbmassstorageenabler  line 392    Java Problem

Original issue reported on code.google.com by coldpizz...@gmail.com on 7 Oct 2013 at 4:58

GoogleCodeExporter commented 9 years ago
waitForFinish is not in v3.3, it has been removed since the beta version of 3.0 
since it promotes the poor practice of locking the thread.

If you must block the thread, you can implement this functionality yourself. 
Look at this post:https://code.google.com/p/roottools/issues/detail?id=50&can=1 

Original comment by Stericso...@gmail.com on 7 Oct 2013 at 5:46

GoogleCodeExporter commented 9 years ago
Furthermore, you can add a function like this:

private void commandWait(Command cmd) throws Exception {

        while (!cmd.isFinished()) {

            synchronized (cmd) {
                try {
                    if (!cmd.isFinished()) {
                        cmd.wait(2000);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

Original comment by Stericso...@gmail.com on 7 Oct 2013 at 5:50

GoogleCodeExporter commented 9 years ago
In case I want the source code to preserve it as is, I guess should be 
downloading an older version of RootTools. Could you please point me to the 
newest version which has waitForFinish?

Original comment by coldpizz...@gmail.com on 7 Oct 2013 at 5:50

GoogleCodeExporter commented 9 years ago
The version 2.6 still has waitForFinish

https://code.google.com/p/roottools/downloads/detail?name=RootTools2.6.jar&can=4
&q=#makechanges

Original comment by Stericso...@gmail.com on 7 Oct 2013 at 5:54

GoogleCodeExporter commented 9 years ago
Thank you so much. It worked flawlessly.

Original comment by coldpizz...@gmail.com on 7 Oct 2013 at 7:28

GoogleCodeExporter commented 9 years ago
I've extended Stephen's solution a bit, added aging:

    private void commandWait(Command cmd) throws Exception {
        int waitTill = 50;
        int waitTillMultiplier = 2;
        int waitTillLimit = 3200; //7 tries, 6350 msec

        while (!cmd.isFinished() && waitTill<=waitTillLimit) {
            synchronized (cmd) {
                try {
                    if (!cmd.isFinished()) {
                        cmd.wait(waitTill);
                        waitTill *= waitTillMultiplier;
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        if (!cmd.isFinished()){
            Log.e(LOG_TAG, "Could not finish root command in " + (waitTill/waitTillMultiplier));
        }
    }

Original comment by materem...@gmail.com on 4 Nov 2013 at 2:47

GoogleCodeExporter commented 9 years ago
What I generally do, although I did not show it in my example is to divide the 
command timeout into fours and then make the command timeout the max.

Original comment by Stericso...@gmail.com on 4 Nov 2013 at 2:50

GoogleCodeExporter commented 9 years ago
It would be good i thing to let a method or an explanation of how to do it on 
the wiki. :)

Original comment by burn2....@gmail.com on 8 Nov 2013 at 9:47