To implement a Java connector, you must extend the
Connector
class. The constructor of your class must
have your ConnectorConfig-derived class as sole parameter.
The second class is your
ConnectorConfig
, in this case,
BasicFilesystemConnectorConfig
public class BasicFilesystemConnector extends Connector {
private final BasicFilesystemConnectorConfig config;
public BasicFilesystemConnector(final BasicFilesystemConnectorConfig config)
throws Exception {
super(config);
this.config = config;
}
Note:
The previous version of the constructor, taking an additional
PushAPI object as first parameter, is now deprecated and must not be used.
The following methods must be implemented:
Method
|
Description
|
public void scan(PushAPI papi, String mode, Object
modeConfig) throws Exception;
|
This method is used to scan/synchronize all documents. The
provided PushAPI object is to be used for synchronization operations.
The optional mode parameter, and its optional configuration
object, can be used in specialized scan cases defined with the
@ConnectorCapabilities annotation.
You can also set the
@ConnectorCapabilities annotation to get a
continuous scan. See
Implement a continuous scan.
|
public Document fetch(String uri) throws Exception
|
This method is used to retrieve a document from the source,
for example, to create a thumbnail or when a user clicks on a search result.
uri is the URI of the indexed document.
|
public MetaContainer getDocumentSecurityTokens(String
uri);
|
This method is used to retrieve the security tokens of a
document. This method is not used during indexing but when
Exalead CloudView needs to retrieve security tokens at real time.
uri is the URI of the indexed document.
When you push documents, you must add a security meta:
document.addMeta("security", "mytoken");
|
You can use the following helper to self-abort a synchronization in
progress:
/**
* Helper which can be called by the connector code to self-abort.
* @param reason the reason why the abort was issued ; may be null
*/
@Override
public final void selfAbortScan(String reason);
You can also use the following triggers, which are called upon aborted
scan, suspended scan, or resumed scan, to execute additional operations:
/**
* Called by the framework when scan abort is requested.
* This method must not change the state of the connector, only wake up some calls
* which might be blocking.
* The scan will only be considered as aborted when the scan() method has returned.
*/
@Override
public void onScanAborted() throws Exception;
/**
* Called by the framework when scan suspend is requested.
* This method must not change the state of the connector, only wake up some calls
* which might be blocking.
* It is then the responsibility of the connector to set the status of the connector
* to SUSPENDED when effectively taken into account.
*/
@Override
public void onScanSuspended() throws Exception;
/**
* Called by the framework when scan resume is requested.
* This method must not change the state of the connector, only wake up some calls
* which might be blocking.
* It is then the responsibility of the connector to set the status of the connector
* to WORKING when effectively taken into account.
*/
@Override
public void onScanResumed() throws Exception;
You should also call the following helper regularly inside long worker
loops (long enumeration of documents) to be able to exit gracefully if an abort
has been requested by the user, or by the internal framework:
/**
* Checks the current connector status and, if an abort command was
* sent, throws an ConnectorAbortingException exception.
*
* This function is a helper which can be called by connector. It is not
* called by the framework.
**/
@Override
public void checkAbortingOperation() throws ConnectorAbortingException;
See the sample Java code for a basic filesystem connector
(DemoFileSystemConnector.java
) located in
<INSTALLDIR>\sdk\cloudview-sdk-java-connectors\samples\fsbasic
.