Apama 10.15.0 | Connecting Apama Applications to External Components | Standard IAF Plug-ins | The File IAF Adapter (JMultiFileTransport) | Opening files for writing
 
Opening files for writing
 
Opening files for writing with parallel processing applications
To open a file for writing, send an OpenFileForWriting event. The definition of the OpenFileForWriting event is similar to the definition of the OpenFileForReading event. See the com.apama.file package in the API Reference for EPL (ApamaDoc) for detailed information on the OpenFileForWriting event.
The procedure for opening a file for writing CSV or fixed width files is effectively the same as for reading. Specify the relevant fields in the payload to describe the format of the file you want to write. When subsequently sending FileLine events, populate the data sequence field with the data for each field.
Again, once constructed, send the OpenFileForWriting event to the "FILE" channel, for example:
send OpenFileForWriting(...) to "FILE"
For fixed width files, you can construct a more complex OpenFileForWriting event in a similar way to that described in Opening fixed width files.
Again, as with reading a file, the File adapter sends a FileHandle or FileError event (see Sending the read request), which your application should listen for, filtering on the requestId for the FileHandle event you are interested in.
Once a FileHandle event has been received, the file has successfully opened and the application can begin to send FileLine events to be written. See the com.apama.file package in the API Reference for EPL (ApamaDoc) for detailed information on the FileLine event.
Notice that the data field is a sequence of strings, rather than a string. This allows you to have the fields you want to write as separate entries in the sequence, and it lets the File adapter format the sequence for writing according to the chosen codec. For the fixed width codec, the number of elements in the sequence should match the number of fields originally specified when opening the file. For the null codec, if the sequence contains more than one element, each field will be written out using a separator defined in the IAF configuration file. This separator can be blank, in which case each element will be written out immediately after the previous one, with a newline after the last element.
The FileLine event is exactly the same as the one received when reading; however, the requestId takes on a more important role. If you specify a positive requestId, your application receives an acknowledgment
When a file is already open for reading, you can write to that file only by appending new data. Of course, you must send an OpenFileForWriting event, and then the File adapter can process FileLine events for writing to that file. You receive a FileError event if the file is open for reading and for writing and you try to write data into the file but not by appending the new data.