Importing Components
A JavaPorts component is a task that has a defined port configuration and an underlying implementation in Java or Matlab. JavaPorts components can be reused by importing them from existing applications. Components may also be exported to a library, from which they can then be imported to multiple applications. A bundle tool is provided which allows users to share components by automatically collecting all necessary supporting files for a component into a JAR archive file.
The following examples illustrate these various methods for reusing JavaPorts components.
Import from Application (single user)
The following configuration file demonstrates how a component may be imported from an existing application.
BEGIN CONFIGURATION
BEGIN DEFINITIONS
DEFINE APPLICATION "Mandelbrot"
DEFINE MACHINE M1="oak" MASTER
DEFINE MACHINE M2="pine"
DEFINE MACHINE M3="elm"
DEFINE MACHINE M4="maple"
DEFINE TASK T1="Display" NUMOFPORTS=1
DEFINE TASK T2="DynamicManager" NUMOFPORTS=4
DEFINE TASK T3="MandelbrotWorker" NUMOFPORTS=1
DEFINE TASK T4="MandelbrotWorker" NUMOFPORTS=1
IMPORT COMPONENT T5="UserApp2/MMWorker" NUMOFPORTS=1 MATLAB
END DEFINITIONS
BEGIN ALLOCATIONS
ALLOCATE T1 M1
ALLOCATE T2 M2
ALLOCATE T3 M3
ALLOCATE T4 M3
ALLOCATE T5 M4
END ALLOCATIONS
BEGIN CONNECTIONS
CONNECT T1.P[0] T2.P[0]
CONNECT T2.P[1] T3.P[0]
CONNECT T2.P[2] T4.P[0]
CONNECT T2.P[3] T5.P[1]
END CONNECTIONS
END CONFIGURATION
The line:
IMPORT COMPONENT T5="UserApp2/MMWorker" NUMOFPORTS=1 MATLAB
instructs JPACT to copy the MMWorker component from the UserApp2 application directory. Once JPACT has copied the component into the directory it will update the configuration file to change the IMPORT line to this:
DEFINE TASK T5="MMWorker" NUMOFPORTS=1 MATLAB REUSE
The component now exists within the Mandelbrot application space and may be modified just like any of the other tasks.
Import from Library (single user)
The user also has the option to copy a component from any application into the library (JavaPorts/Lib) directory. Components (.class and .tp files) placed in this directory are accessible by any of the user's applications. The following line may be used to import a library component into a new application:
IMPORT COMPONENT T5="MMWorker" NUMOFPORTS=1 MATLAB LIB
The LIB keyword tells the JavaPorts runtime to look for the component in the library directory rather than in the application directory. In the case of Java, only the executable class file and TP tree will be available, so the component code cannot be modified as in the previous example.
Exporting and Importing with bundle (multi-user)
In addition to reusing components across applications, a user may wish to share a component with other users. The bundle.sh script automates the process of collecting all necessary supporting files for a component into a JAR archive file, which may be transferred to another user's file system.
The first step is to enter the Export subdirectory of the source application, and export the component using the following command:
bundle.sh -e MMWorker
This will create a MMWorker.jar file, which can be copied to the Import subdirectory of the destination application. From there, use the following command to extract the component from the JAR file and import it into the destination application:
bundle.sh -i MMWorker.jar
This same process can also be performed using the library directory as a go-between by specifying the LIB keyword to the bundle.sh script.
|