Hanumant Hi can anybody please help me to create a data adapter or similar steps to create a simple data adapter which will simply create data in for loop or can print random data on screen. If u have simple working example then also fine... i tried to analyse the data adapter source of stock list demo but its out of my range.
mathiasmethner The thread fits to my problems. Creating the client side is easy, since there is a tutorial. But creating the server side or even edit the StockListDemo looks "a little" more difficult.
Mone Hi, this is a very simple dataadapter. You can subscribe any item name. Each item has 2 fields, timestamp and count. [syntax="JAVA"]package com.lightstreamer.adapters.simplest; import java.io.File; import java.util.Date; import java.util.HashMap; import java.util.Map; import com.lightstreamer.interfaces.data.DataProvider; import com.lightstreamer.interfaces.data.DataProviderException; import com.lightstreamer.interfaces.data.FailureException; import com.lightstreamer.interfaces.data.ItemEventListener; import com.lightstreamer.interfaces.data.SubscriptionException; public class Simplest implements DataProvider { private ItemEventListener listener; private Map<String, ItemThread> threads = new HashMap<String, ItemThread>(); public void init(Map params, File configDir) throws DataProviderException { } public boolean isSnapshotAvailable(String itemName) throws SubscriptionException { return false; } public void setListener(ItemEventListener listener) { this.listener = listener; } public synchronized void subscribe(String itemName, boolean needsIterator) throws SubscriptionException, FailureException { ItemThread it = threads.get(itemName); if (it == null) { it = new ItemThread(itemName); it.start(); threads.put(itemName, it); } } public synchronized void unsubscribe(String itemName) throws SubscriptionException, FailureException { ItemThread it = threads.get(itemName); if (it != null) { it.close(); threads.remove(itemName); } } class ItemThread extends Thread { private final String item; private volatile boolean go = true; public ItemThread(String item) { this.item = item; } public void run() { int c = 0; while(go) { Map<String, String> data = new HashMap<String, String>(); data.put("timestamp", (new Date()).toString()); data.put("count", String.valueOf(c)); listener.update(item, data, false); c++; try { Thread.sleep(1000); } catch (InterruptedException e) { } } } public void close() { go = false; } } } [/syntax] this is the relative adapters.xml [syntax="XML"] <?xml version="1.0"?> <adapters_conf id="SIMPLEST"> <metadata_provider> <adapter_class>com.lightstreamer.adapters.metadata.LiteralBasedProvider</adapter_class> <param name="item_family_1">.*</param> <param name="modes_for_item_family_1">MERGE</param> </metadata_provider> <data_provider> <adapter_class>com.lightstreamer.adapters.simplest.Simplest</adapter_class> </data_provider> </adapters_conf> [/syntax] and an example client (my libraries are located under /LS4/): [syntax="JS"]<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" src="/LS4/lscommons.js"></script> <script language="JavaScript" src="/LS4/lspushpage.js"></script> </head> <body> <h1>Simplest</h1> <div> Item1 <span source="lightstreamer" table="table1" item="1" field="timestamp">Loading...</span> <span source="lightstreamer" table="table1" item="1" field="count">Loading...</span> </div> <div> MyItem <span source="lightstreamer" table="table2" item="1" field="timestamp">Loading...</span> <span source="lightstreamer" table="table2" item="1" field="count">Loading...</span> </div> <script> /////////////////PushPage Configuration var lsPage = new PushPage(); var debugAlerts = false; var remoteAlerts = false; var pushHost = null; var pushPort = null; var useDomain = null; lsPage.context.setDomain(useDomain); lsPage.context.setDebugAlertsOnClientError(debugAlerts); lsPage.context.setRemoteAlertsOnClientError(remoteAlerts); lsPage.onEngineCreation = function(lsEngine) { lsEngine.context.setDebugAlertsOnClientError(debugAlerts); lsEngine.context.setRemoteAlertsOnClientError(remoteAlerts); lsEngine.connection.setLSHost(pushHost); lsEngine.connection.setLSPort(pushPort); lsEngine.connection.setAdapterName("SIMPLEST"); lsEngine.changeStatus("STREAMING"); } lsPage.bind(); lsPage.createEngine("SimplestEngine","/LS4/","SHARE_SESSION"); ///////////////////////Table configuration var schema = ["timestamp","count"]; var table1 = new OverwriteTable("Item1", schema, "MERGE"); table1.setClearOnDisconnected(true); table1.setClearOnRemove(true); lsPage.addTable(table1, "table1"); var table2 = new OverwriteTable("MyItem", schema, "MERGE"); table2.setClearOnDisconnected(true); table2.setClearOnRemove(true); lsPage.addTable(table2, "table2"); </script> </body> </html> [/syntax]
Mone Hi sjohn, since I'm talking about a Java adapter no dll are involved but jars. I've deleted your question since cross-posted on the .NET section of the forum