com.ibm.di.connector
Class FileConnector

java.lang.Object
  extended by com.ibm.di.connector.Connector
      extended by com.ibm.di.connector.FileConnector
All Implemented Interfaces:
ConnectorInterface, VersionInfoInterface

public class FileConnector
extends Connector
implements ConnectorInterface

The file system Connector is a transport Connector that requires a Parser to operate. The file system Connector reads and writes files available on the system it runs on. Concurrent usage of a file can be controlled by means of a locking mechanism. This Connector can only be used in Iterator or AddOnly mode, or for the equivalent operations in Passive state.


Field Summary
 
Fields inherited from class com.ibm.di.connector.Connector
ALL_MODES, myLog, PROPERTY_MESSAGE, PROPERTY_READER, PROPERTY_WRITER
 
Constructor Summary
FileConnector()
          Constructor.
 
Method Summary
 void acquireLock(FileChannel fc, long timeout, boolean shared)
          Attempts to acquire a lock on a File Channel
 Entry getNextEntry()
          Return the next Entry from the connector.
 String getVersion()
          Version information.
 void initialize(Object o)
          Initialize the connector.
 void openReadFile()
          Opens the file specified by the FilePath field in the Config Tab for reading.
 void openWriteFile()
          Opens the file specified by the FilePath field in the Config Tab for writing.
 void putEntry(Entry entry)
          Add a new entry to the data source
 void reconnect()
          Reconnect to the underlying data source.
 void releaseLock()
          Releases the acquired lock.
 void selectEntries()
          Prepare the Connector for sequential read.
 
Methods inherited from class com.ibm.di.connector.Connector
addFindEntry, allModes, clearFindEntries, debug, debugMode, deleteEntry, findEntry, findEntry, getBoolean, getClassInstance, getConfiguration, getContext, getFindEntryCount, getFirstFindEntry, getLog, getMaxDuplicateEntries, getModes, getModes, getName, getNextClient, getNextFindEntry, getParam, getParser, getProperty, getPushbackEntry, getRawConnectorConfiguration, getRSInterface, getUI, hasConfigValue, hasParser, initParser, isDeltaSupported, isExceptionFatal, isIOException, logError, logmsg, modEntry, modEntry, pushback, queryOperations, queryReply, querySchema, queryTables, reconnect, registerScriptBeans, replyEntry, setConfiguration, setContext, setCurrent, setDebugMode, setLog, setMaxDuplicateEntries, setModes, setModes, setName, setParam, setParser, setProperty, setRSInterface, terminate, terminateServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ibm.di.connector.ConnectorInterface
deleteEntry, findEntry, getConfiguration, getContext, getFindEntryCount, getFirstFindEntry, getMaxDuplicateEntries, getName, getNextClient, getNextFindEntry, getParam, getPushbackEntry, getRawConnectorConfiguration, isDeltaSupported, isExceptionFatal, isIOException, modEntry, modEntry, pushback, queryOperations, queryReply, querySchema, reconnect, registerScriptBeans, replyEntry, setConfiguration, setContext, setCurrent, setLog, setMaxDuplicateEntries, setName, setParam, setRSInterface, terminate, terminateServer
 

Constructor Detail

FileConnector

public FileConnector()
Constructor. Initializes the connector to work in AddOnly and Iterator mode.

Method Detail

initialize

public void initialize(Object o)
                throws Exception
Initialize the connector. The connector may be passed a parameter of any kind by the user. It is up to the connector to determine whether this object can be used or not. The parameter is typically provided by a user script. When an AssemblyLine initializes it's Connectors, they are passed a ConnectorMode object.

Specified by:
initialize in interface ConnectorInterface
Overrides:
initialize in class Connector
Parameters:
o - Expects Reader or Writer to initialize the Parser with, or a ConnectorMode with the mode in which the Iterator is set to open the specified file in the configuration for reading or writing respectively for Iterator and AddOnly modes. If the object is not an instance of those classes, the iterator checks for a configuration parameter with name "fileMode" and if exists, checks if equals to "input" (and opens the file specified in the configuration for reading) or equals to "output" (and opens the file specified in the configuration for writing). An exception is thrown if none of these situations occur.
Throws:
Exception - if the initialization of this connector fails.

selectEntries

public void selectEntries()
                   throws Exception
Prepare the Connector for sequential read. Opens the file specified in FilePath field in the Config Tab. When the Connector is used as an Iterator in an AssemblyLine, this method will be called.

Specified by:
selectEntries in interface ConnectorInterface
Overrides:
selectEntries in class Connector
Throws:
Exception - if an error occurs.

getNextEntry

public Entry getNextEntry()
                   throws Exception
Return the next Entry from the connector.

Specified by:
getNextEntry in interface ConnectorInterface
Overrides:
getNextEntry in class Connector
Returns:
- the next Entry, or null if no more data
Throws:
Exception - if an error occurs.
See Also:
selectEntries()

putEntry

public void putEntry(Entry entry)
              throws Exception
Add a new entry to the data source

Specified by:
putEntry in interface ConnectorInterface
Overrides:
putEntry in class Connector
Parameters:
entry - The entry data to add
Throws:
Exception - if an error occurs.

openReadFile

public void openReadFile()
                  throws Exception
Opens the file specified by the FilePath field in the Config Tab for reading. If the default value is specified, then the standard input is used. The parser is initialized with the acquired stream.

Throws:
Exception - If the FilePath field is empty, an Exception is thrown

openWriteFile

public void openWriteFile()
                   throws Exception
Opens the file specified by the FilePath field in the Config Tab for writing. If the default value is specified, then the standard output is used. If the "fileMode" parameter is set to "append", then the stream is opened for appending. The parser is initialized with the acquired stream. If appending and the parser is a CSV parser, the method takes care for what is necessary to append to the stream.

Throws:
Exception - If the FilePath field is empty, an Exception is thrown

acquireLock

public void acquireLock(FileChannel fc,
                        long timeout,
                        boolean shared)
                 throws Exception
Attempts to acquire a lock on a File Channel

Parameters:
fc - The File channel we are attempting to lock
timeout - The max time in seconds in which the lock has to be acquired.
shared - true to request a shared lock, in which case this channel must be open for reading (and possibly writing); false to request an exclusive lock, in which case this channel must be open for writing (and possibly reading)
Throws:
Exception - If unable to acquire the lock within timeout time, an Exception is thrown

releaseLock

public void releaseLock()
Releases the acquired lock.


getVersion

public String getVersion()
Version information.

Specified by:
getVersion in interface VersionInfoInterface
Returns:
version information

reconnect

public void reconnect()
               throws Exception
Reconnect to the underlying data source. Terminates the current connector, initializes it again and if in Iterator mode, prepares the connector for sequential read.

Overrides:
reconnect in class Connector
Throws:
Exception - if an error occurs.
See Also:
Connector.initialize(Object)