|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.wolfram.jlink.StdLink
StdLink contains two methods that you use to interact with the link back to the kernel in cases where Java is "installed" into Mathematica (that is, InstallJava[] has been called in the Mathematica session). The getLink() method returns this link, and requestTransaction() must be called from the user-interface thread before calling into Mathematica.
You never create or use an instance of StdLink; it simply is a container for some methods and state related to the link back to the kernel. The name is inspired by the 'stdlink' global variable that holds the link in C-language "installable" MathLink programs generated by the mprep tool.
| Constructor Summary | |
StdLink()
|
|
| Method Summary | |
static com.wolfram.jlink.KernelLink |
getLink()
When called during a session when Java is "installed" into Mathematica (i.e., InstallJava[] has been called in Mathematica), getLink() returns the KernelLink that points back to Mathematica. |
static void |
requestTransaction()
Must be called from code that calls into Mathematica from the user-interface thread. |
static void |
setLink(com.wolfram.jlink.KernelLink ml)
Sets the link that will be returned by getLink() when the program is not in the middle of a call from Mathematica. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public StdLink()
| Method Detail |
public static com.wolfram.jlink.KernelLink getLink()
Here is an example of how it might be called in a method that wants to return a result to Mathematica manually, instead of having its normal return value sent back.
KernelLink link = StdLink.getLink();
if (link != null) {
link.beginManual();
... code here to put a result to Mathematica
}
public static void setLink(com.wolfram.jlink.KernelLink ml)
ml - public static void requestTransaction()
If you are writing a "listener"-type class (i.e., one that implements java.util.EventListener) that calls into Mathematica as a result of some user action on the user-interface thread, you should consider making your class a subclass of MathListener. The MathListener class handles all the details of the interaction with Mathematica for you, including calling requestTransaction().
Here is a typical example of code that calls requestTransaction(). Note that the code that sends the evaluation and reads the answer must still be in a synchronized block. This synchronization solves a different problem than requestTransaction(). Make sure you enter the synchronized block after requestTransaction(), or the user-interface thread will hang forever.
KernelLink ml = StdLink.getLink();
StdLink.requestTransaction();
synchronized (ml) {
try {
ml.evaluate("buttonClickFunction[]");
ml.discardAnswer();
// evaluate() sends an EvaluatePacket. You could also send the EvaluatePacket manually:
//ml.putFunction("EvaluatePacket", 1);
//ml.putFunction("ToExpression", 1);
//ml.put("buttonClickFunction[]");
//ml.discardAnswer();
} catch (MathLinkException e) {}
}
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||