Export can run independently from the calling application. This is called out of process. Out-of-process conversions protect the stability of the calling application in the rare case when a malformed document causes Export to fail. You can also run Export in the same process as the calling application. This is called in-process. However, it is strongly recommended you convert documents out of process whenever possible.
The Export out-of-process framework uses a client-server architecture. The calling application sends an out-of-process conversion request to the Service Request Broker in the main Export process. The Broker then creates, monitors, and manages a Servant process for the request—each request is handled by one independent Servant process. Data is exchanged between the application thread and the Servant through TCP/IP sockets. The source data is sent to the Servant process as a data stream or file, converted in the Servant, and then returned to the application thread. At that point, the application can either terminate the Servant process or send more data for conversion.
Multiple conversion requests can be sent from multiple threads in the calling application simultaneously. All requests sent from one thread are processed by the Servant mapped to that thread; in other words, each thread can only have one Servant to process its conversion requests.
Any standard conversion errors generated by the Servant are sent to the application.
Currently, the main Export process and Servant processes must run on the same host.
The following are requirements for running Export out of process:
Internet Protocol (TCP/IP) must be installed
Multithreaded processing must be supported on the operating system platform
The user application must be built with a multithreaded runtime library
The following methods run in-process or out of process:
convert
convertTo
getSummaryInfo
Other
Although most components of the out-of-process conversion are transparent, the following parameters are configurable:
File-size threshold/temporary file location
Conversion time-out
Listener port numbers and time-out
Connection time-out and retry
Servant process name
These parameters are defined internally, but you can override the default by defining the parameter in the formats_e.ini
file. The formats_e.ini
file is in the directory install\OS\bin
, where install
is the path name of the Export installation directory and OS
is the name of the operating system.
To set the parameters, add the following section to the formats_e.ini
file:
[KVExportOOPOptions] TempFileSizeMark= TempFilePath= WaitForConvert= WaitForConnectionTime= ListenerPortList=
ConnectRetryInterval= ConnectRetry= ServantName=
Each parameter is described in the following table.
The default values for these parameters are set to ensure reasonable performance on most systems. If you are processing a large number of files, or running Export on a slow machine, you might need to increase some of the time-out and retry values.
To convert files out of process
If required, set parameters for the out-of-process conversion in the formats_e.ini
file. See Configure Out-of-Process Conversions.
Instantiate an HtmlExport
object.
To ensure multithreaded conversions are thread-safe, you must create a unique context pointer for every thread by instantiating an HtmlExport
object. In addition, threads must not share context pointers, and the same context pointer must be used for all API calls in the same thread. Creating a context pointer for every thread does not affect performance because the context pointer uses minimal resources.
All methods that can run out of process must be called within the out-of-process session, that is, after the call to initialize the out-of-process session and before the call to end the out-of-process session.
When terminating an out-of-process session, persist the Servant process by setting the Boolean flag bKeepServantAlive
in the endOOPSession
method. If the Servant process remains active, subsequent conversion requests are processed more quickly because the Servant process is already prepared to receive data. Only terminate the Servant when there are no more out-of-process requests.
To recover from a failure in the Servant process, start a new out-of-process session. This creates a new Servant process for the next conversion.
The HtmlTest.java
sample program demonstrates how to run Export out of process.
To convert files out of process in the Java API
If required, set parameters for the out-of-process conversion in the formats_e.ini
file. See Configure Out-of-Process Conversions.
Create an instance of the HtmlExport
class.
HtmlExport objHtmlExport = new HtmlExport();
If you are using a template file to set the conversion options, call the setIniFileName
method.
objHtmlExport.setIniFileName(iniFile);
If you are using the API to set the conversion options, create instances of the following classes:
HtmlOptionInfo
HtmlTemplateInfo
HtmlTOCOptionInfo
StyleMapping
HtmlHeadingInfo
Set the classes to the current HtmlExport
object using the appropriate set methods. If you do not set the classes before calling the startOOPSession
method, default values are used.
Set the location of the Export libraries by calling the setExportDirectory
method. These are normally in the directory install\OS\bin
, where install
is the path name of the Export installation directory and OS
is the name of the operating system.
objHtmlExport.setExportDirectory(exportDir);
Optionally, set the input source as either a file or stream by calling the setInputSource
method.
//set the input source as file
objHtmlExport.setInputSource(inFile);
//set the input source as stream
inf = new File(inFile);
fis = newFileInputStream(inf);
objHtmlExport.setInputSource(fis);
Set up an out-of-process session by calling the startOOPSession
method. This initializes the out-of-process session, creates a Servant process, establishes a communication channel between the application thread and the Servant, and sends the data to the Servant.
objHtmlExport.startOOPSession();
Convert the input and generate the output files by calling the convertTo
method. You cannot use the convert
methods that set the input source because the input source must be set before the out-of-process session is initialized. The convertTo
method can only be called once in a single out-of-process session.
objHtmlExport.convertTo(outFile);
Terminate the out-of-process session by calling the endOOPSession
method. The Servant ends the current conversion session, and releases the source data and session resources.
objHtmlExport.endOOPSession(TRUE);
After all files are converted, terminate the out-of-process session and the Servant process by calling endOOPSession
and setting the Boolean to FALSE
.
objHtmlExport.endOOPSession(FALSE);
Terminate the Export session and free allocated system resources by calling the shutdownExport()
method.
objHtmlExport.shutdownExport();
|