Class ImportHandler
public class ImportHandler extends Object
- Configuring an import channel through the
import-n
property defined in the application's configuration file. - Retrieving imported objects from the channel.
- For each object, creating an instance of each data object that the application
produces
and letting it have a chance to interpret the data by calling itsimportObject()
method. - Whenever a data object is
committed
itsexportObject()
method is called, and if it returns a non-null object, the object is exported to the import channel.
The mechanism provided by this class supports importing and exporting of serialized data through one of the communication channels
supported by the framework (or a communication plugin). It may happen that you want to hook into
the basic mechanism and provide some extra processing in one or more of its steps. You can do it by extending the class. If you do,
you should register your implementation with Main.createImportHandler()
to
make it a substitute to the default class. This is called a serialize Import handler.
You can also implement a general object Import handler, in which case you would write the code for retrieving and delivering import/export objects directly.
Override configure()
to customize your handler configuration.
To modify the handler behavior in connection and disconnection events override onConnect()
,
onDisconnect()
and onConnectFailed()
.
To extend the handling of imported serialized data override
processLine()
.
General object handlers should call processObject()
to feed the framework with imported objects.
Override exportObject()
to handle exported objects in the case of a general object handler,
or to extend the default implementation in the case of serialize handlers.
To do custom cleanup code when the handler is discarded override cleanup()
.
Note that each instance of this class manages one Channel
object (in the case of serialize handler).
You can get the object by calling getChannel()
.
-
Constructor Summary
Constructors Constructor Description ImportHandler()
Class constructor. -
Method Summary
Modifier and Type Method Description protected void
cleanup()
Cleans up object resources.protected boolean
configure(Map<String,String> configParams, int n)
Configures and initializes the handler.protected boolean
exportObject(Object data)
Exports an object.protected Channel
getChannel()
Returns theChannel
object managed by this handler.String
getName()
Returns the connection name.String
getRemoteAddress()
Returns the remote address of the connected entity.protected String
getServerVersion()
Returns the version of the server application the channel managed by this handler is connected to, or null if not applicable.protected void
onConnect()
Called when the channel managed by this handler is connected.protected void
onConnectFailed(Exception ex)
Called when the channel managed by this handler could not connect.protected void
onDisconnect(String reason)
Called when the channel managed by this handler is disconnected.protected void
processLine(String line, ZDate ts)
Processes an imported serialized data line.protected void
processObject(Object importObject, ZDate ts, int size)
Processes an imported object.
-
Constructor Details
-
ImportHandler
public ImportHandler()Class constructor.
-
-
Method Details
-
configure
Configures and initializes the handler.configures and initializes the handler from from parameters specified by
import-n
properties in the application's configuration file. The values of these properties must be a list of pairs key=value concatenated by a semicolon.The default implementation of the method initializes a serialized data channel as documented there. Implementations of serialize Import handlers can override this method to add custom initialization code after calling
super.configure()
. Implementations of general object handlers can override it to provide their own configuration and initialization code.- Parameters:
configParams
- a map of key=value configuration parameters.n
- the n value of the import-n property.- Returns:
- true on success.
-
onConnect
protected void onConnect()Called when the channel managed by this handler is connected.Override this method to do extra processing when the channel managed by this handler is connected. Your implementation must call
super.onConnect()
. -
onDisconnect
Called when the channel managed by this handler is disconnected.Override this method to do extra processing when the channel managed by this handler is disconnected. Your implementation must call
super.onDisconnect(reason)
.- Parameters:
reason
- text describing the disconnection reason as implemented byChannel
.
-
onConnectFailed
Called when the channel managed by this handler could not connect.Override this method to do extra processing when the channel managed by this handler could not connect. Your implementation must call
super.onConnectFailed(ex)
.- Parameters:
ex
- the exception object that was thrown on the attempt to connect, if any, or null if not applicable.
-
processLine
Processes an imported serialized data line.Override this method if you implement a serialize importer and you want to do extra processing on imported lines before passing them over to the framework. To pass the line to the framework call
super.processLine(line, ts)
.- Parameters:
line
- record content.ts
- timestamp attached to the line if provided by the channel managed by this handler.
-
processObject
Processes an imported object.You can call this method when you implement a general object import handler in order to process one import object.
- Parameters:
importObject
- the imported objectts
- timestamp of the import. If null, the current time is used.size
- size of the object in bytes, for statistic purposes (logging and SpiderAdmin).- Throws:
Exception
-
exportObject
Exports an object.Override this method to do extra processing on exported records before transmitting them over the channel managed by this handler (if you implement a serialize importer), or to export it in a form other than a serialized string (if you implement a general object importer). In the first case, call
super.exportObject(data)
to transmit the data as a string.- Parameters:
data
- the exported record.- Returns:
- true if and only if record was transmitted successfully.
-
getChannel
Returns theChannel
object managed by this handler.- Returns:
- the Channel object managed by this handler.
-
cleanup
protected void cleanup()Cleans up object resources.Override this method to do custom resource cleanup code when the handler is discarded.
-
getServerVersion
Returns the version of the server application the channel managed by this handler is connected to, or null if not applicable.Override this method to return a string representing the version of the server application this handler is connected to.
- Returns:
- the version of the server application the channel managed by this handler is connected to, or null if not applicable or by default.
-
getName
Returns the connection name.Returns the name attached to the connection managed by this handler in the application's configuration file. If a name is not attached, the value of n used in the
import-n
property defined in that file is returned.- Returns:
- the connection name.
-
getRemoteAddress
Returns the remote address of the connected entity.- Returns:
- the remote address of the connected entity.
-