Consultor Eletrônico



Kbase P165018: How to read from a file using the Fle Adapter
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   4/30/2010
Status: Unverified

GOAL:

How to read from a file using the Fle Adapter

GOAL:

How to read data from a text file using the File Adapter

GOAL:

How to read lines from the text file using the File Adapter

FACT(s) (Environment):

Apama 4.x
Apama Adapters

FIX:



Create a studio project, and add the file adapter bundle. Once it is setup, create a monitor script, and copy the code below:
monitor myfilesample {
action onload() {
com.apama.statusreport.SubscribeStatus sub := new com.apama.statusreport.SubscribeStatus;
sub.serviceID:="File";
route sub;
/* routes an event to receveive the information on the adapter */

com.apama.statusreport.Status st;

on com.apama.statusreport.Status(serviceID="File" , available = false) {

/* at this point we have the adapter up, so we are ready to open the file */
com.apama.file.OpenFileForReading openFile;
openFile:= new com.apama.file.OpenFileForReading;
openFile.transportName:="JMultiFileTransport";
openFile.requestId:=integer.getUnique();
openFile.filename:="c:/temp/test.txt";
openFile.codec:="JNullCodec";

emit openFile to "FILE";
com.apama.file.FileHandle fh;
com.apama.file.FileError fe;
/* in case an error happens, handles with this event */
on all com.apama.file.FileError(requestId=openFile.requestId):fe {
print "Error opening the file:" + fe.toString();
}
/* if success opening the file, here we continue the processing */
on com.apama.file.FileHandle(requestId = openFile.requestId):fh {
color=#7f0055 size=2>print ("got the file handle");
com.apama.file.ReadLines rl := new com.apama.file.ReadLines;
rl.transportName := "JMultiFileTransport";
rl.sessionId := fh.sessionId;
rl.requestId := integer.getUnique();
rl.numberOfLines:=100;/* some random number of lines */
emit rl to "FILE"; /* now we say to the adapter to start flowing the file lines */
com.apama.file.FileLine fl;
/* read the file lines returned by the Adapter */

on all com.apama.file.FileLine(sessionId = rl.sessionId):fl {
print "FILE LINE:" + fl.toString();
}
/* when it finishes, emit a close file */
on com.apama.file.EndOfFile(sessionId = rl.sessionId) {
emit com.apama.file.CloseFile("JMultiFileTransport",integer.getUnique(), rl.sessionId) to "FILE";
}


}

}

}

}.