EngineCallBacks.queryInterrupt - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : Java Application Programming Interface : EngineCallBacks Interface : OpenMaple/Java/EngineCallBacks/queryInterrupt

EngineCallBacks.queryInterrupt

queries if Maple should interrupt computation

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

boolean queryInterrupt( Object data ) throws MapleException

Parameters

data

-

arbitrary data that was passed into the Engine constructor

Description

• 

queryInterrupt is a member function of the com.maplesoft.openmaple.EngineCallBacks interface.  It allows the Java OpenMaple programmer to interrupt the Maple engine during computation.  queryInterrupt is called periodically while the Maple engine is running.  If queryInterrupt returns true then Maple interrupts the computation.

Examples

import com.maplesoft.openmaple.*;

import com.maplesoft.externalcall.MapleException;

class Example

{

    static private class CallBacks implements EngineCallBacks

    {

    double last;

    boolean limitExceeded;

    CallBacks()

    {

        last = 0.0;

        limitExceeded = false;

    }

    public void textCallBack( Object data, int tag, String output )

        throws MapleException

    {

        switch ( tag )

        {

        case MAPLE_TEXT_OUTPUT:

            System.out.print( "Text: " );

            break;

        case MAPLE_TEXT_DIAG:

            System.out.print( "Diag: " );

            break;

        case MAPLE_TEXT_MISC:

            System.out.print( "Misc: " );

            break;

        case MAPLE_TEXT_HELP:

            System.out.print( "Help: " );

            break;

        case MAPLE_TEXT_QUIT:

            System.out.print( "Quit: " );

            break;

        case MAPLE_TEXT_WARNING:

            System.out.print( "Warning: " );

            break;

        case MAPLE_TEXT_DEBUG:

            System.out.print( "Debug: " );

            break;

        }

        System.out.println( output );

    }

    public void errorCallBack( Object data, int offset, String msg )

        throws MapleException

    {

        if ( offset >= 0 )

        {

        throw new MapleException( "Error: "+msg );

        }

        else

        {

        throw new MapleException( "syntax error at offset "+offset+

            ": "+msg );

        }

    }

    public void statusCallBack( Object data, long kbused, long kballoced,

        double timeused )

            throws MapleException

    {

        if ( timeused > 5 )

        {

        limitExceeded = true;

        }

        if ( timeused-last > 1 )

        {

        System.out.println( "Status: used = "+kbused+", alloced = "+

            kballoced+", time = "+timeused );

        last = timeused;

        }

    }

    public String readLineCallBack( Object data, boolean debug )

        throws MapleException

    {

        return "readline";

    }

    public boolean redirectCallBack( Object data, String output, boolean

append )

        throws MapleException

    {

        System.out.println( "redirect to "+output+" append = "+append );

            return true;

    }

    public String callBackCallBack( Object data, String output )

        throws MapleException

    {

        System.out.println( "callback: "+output );

        return output+";";

    }

    public boolean queryInterrupt( Object data )

        throws MapleException

    {

        return limitExceeded;

    }

    public String streamCallBack( Object data, String name, String args[] )

        throws MapleException

    {

        StringBuffer sbuf;

        int i;

        sbuf = new StringBuffer( name );

        for ( i = 0; i < args.length; i++ )

        {

        sbuf.append( args[i] );

        }

        return sbuf.toString();

    }

    }

    public static void main( String notused[] ) throws MapleException

    {

    String mapleArgs[];

    Engine engine;

    Algebraic a;

    int i;

    mapleArgs = new String[1];

    mapleArgs[0] = "java";

    engine = new Engine( mapleArgs, new CallBacks(), null, null );

    for ( i = 0; i < 10000000; i++ )

    {

        a = engine.evaluate( "Array( 1..10^5 ):" );

        if ( a == null )

        {

        break;

        }

        a.dispose();

    }

    System.out.println( "i's value when finished: "+i );

    }

}

Executing this code produces output similar to the following.

Status: used = 45963, alloced = 1503, time = 1.01

Status: used = 105566, alloced = 1503, time = 2.02

Status: used = 164192, alloced = 1503, time = 3.0300000000000002

Status: used = 224771, alloced = 1503, time = 4.05

i's value when finished: 2880

See Also

ExternalCalling/Java/MapleException

OpenMaple

OpenMaple/Java/Engine

OpenMaple/Java/Engine/Engine

OpenMaple/Java/EngineCallBacks

OpenMaple/Java/EngineCallBacksDefault

OpenMaple/Java/EngineCallBacksDefault/queryInterrupt

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam