Class MathLinkFactory


  • public class MathLinkFactory
    extends java.lang.Object
    MathLinkFactory is the class that is used to construct objects of the various link interfaces (MathLink, KernelLink, and LoopbackLink). Because these are interfaces, not classes, and the actual classes that implement them are deliberately unknown to the client, "factory" methods are needed to create the actual objects used.

    Most programmers will use createKernelLink() instead of createMathLink().

    These methods correspond to calling one of the MLOpen functions in the C-language MathLink API.

    • Constructor Detail

      • MathLinkFactory

        public MathLinkFactory()
    • Method Detail

      • createKernelLink

        public static KernelLink createKernelLink​(java.lang.String cmdLine)
                                           throws MathLinkException
        Creates a KernelLink. The argument is a string that follows the same specification as in the C-language function MLOpenString, as documented in the Mathematica book.

        Here are some examples:

         // Typical launch on Windows
         KernelLink ml =
             MathLinkFactory.createKernelLink("-linkmode launch -linkname 'c:\\program files\\wolfram research\\mathematica\\5.1\\mathkernel.exe'");
         

        // Typical launch on Unix KernelLink ml = MathLinkFactory.createKernelLink("-linkmode launch -linkname 'math -mathlink'");

        // Typical launch on Mac OS X KernelLink ml = MathLinkFactory.createKernelLink("-linkmode launch -linkname '\"/Applications/Mathematica 5.1.app/Contents/MacOS/MathKernel\" -mathlink'");

        // Typical "listen" link on any platform: KernelLink ml = MathLinkFactory.createKernelLink("-linkmode listen -linkname 1234 -linkprotocol tcp"); // Windows can use the default protocol for listen/connect links: KernelLink ml = MathLinkFactory.createKernelLink("-linkmode listen -linkname foo");

        Parameters:
        cmdLine - a string parsed as a command line
        Returns:
        the KernelLink
        Throws:
        MathLinkException - if the link fails to open
      • createKernelLink

        public static KernelLink createKernelLink​(java.lang.String[] argv)
                                           throws MathLinkException
        Creates a KernelLink. The argument is an array of strings that follows the same specification as in the C-language function MLOpenArgv, as documented in the Mathematica book.

        Here are some example argv arrays:

         // Typical launch on Windows:
         String[] argv = {"-linkmode", "launch", "-linkname",
         "c:\\program files\\wolfram research\\mathematica\\5.1\\mathkernel.exe"};
         

        // Typical launch on UNIX: String[] argv = {"-linkmode", "launch", "-linkname", "math -mathlink"};

        // Typical launch on Mac OS X: String[] argv = {"-linkmode", "launch", "-linkname", "\"/Applications/Mathematica 5.1.app/Contents/MacOS/MathKernel\" -mathlink"};

        // Typical "listen" link on any platform: String[] argv = {"-linkmode", "listen", "-linkname", "1234", "-linkprotocol", "tcp"};

        // Windows can use the default protocol for listen/connect links: String[] argv = {"-linkmode", "listen", "-linkname", "foo"};

        Parameters:
        argv - an array of string arguments
        Returns:
        the KernelLink
        Throws:
        MathLinkException - if the link fails to open
      • createKernelLink

        public static KernelLink createKernelLink​(MathLink ml)
                                           throws MathLinkException
        Creates a KernelLink by wrapping a MathLink. This method is primarily of use to developers who want to create their own implementations of the MathLink interface, for example one based on CORBA rather than the native protocols used by the MathLink library. All you have to do is implement MathLink; KernelLink is free because there is an internal KernelLink implementation class that can do everything by manipulating a MathLink instance. This is the method that creates such a KernelLink.

        You give up ownership of the MathLink you pass in, meaning that it can only be used, including being closed, by the KernelLink.

        Parameters:
        ml - the MathLink to wrap
        Returns:
        the KernelLink
        Throws:
        MathLinkException
      • createMathLink

        public static MathLink createMathLink​(java.lang.String cmdLine)
                                       throws MathLinkException
        Creates a MathLink. The argument is a string that follows the same specification as in the C-language function MLOpenString, as documented in the Mathematica book.

        Most programmers will use createKernelLink() instead, because they want to work with the higher-level KernelLink interface, not MathLink.

        Here is an example:

         MathLinkFactory.createMathLink("-linkmode listen -linkname 1234 -linkprotocol tcp");
        Parameters:
        cmdLine - a string parsed as a command line
        Returns:
        the MathLink
        Throws:
        MathLinkException - if the link does not open correctly
        See Also:
        createKernelLink(String)
      • createMathLink

        public static MathLink createMathLink​(java.lang.String[] argv)
                                       throws MathLinkException
        Creates a MathLink. The argument is an array of strings that follows the same specification as in the C-language function MLOpenArgv, as documented in the Mathematica book.

        Most programmers will use createKernelLink() instead, because they want to work with the higher-level KernelLink interface, not MathLink.

        Here is an example:

         String[] argv = {"-linkmode", "listen", "-linkname", "1234", "-linkprotocol", "tcp"};
         MathLinkFactory.createMathLink(argv);
        Parameters:
        argv - an array of string arguments
        Returns:
        the MathLink
        Throws:
        MathLinkException - if the link does not open correctly
        See Also:
        createKernelLink(String[])