Package com.ibm.di.connector
Class FileConnector
- java.lang.Object
-
- com.ibm.di.connector.Connector
-
- 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
Constructors Constructor Description FileConnector()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacquireLock(java.nio.channels.FileChannel fc, long timeout, boolean shared)Attempts to acquire a lock on a File ChannelEntrygetNextEntry()Return the next Entry from the connector.java.lang.StringgetVersion()Version information.voidinitialize(java.lang.Object o)Initialize the connector.voidopenReadFile()Opens the file specified by the FilePath field in the Config Tab for reading.voidopenWriteFile()Opens the file specified by the FilePath field in the Config Tab for writing.voidputEntry(Entry entry)Add a new entry to the data sourcevoidreconnect()Reconnect to the underlying data source.voidreleaseLock()Releases the acquired lock.voidselectEntries()Prepare the Connector for sequential read.-
Methods inherited from class com.ibm.di.connector.Connector
addFindEntry, allModes, clearFindEntries, debug, debugMode, deleteEntry, extractExceptionInformation, 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
-
-
-
-
Method Detail
-
initialize
public void initialize(java.lang.Object o) throws java.lang.ExceptionInitialize 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:
initializein interfaceConnectorInterface- Overrides:
initializein classConnector- 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:
java.lang.Exception- if the initialization of this connector fails.
-
selectEntries
public void selectEntries() throws java.lang.ExceptionPrepare 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:
selectEntriesin interfaceConnectorInterface- Overrides:
selectEntriesin classConnector- Throws:
java.lang.Exception- if an error occurs.
-
getNextEntry
public Entry getNextEntry() throws java.lang.Exception
Return the next Entry from the connector.- Specified by:
getNextEntryin interfaceConnectorInterface- Overrides:
getNextEntryin classConnector- Returns:
- - the next Entry, or null if no more data
- Throws:
java.lang.Exception- if an error occurs.- See Also:
selectEntries()
-
putEntry
public void putEntry(Entry entry) throws java.lang.Exception
Add a new entry to the data source- Specified by:
putEntryin interfaceConnectorInterface- Overrides:
putEntryin classConnector- Parameters:
entry- The entry data to add- Throws:
java.lang.Exception- if an error occurs.
-
openReadFile
public void openReadFile() throws java.lang.ExceptionOpens the file specified by the FilePath field in the Config Tab for reading. If the default value- Throws:
java.lang.Exception- If the FilePath field is empty, an Exception is thrown
-
openWriteFile
public void openWriteFile() throws java.lang.ExceptionOpens the file specified by the FilePath field in the Config Tab for writing. If the default value- Throws:
java.lang.Exception- If the FilePath field is empty, an Exception is thrown
-
acquireLock
public void acquireLock(java.nio.channels.FileChannel fc, long timeout, boolean shared) throws java.lang.ExceptionAttempts to acquire a lock on a File Channel- Parameters:
fc- The File channel we are attempting to locktimeout- 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:
java.lang.Exception- If unable to acquire the lock within timeout time, an Exception is thrown
-
releaseLock
public void releaseLock()
Releases the acquired lock.
-
getVersion
public java.lang.String getVersion()
Version information.- Specified by:
getVersionin interfaceVersionInfoInterface- Returns:
- version information
-
reconnect
public void reconnect() throws java.lang.ExceptionReconnect to the underlying data source. Terminates the current connector, initializes it again and if in Iterator mode, prepares the connector for sequential read.- Overrides:
reconnectin classConnector- Throws:
java.lang.Exception- if an error occurs.- See Also:
Connector.initialize(Object)
-
-