Developing Apama Applications > Developing Adapters > Standard Apama Adapters > Apama File adapter > Opening files for reading > Opening files for reading with parallel processing applications
Opening files for reading with parallel processing applications
If your Apama application implements parallel processing, you may want to increase parallelism by processing the incoming events from the File adapter in a separate, private, context, rather than doing everything in the correlator’s main context. To request that events from the File adapter are sent to the private context your monitor is running in, the monitor should open the file using the com.apama.file.OpenFileForReadingToContext event instead of OpenFileForReading. The OpenFileForReadingToContext event has a field that contains a standard OpenFileForReading event (see Opening files for reading), in addition to a field specifying the context that file adapter events should go to for processing, (which is usually the context the monitor itself is running in, context.current()), and the name of the channel the File adapter is using. When using the OpenFileForReadingToContext event, the OpenFileForReadingToContext event and all other file adapter events must not be emitted directly to the adapter, but rather enqueued to the correlator’s main context, where the adapter service monitor runs. The File adapter’s service monitor is responsible for emitting the events that are enqueued from other contexts to the File adapter, and for enqueuing the events received from the File adapter to whichever context should process them (as specified in the OpenFileForReadingToContext event).
The OpenFileForReadingToContext event is defined as follows:
event OpenFileForReadingToContext
{
context instanceContext;
string fileChannel;
OpenFileForReading fileEvent;
}
Here is an example of how the OpenFileForReadingToContext event is used:
com.apama.file.OpenFileForReading openFileForReading :=
new com.apama.file.OpenFileForReading;

... // populate the fields of the openFileForReading event as needed

// Instead of emitting openFileForReading to "FILE", wrap it in
// the OpenFileForReadingToContext event and enqueue it to the service
// monitor in the main context.

enqueue com.apama.file.OpenFileForReadingToContext(context.current(),
"FILE", openFileForReading) to mainContext;

com.apama.file.FileHandle readHandle;
on com.apama.file.FileHandle(
transportName=openFileForReading.transportName,
requestId=openFileForReading.requestId):readHandle
{
// instead of emitting to the "FILE" channel, enqueue it to the main
// context
enqueue com.apama.file.ReadLines(openFileForReading.transportName, -1,
readHandle.sessionId, 20) to mainContext;
...
}
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.