Connecting Apama Applications to External Components > Using Standard Adapters > Using the Apama File Adapter > Specifying file names in OpenFileForReading events
Specifying file names in OpenFileForReading events
In an OpenFileForReading event, the value of the filename field can be a specific file name or a wildcard pattern. However, the filename cannot have multiple wildcards.
Specific filename
When you specify a specific filename in an OpenFileForReading event, when the adapter receives requests to read lines from the file, the adapter reads till the end of the file and waits until more data is available. An external process, or the adapter itself, might write more data to the file if it is open for write at the same time that it is being read. If more data becomes available, the File adapter sends it. If the File adapter receives a CloseFile event, the File adapter closes the file against further reading.
Each time the File adapter reaches the end of the file it is reading, the File adapter sends an EndOfFile event to the correlator. If, during this process, more data was appended to the file, the file operations will continue as normal — that is, the File adapter will send more lines if they were requested. Thus, when reading specific files, file appends are acceptable and have a well defined behavior. However, any other modifications, such as changing the lines that have already been read, may have undefined results. An application can ignore or react to an EndOfFile event. The definition of an EndOfFile event is as follows:
event EndOfFile
{
/* The name of the transport being used within the file adapter */
string transportName;
 
/* The session ID this File is associated with */
integer sessionId;
 
/* The name of the file*/
string filename;
}
Wildcard filenames
Now suppose that in an OpenFileForReading event, the value of the filename field is a wildcard pattern. In this case, the adapter does the following:
1. Opens a new file that matches the pattern
2. Reads that file in its entirety
3. Sends back an EndOfFile event
4. Opens the next file that matches the pattern if one is available
For the application's information, the File adapter sends back an event when it opens each new file. The NewFileOpened event contains the name of the file that was opened:
event NewFileOpened
{
/* The name of the transport being used within the file adapter */
string transportName;
 
/* The session Id this File is associated with */
integer sessionId;
 
/* The filename opened */
string filename;
The order of opening the files that match the wildcard pattern is not specified. Currently, the files are ordered by the modification date and then alphabetically by filename.
If a file that has been previously read is externally modified (while in the meantime, the File adapter is reading from other files that match the wildcard pattern), the file is read again in its entirety. That is, any files that are modified after reading from them will be read again (until the CloseFile is sent). Note that this includes file appends.
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.