Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Nov 2006
    Location
    Belfast
    Posts
    15
    How do I get a reference to the Data Adapter (that is being used by the kernel in conjunction with the MetaDataAdapter, not an arbitrary DataAdapter object) instance inside the MetaAdapter?

    NOTE by Alessandro: With the release of Lightstreamer Server v.3.5, the current thread has been replaced by this new thread: http://www.lightstreamer.com/vb/showthread.php?t=422

  2. #2
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784

    Post

    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:
    1. <?xml version="1.0"?>
    2.  
    3. <adapters_conf id="ADAPTER_ID">
    4.  
    5.  <metadata_provider>
    6.   <adapter_class>my_package.MyMetadataProvider</adapter_class>
    7.   <param name="match_id">ADAPTER_ID</param>
    8.  </metadata_provider>
    9.  
    10.  <data_provider>
    11.   <adapter_class>my_package.MyDataProvider</adapter_class>
    12.   <param name="match_id">ADAPTER_ID</param>
    13.  </data_provider>
    14.  
    15. </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:
    1. package my_package;
    2.  
    3. import java.io.File;
    4. import java.util.HashMap;
    5. import java.util.Map;
    6.  
    7. import com.lightstreamer.adapters.metadata.LiteralBasedProvider;
    8. import com.lightstreamer.interfaces.metadata.MetadataProviderException;
    9.  
    10. public class MyMetadataProvider extends LiteralBasedProvider {
    11.    
    12.     public static HashMap MyDataProviderInstances = new HashMap();
    13.    
    14.     private MyDataAdapter dataAdapter;
    15.    
    16.     public void init(Map params, File configDir) throws MetadataProviderException {
    17.         super.init(params,configDir);
    18.         String adapter_id = (String) params.get("match_id");
    19.         if (adapter_id == null) { throw new MetadataProviderException("match_id for metadata adapter is missing"); }
    20.         MyDataProviderInstances.put(adapter_id,this);
    21.     }
    22.    
    23.     public void setDataAdapter(MyDataAdapter dataAdapter) {
    24.         this.dataAdapter = dataAdapter;
    25.     }
    26.    
    27. }
    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:
    1. package my_package;
    2.  
    3. import java.io.File;
    4. import java.util.Map;
    5.  
    6. import com.lightstreamer.interfaces.data.DataProvider;
    7. import com.lightstreamer.interfaces.data.DataProviderException;
    8.  
    9. public class MyDataAdapter implements DataProvider {
    10.  
    11.     private MyMetadataProvider metadataAdapter;
    12.    
    13.     public void init(Map params, File configDir) throws DataProviderException {
    14.         String adapter_id = (String) params.get("match_id");
    15.         if (adapter_id == null) { throw new DataProviderException("match_id for data adapter is missing"); }
    16.         metadataAdapter = (MyMetadataProvider) MyMetadataProvider.MyDataProviderInstances.get(adapter_id);
    17.         if (metadataAdapter == null) { throw new DataProviderException("no matching metadata adapter. Check match_id parameters"); }
    18.         metadataAdapter.setDataAdapter(this);
    19.     }
    20. }
    Hope that helps.
    Mone.

  3. #3
    Member
    Join Date
    Nov 2006
    Location
    Belfast
    Posts
    15
    Forgive me if I misunderstand, but would this design not mean that multiple instances of the same MetaAdapter would overwrite eachother's stored data provider instance through MyDataProviderInstances.put(adapter_id,this)?

    I need to communicate with the DataAdapter instance that provides the data to the particular MetaDataAdapter in question. Although all clients will be using the same DataAdapter, they will pass in different parameters through sendMessage that will cause each DataAdapter instance to send data that will differ based on this. I'm not sure that is possible with what you have suggested?

  4. #4
    Power Member
    Join Date
    Jul 2006
    Location
    Cesano Maderno, Italy
    Posts
    784
    Each Adapter is made with 2 object's instances. A DataProvider instance and a MetadataProvider one.
    To configure an Adapter you must create an adapters.xml file and put it under the adapters folder (refer to LS_HOME/DOCS-SDKs/sdk_adapter_java/examples/StockListDemo/Deployment_LS/README.TXT. for further details on how to deploy an adapter) In this file you choose the DataProvider class, the MetadaProvider class and it's also possible to set parameters to be passed to the class's instances.

    Obviously you can use a class to create more Adapters. eg you have 2 adapters. Just set the 2 adapters.xml as follows:
    The first one will use MyDataProvider as DataProvider and MyMetadataProvider as MetadataProvider.
    Code xml:
    1. <?xml version="1.0"?>
    2.  
    3. <adapters_conf id="ADAPTER_1">
    4.    <metadata_provider>
    5.       <adapter_class>my_package.MyMetadataProvider</adapter_class>
    6.       <param name="match_id">ADAPTER_1</param>
    7.    </metadata_provider>
    8.  
    9.    <data_provider>
    10.       <adapter_class>my_package.MyDataProvider</adapter_class>
    11.       <param name="match_id">ADAPTER_1</param>
    12.    </data_provider>
    13. </adapters_conf>

    The other use MyDataProvider2 as DataProvider and MyMetadataProvider as MetadataProvider.
    Code xml:
    1. <?xml version="1.0"?>
    2.  
    3. <adapters_conf id="ADAPTER_2">
    4.    <metadata_provider>
    5.       <adapter_class>my_package.MyMetadataProvider</adapter_class>
    6.       <param name="match_id">ADAPTER_2</param>
    7.    </metadata_provider>
    8.  
    9.    <data_provider>
    10.       <adapter_class>my_package.MyDataProvider2</adapter_class>
    11.       <param name="match_id">ADAPTER_2</param>
    12.    </data_provider>
    13. </adapters_conf>

    At this point you have 2 MyMetadaProvider instances and each one receives its match_id parameter.
    Code java:
    1. String adapter_id = (String) params.get("match_id");
    so adapter_id is "ADAPTER_1" for the first instance and "ADAPTER_2" for the other.

    Now with this call
    Code java:
    1. MyDataProviderInstances.put(adapter_id,this);
    each MyMetadataProvider instance puts in the MyDataProviderInstances HashMap its reference with a different key (equals to the match_id received).

    From the other side MyDataProvider an MyDataProvider2 instances get each one a different MyMetadataProvider instance.
    Code java:
    1. String adapter_id = (String) params.get("match_id");
    Code java:
    1. metadataAdapter = (MyMetadataProvider) MyMetadataProvider.MyDataProviderInstances.get(adapter_id);

    Mone.

    PS: I saw that on my previous post i fogot to instantiate MyDataProviderInstances. Sorry.

  5. #5
    Administrator
    Join Date
    Jul 2006
    Location
    Milan, Italy
    Posts
    517

    Exclamation

    With the release of Lightstreamer Server v.3.5, the current thread has been replaced by this new thread: http://www.lightstreamer.com/vb/showthread.php?t=422

 

 

Similar Threads

  1. Multiple Data/Metadata Adapters
    By odeheurles in forum Adapter APIs
    Replies: 6
    Last Post: January 26th, 2015, 09:50 AM
  2. Replies: 3
    Last Post: November 14th, 2011, 09:33 AM
  3. Replies: 1
    Last Post: July 21st, 2011, 10:16 AM
  4. multiple data adapters
    By rd2008 in forum Client APIs
    Replies: 2
    Last Post: January 7th, 2009, 02:28 PM
  5. Replies: 2
    Last Post: March 26th, 2008, 09:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 11:15 AM.