-
December 6th, 2006, 04:49 PM
#2
Hi,
I will expand on this through a little example.
We will put a static HashMap in the MetaDataProvider class, then we will access that HashMap from the DataProvider class, retrieve our related instance and pass to it our DataProvider instance. This flow is needed since LS Kernel initiates the Metadata Adapter before initiating the Data Adapter. This tutorial assumes a basic understanding of Java.
First of all create the adapters.xml file. We will put an additional parameter (match_id) that will help us to make a match between a DataAdapter instance and the MetadataAdapter one. This way, if we have more adapters that share the same class, we just need to give them different match_id to avoid collisions:
Code xml:
<?xml version="1.0"?>
<adapters_conf id="ADAPTER_ID">
<metadata_provider>
<adapter_class>my_package.MyMetadataProvider</adapter_class>
<param name="match_id">ADAPTER_ID</param>
</metadata_provider>
<data_provider>
<adapter_class>my_package.MyDataProvider</adapter_class>
<param name="match_id">ADAPTER_ID</param>
</data_provider>
</adapters_conf>
So MyMetadataProvider will be our MetadataAdapter class.
To implement this class we will extend the classic LiteralBasedProvider. We will reimplement the init method (to put each instance inside a HashMap) and we will add a method for the setting of the related MyDataProvider instance:
Code java:
package my_package;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import com.lightstreamer.adapters.metadata.LiteralBasedProvider;
import com.lightstreamer.interfaces.metadata.MetadataProviderException;
public class MyMetadataProvider extends LiteralBasedProvider {
private MyDataAdapter dataAdapter;
public void init
(Map params,
File configDir
) throws MetadataProviderException
{
super.init(params,configDir);
if (adapter_id == null) { throw new MetadataProviderException("match_id for metadata adapter is missing"); }
MyDataProviderInstances.put(adapter_id,this);
}
public void setDataAdapter(MyDataAdapter dataAdapter) {
this.dataAdapter = dataAdapter;
}
}
MyDataProvider will be our DataAdapter class. In the init method of this class we will retrieve the MyMetadataProvider instance from the MyDataProviderInstances HashMap, then we will call its setDataAdapter method. At that point two-way comunication is available. Note that to create a DataProvider implementation you will need to implement a number of methods (like onSubscribe onUnsubscribe etc..) but in this example those are omitted for simplicity:
Code java:
package my_package;
import java.io.File;
import java.util.Map;
import com.lightstreamer.interfaces.data.DataProvider;
import com.lightstreamer.interfaces.data.DataProviderException;
public class MyDataAdapter implements DataProvider {
private MyMetadataProvider metadataAdapter;
public void init
(Map params,
File configDir
) throws DataProviderException
{
if (adapter_id == null) { throw new DataProviderException("match_id for data adapter is missing"); }
metadataAdapter = (MyMetadataProvider) MyMetadataProvider.MyDataProviderInstances.get(adapter_id);
if (metadataAdapter == null) { throw new DataProviderException("no matching metadata adapter. Check match_id parameters"); }
metadataAdapter.setDataAdapter(this);
}
}
Hope that helps.
Mone.
Similar Threads
-
By odeheurles in forum Adapter SDKs
Replies: 6
Last Post: January 26th, 2015, 09:50 AM
-
By vnipt in forum General
Replies: 3
Last Post: November 14th, 2011, 09:33 AM
-
By emese in forum Adapter SDKs
Replies: 1
Last Post: July 21st, 2011, 10:16 AM
-
By rd2008 in forum Client SDKs
Replies: 2
Last Post: January 7th, 2009, 02:28 PM
-
By chinghunglai in forum General
Replies: 2
Last Post: March 26th, 2008, 09:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
All times are GMT +1. The time now is 12:40 AM.
Bookmarks