Class BootstrapConnector<K>
- java.lang.Object
-
- com.boomi.connector.util.BootstrapConnector<K>
-
- All Implemented Interfaces:
Connector
,ConnectorCacheFactory<K,BootstrapConnector.ClassLoaderCache<K>,BrowseContext>
public abstract class BootstrapConnector<K> extends Object implements Connector, ConnectorCacheFactory<K,BootstrapConnector.ClassLoaderCache<K>,BrowseContext>
Connector base class which can be used to implement a Connector which downloads the actual service classes at runtime. The connector archive should include a subclass of this class which does not use any service specific classes. The subclass is responsible for downloading the service classes and constructing a new classloader including the service specific classes. Once this classloader has been created, it can be used to load the actual Connector implementation (this implementation can use any service specific classes it desires). The subclass of this class will delegate all the Connector method invocations to this delegate Connector implementation. The ClassLoader and delegate Connector will be cached in an instance of a ClassLoaderCache.The ClassLoader information will be cached indefinitely by default. If the service classes will be periodically updated, the ClassLoaderCache can be subclassed and the
ConnectorCache.isValid()
method overridden to handle periodic checks for updates or whatever other logic is necessary.As with a normal Connector implementation, all methods must be thread-safe. To make that easier, the
createCache(K, com.boomi.connector.api.BrowseContext)
method is synchronized.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BootstrapConnector.ClassLoaderCache<K>
ConnectorCache implementation used to cache a service specific ClassLoader and Connector implementation.
-
Constructor Summary
Constructors Modifier Constructor Description protected
BootstrapConnector()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Browser
createBrowser(BrowseContext browseContext)
Returns a Browser for this connector.BootstrapConnector.ClassLoaderCache<K>
createCache(K key, BrowseContext browseContext)
Returns a new instance of a ConnectorCache for the given key and context.protected abstract BootstrapConnector.ClassLoaderCache<K>
createClassLoaderCache(K key, BrowseContext browseContext)
Returns a new ClassLoaderCache instance.protected abstract K
createClassLoaderCacheKey(BrowseContext browseContext)
Returns the key which should be used to cache the ClassLoaderCache.Operation
createOperation(OperationContext operationContext)
Returns the actual Operation.void
initialize(AtomContext newContext)
Does any startup initialization for this connector.protected Connector
loadConnectorDelegate(String implClassName, ClassLoader cl)
Utility method which loads the delegate Connector implementation with the given implClassName from the given ClassLoader.
-
-
-
Method Detail
-
initialize
public void initialize(AtomContext newContext)
Description copied from interface:Connector
Does any startup initialization for this connector. This will be called exactly once (within external synchronization) after the Connector is instantiated and before any other methods are called on it.This call may do expensive things like open connections or other resources which will be used throughout the Connector's lifecycle. Connectors are never explicitly closed, so explicit resource cleanup (if necessary) should be managed through garbage-collector hooks (e.g. reference objects or finalize). Note that any resources cached at the Connector level should not be account specific. The preferred resource cache is the one returned by a call to
ConnectorContext.getConnectorCache()
as it is Boomi account specific and therefore may be used to cache account specific information.- Specified by:
initialize
in interfaceConnector
- Parameters:
newContext
- the static atom context
-
createBrowser
public Browser createBrowser(BrowseContext browseContext)
Returns a Browser for this connector. All connection fields from the connector's descriptor will be provided inConnectorContext.getConnectionProperties()
if the configuration is marked "requireConnectionForBrowse" and all operation fields marked "includeInBrowse will be provided inBrowseContext.getOperationProperties()
(where the keys will be the relevant field's "id" and the values will be of the appropriate Java type for the relevant field's "type").This call should be relatively cheap as Browsers are only ever created for a single invocation. Any resource caching should be handled at the Connector level or via the
ConnectorContext.getConnectorCache()
.This implementation loads a valid instance of ClassLoaderCache and delegates the
createBrowser()
call to the referenced delegate Connector.- Specified by:
createBrowser
in interfaceConnector
- Parameters:
browseContext
- the context for this browse operation. this context is considered to be owned by the Browser after this call and may be held by the Browser for use in subsequent method calls.- Returns:
- a Browser for use when browsing this connector
-
createOperation
public Operation createOperation(OperationContext operationContext)
Returns the actual Operation. All connection fields from the connector's descriptor will be provided inConnectorContext.getConnectionProperties()
and operation all fields will be provided inBrowseContext.getOperationProperties()
(where the keys will be the relevant field's "id" and the values will be of the appropriate Java type for the relevant field's "type").This call should be relatively cheap as Operations are only ever created for a single invocation. Any resource caching should be handled at the Connector level or via the
ConnectorContext.getConnectorCache()
.This implementation loads a valid instance of ClassLoaderCache and delegates the
createOperation()
call to the referenced delegate Connector.- Specified by:
createOperation
in interfaceConnector
- Parameters:
operationContext
- the context for this connector operation. this context is considered to be owned by the Operation after this call and may be held by the Operation for use in subsequent method calls.- Returns:
- an Operation for use when executing operations for this connector
-
createCache
public final BootstrapConnector.ClassLoaderCache<K> createCache(K key, BrowseContext browseContext)
Returns a new instance of a ConnectorCache for the given key and context.Creates a ClassLoaderCache instance by calling
createClassLoaderCache(K, com.boomi.connector.api.BrowseContext)
and returns it. This method is synchronized in order to simplify implementing this method in a thread-safe manner.- Specified by:
createCache
in interfaceConnectorCacheFactory<K,BootstrapConnector.ClassLoaderCache<K>,BrowseContext>
- Parameters:
key
- the key by which this ConnectorCache will be cached in the connector cachebrowseContext
- the current connector context. Note, this context should not be held by the ConnectorCache instance, but may be used to retrieve connection properties.- Returns:
- a valid ConnectorCache instance
-
loadConnectorDelegate
protected Connector loadConnectorDelegate(String implClassName, ClassLoader cl) throws Exception
Utility method which loads the delegate Connector implementation with the given implClassName from the given ClassLoader.- Parameters:
implClassName
- the fully-qualified name of the service specific Connector implementationcl
- the ClassLoader which contains all the necessary classes for accessing the service- Returns:
- the service specific Connector implementation, initialized and ready to go
- Throws:
Exception
-
createClassLoaderCacheKey
protected abstract K createClassLoaderCacheKey(BrowseContext browseContext)
Returns the key which should be used to cache the ClassLoaderCache. The key should include whatever information is required to uniquely identify the ClassLoader information.- Parameters:
browseContext
- current browse/operation context
-
createClassLoaderCache
protected abstract BootstrapConnector.ClassLoaderCache<K> createClassLoaderCache(K key, BrowseContext browseContext) throws Exception
Returns a new ClassLoaderCache instance. The implementation of this methd should load the required classes, construct a ClassLoader, and create the delegate Connector instance (the latter part can be achieved via a call toloadConnectorDelegate(java.lang.String, java.lang.ClassLoader)
).- Parameters:
key
- key returned from a call tocreateClassLoaderCacheKey(com.boomi.connector.api.BrowseContext)
browseContext
- current browse/operation context- Returns:
- the new ClassLoaderCache instance
- Throws:
Exception
-
-