a
Using Connector Fed Datapool
A Datapool can be registered as a listener of connector that implement DataUpdateConnector interface. A connector can have multiple topics and serve multiple Datapools. A Connector can also be configured to be different scope (for example PS or APP). A Connector is instantiated when a Datapool is created. For PS scope the connector instance is kept at Presentation Server. Datapools from different applications can access to the same instance of connector to subscribe to the available topic. For APP scope, the connector instance is kept privately in an application.
/**
*InterfaceofConnectorfeedingupdatestoitstopiclisteners.
*
*@altioapiall
*/
publicinterfaceDataUpdateConnector
{
/**
*AddtopictotheConnector.Donothingifexistingtopicisfound.
*
*@paramtopicName
thenameofthetopic
*/
publicvoidaddTopic(String
topicName);
/**
*Addalistenertospecifiedtopic. Donothingifthelistenerisalready
*subscribingtothetopic.
*
*@paramtopicName thenameofthetopic
*@paramlistener Dataupdatelistener
*@exception TopicNotFoundExceptionifspecifiedtopicisunknown
*/
publicvoidsubscribe(String topicName, DataUpdateListener listener)
throws TopicNotFoundException ;
/**
*Removethelistenerfromspecifiedtopic.
*
*@paramtopicName thenameofthetopic
*@paramlistener Dataupdatelistener
*@exception TopicNotFoundExceptionifspecifiedtopicisunknown
*/
publicvoidunsubscribe(String topicName, DataUpdateListener listener)
throws TopicNotFoundException;
/**
*Sendupdate(XMLstring)toalllistenersofspecifiedtopic
*@paramtopicName thenameofthetopic
*@paramxmlString dataupdateinxmlstring
*@exception TopicNotFoundExceptionifspecifiedtopicisunknown
*/
publicvoidsendUpdate(String topicName, String xmlString)
throws TopicNotFoundException, InvalidDataException;
/**
*Sendupdate(DOMElement)toalllistenersofaspecifiedtopic.
*@paramtopicName thenameofthetopic
*@paramdomElem dataupdateinDOMElement
*@exception TopicNotFoundExceptionifspecifiedtopicisunknown
*/
publicvoidsendUpdate(String topicName, Element domElem)
throws TopicNotFoundException, InvalidDataException;
/**
*Getallavailabletopicsoftheconnector.
*@return Arrayoftopicname(String)
*/
publicString[] getTopics();
/**
*Resetalltopics.Iftherearestilllistenerssubscribingtoatopic,
*theywillbenotifiedwithsetStatus()callwithfailurestatusandmessage.
*
*/
publicvoidshutdown();
}
AltioLive includes a default implementation of the Connector, DataUpdateConnectorImpl.
Add syncEngine${Studio|APS}${Professional|Enterprise|Workgroup}.jar (in ${AltioContext}/WEB-INF/lib) to your CLASSPATH.
Extent your class from com.altio.ext.connector.update.DataUpdateConnectorImpl class.
When your connector is initialized, call addTopic() to set-up all available topics for your connector. This shall be done before any listener can subscribe to that topic. When new update is available, your connector shall call DataUpdateListener's interface function, sendUpdate() to broadcast the update to all listeners of the connector.
A sample connector, SampleDataConnector.java, is included in AltioLive Studio. This Connector has 3 topics, PRICE, INVENTORY and RESULT, and receives data updates from UpdateGenerators every 5, 10 and 1 second(s). When new updates are available in the SampleDataConnector, they are pushed to the DataUpdateListener (e.g. Datapool) by calling listener's newUpdate() interface function.
/**
*Sampleconnectorgeneratingprice/inventory/result updates every5, 10 and 1 second.
*/
publicclassSampleDataConnector extendsDataUpdateConnectorImpl {
privateUpdateGenerator priceUpdater = null;
privateUpdateGenerator inventoryUpdater = null;
privateUpdateGenerator resultUpdater = null;
/**
*Constructor
*/
publicSampleDataConnector() {
// setup 3 topics for this connector
addTopic(UpdateGenerator.priceTopic);
addTopic(UpdateGenerator.inventoryTopic);
addTopic(UpdateGenerator.resultTopic);
// get update generators
priceUpdater = UpdateGenerator.getGenerator(UpdateGenerator.priceTopic);
inventoryUpdater = UpdateGenerator.getGenerator(UpdateGenerator.inventoryTopic);
resultUpdater = UpdateGenerator.getGenerator(UpdateGenerator.resultTopic);
// subscribe to the updaters
priceUpdater.subscribe(this);
inventoryUpdater.subscribe(this);
resultUpdater.subscribe(this);
System.out.println("SampleDataConnector created");
}
/**
*Implementation of UpdateGenerator's interface functions.
* Whenever new update is available, this method is invoked
*/
public void onUpdate(String topic, String update) {
try {
//send update to all topic listeners of this connector
sendUpdate(topic, update);
}
catch(Exception e) {
; //
}
}
/**
* Implementation of UpdateGenerator's interface function.
* Whenever UpdateGenerator no longer generates update, this method is invoked
*/
public void disconnect(String topic) {
// tell all listeners of the topic connector the situation
shutdown(topic);
}
/**
*KillThreadscreated
*/
protectedvoidfinalize() {
if(priceUpdater!=null) {
priceUpdater.unsubscribe(this);
priceUpdater.kill();
}
if (inventoryUpdater!=null) {
inventoryUpdater.unsubscribe(this);
inventoryUpdater.kill();
}
if (resultUpdater!=null) {
resultUpdater.unsubscribe(this);
resultUpdater.kill();
}
System.out.println("SampleDataConnector stopped);
}
}
Other supporting classes of this sample connector can be found under the same directory: src/com/altio/demo/datapool/data.
The Connector shall have a default constructor to be instantiated by the Datapool. However it is possible to work around this limitation by registering a connector instance. Please contact Altio for information.