org.addsimplicity.anicetus.io
Class FileDeliveryAdapter

java.lang.Object
  extended by org.addsimplicity.anicetus.io.FileDeliveryAdapter
All Implemented Interfaces:
DeliveryAdapter, org.springframework.beans.factory.DisposableBean

public class FileDeliveryAdapter
extends java.lang.Object
implements DeliveryAdapter, org.springframework.beans.factory.DisposableBean

The file delivery adapater will publish events to a file or stream. This adapter is provided to assist with development debugging where running a bus may not be necessary or convenient.

Author:
Dan Pritchett (driveawedge@yahoo.com)

Constructor Summary
FileDeliveryAdapter()
           
 
Method Summary
 void close()
          Close the current file stream, if it was opened by the delivery adapter.
 void destroy()
          The destroy method is called by the Spring framework when this bean is being disposed.
 ExceptionHandler getExceptionHandler()
          Get the current exception handler that is in effect.
 TelemetryEncoder getTranslator()
          Get the current session translator that is in effect.
 java.io.Writer getWriter()
          Get the current stream where telemetry is being written.
 void sendTelemetry(GlobalInfo telemetry)
          Send the telemetry to the file.
 void setExceptionHandler(ExceptionHandler handler)
          Set the exception handler that will receive exceptions that occur.
 void setFile(java.lang.String fileName)
          Set the file where events are written.
 void setTranslator(TelemetryEncoder translator)
          Set the translator that will be used for this session.
 void setWriter(java.io.Writer writer)
          Set the stream to use for writing telemetry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileDeliveryAdapter

public FileDeliveryAdapter()
Method Detail

close

public void close()
           throws java.io.IOException
Close the current file stream, if it was opened by the delivery adapter.

Throws:
java.io.IOException - if an error occurs while attempting to close the stream.

destroy

public void destroy()
             throws java.lang.Exception
The destroy method is called by the Spring framework when this bean is being disposed.

Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
java.lang.Exception
See Also:
DisposableBean.destroy()

getExceptionHandler

public ExceptionHandler getExceptionHandler()
Get the current exception handler that is in effect.

Returns:
the exception handler.

getTranslator

public TelemetryEncoder getTranslator()
Get the current session translator that is in effect.

Returns:
the current translator.

getWriter

public java.io.Writer getWriter()
Get the current stream where telemetry is being written.

Returns:
the current stream.

sendTelemetry

public void sendTelemetry(GlobalInfo telemetry)
Send the telemetry to the file. It will be translated using the session translator and written immediately to the file, blocking the caller until it has completed.

Specified by:
sendTelemetry in interface DeliveryAdapter
Parameters:
telemetry - The telemetry artifact to write to the file.
See Also:
DeliveryAdapter.sendTelemetry(org.addsimplicity.anicetus.entity.GlobalInfo)

setExceptionHandler

public void setExceptionHandler(ExceptionHandler handler)
Set the exception handler that will receive exceptions that occur.

Specified by:
setExceptionHandler in interface DeliveryAdapter
Parameters:
handler - The handler to receive exceptions.

setFile

public void setFile(java.lang.String fileName)
             throws java.io.IOException
Set the file where events are written. The file will be written, with append mode. Any previously opened file will be closed.

Parameters:
fileName - The name of the file.
Throws:
java.io.IOException - if the file does not exist and cannot be created or opened for write.

setTranslator

public void setTranslator(TelemetryEncoder translator)
Set the translator that will be used for this session. The default translator formats the telemetry as JSON.

Parameters:
translator - The translator to use.
See Also:
JsonEncoder

setWriter

public void setWriter(java.io.Writer writer)
Set the stream to use for writing telemetry. Note that this stream will not be closed by the delivery adapter. The life cycle of the stream is owned by the caller.

Parameters:
writer - The stream to be used for writing telemetry.


Copyright © 2009 Add Simplicity. All Rights Reserved.