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 void
acquireLock(java.nio.channels.FileChannel fc, long timeout, boolean shared)
Attempts to acquire a lock on a File ChannelEntry
getNextEntry()
Return the next Entry from the connector.java.lang.String
getVersion()
Version information.void
initialize(java.lang.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 sourcevoid
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, 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.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 interfaceConnectorInterface
- Overrides:
initialize
in 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.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 interfaceConnectorInterface
- Overrides:
selectEntries
in 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:
getNextEntry
in interfaceConnectorInterface
- Overrides:
getNextEntry
in 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:
putEntry
in interfaceConnectorInterface
- Overrides:
putEntry
in classConnector
- Parameters:
entry
- The entry data to add- Throws:
java.lang.Exception
- if an error occurs.
-
openReadFile
public void openReadFile() throws java.lang.Exception
Opens 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.Exception
Opens 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.Exception
Attempts 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:
getVersion
in interfaceVersionInfoInterface
- Returns:
- version information
-
reconnect
public void reconnect() throws java.lang.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 classConnector
- Throws:
java.lang.Exception
- if an error occurs.- See Also:
Connector.initialize(Object)
-
-