Adapter Development Kit 6.5 | webMethods Adapter Development Kit Documentation | webMethods Adapter Development Kit Installation and User’s Documentation | Listener Notifications | Listener Implementation | Implementing Run-Time Code
 
Implementing Run-Time Code
The run-time code for the example listener manages a FileReader object and variables to hold data read from the log as follows:
private FileReader _reader = null;
private StringBuffer workingBuffer = new StringBuffer();
private String _lastDataObject = null;
public void listenerStartup() throws ResourceException
{
try
{
_reader = retrieveConnection().getReader(_fileName);
while(_reader.ready())
{
_reader.read(); // move to the end of the stream
}
}
catch (Throwable t)
{
throw MyAdapter.getInstance().createAdapterException(100,t);
}
}
public Object waitForData() throws ResourceException
{
try
{
if(_reader.ready())
{
do
{
int i = _reader.read();
if (i != -1)
{
char c = (char)i;
workingBuffer.append(c);
if(c == '\n')
{
_lastDataObject = new String(workingBuffer);
workingBuffer = new StringBuffer();
break;
}
}
else
{
break;
}
}
while (_reader.ready());
}
}
catch (Throwable t)
{
throw MyAdapter.getInstance().createAdapterException(100,t);
}
return _lastDataObject;
}
public void listenerShutdown()
{
try
{
_reader.close();
}
catch(Throwable t){}
}
The example also includes an implementation of processNotificationResults:
public void processNotificationResults(NotificationResults results)
throws ResourceException
{
if(results != null)
{
if(results.hadError())
{
MyAdapter.getLogger().logError(9999,
"Error processing: " + this._lastDataObject
+" errorInfo = " + results.getErrorInfo().toString());
}
}
else
{
MyAdapter.getLogger().logError(
9999,"No notification available to process:" + this._lastDataObject);
}
}