Results 1 to 2 of 2
  1. #1
    Senior Member
    Join Date
    Jan 2011
    Location
    Navi Mumbai
    Posts
    30

    Subscription Error. Requested Data Adapter, MySample, not found(code 17).

    I am getting the following error when i run the client code. i have modified existing stocklist demo sample, i have included the log file, this is my ExternalFeed.cs code which i modified.
    Code:
    using System;
    using System.Threading;
    using System.Collections;
    using System.Data.SqlClient;
    using System.Data;
    
    namespace DataAdapterDemo
    {
        public interface IExternalFeedListener
        {
            void OnEvent(string itemName, IDictionary currentValues, bool isSnapshot);
        }
    
        public class ExternalFeedSimulator {
    
            private double [] _updateTimeMeans;        
            private double [] _updateTimeStdDevs;
    
            private IDictionary _stockGenerators;
            private IExternalFeedListener _listener;
    
            private IList _snapshotQueue;
            private Thread _snapshotSender;
            //
            private int[] _equipStatus;
            private string[] _equipNames;
    
            private DataTable dt;
            private SqlConnection connection;
            private SqlCommand command;
    
            public ExternalFeedSimulator() {
                _stockGenerators= new Hashtable();
                _snapshotQueue= new ArrayList();
    
                _updateTimeMeans = new double[] { 30000, 500, 3000, 2000, 1500, 300, 1000, 5000, 1300 };
                _updateTimeStdDevs = new double[] { 6000, 300, 1000, 800, 5000, 100, 600, 3000, 10000 };
    
    
                connection = new SqlConnection("Data Source=(local);Database=TestDB;Integrated Security=true;");
                command = new SqlCommand("Select * from Products", connection);
                connection.Open();
                SqlDataReader dr = command.ExecuteReader();
                dt = new DataTable();
                dt.Columns.Add("ProductID", typeof(int));
                dt.Columns.Add("ProductName", typeof(string));
                dt.Columns.Add("TotalQuantity", typeof(int));
                dt.Columns.Add("UnitPrice", typeof(double));
    
                while (dr.Read())
                {
                    dt.Rows.Add(dr[0], dr[1], dr[2], dr[3]);
                }
                connection.Close();
            }
    
            public void Start() {
                if (_snapshotSender != null) return;
                int recCount = dt.Rows.Count;
                dt.Columns.Add("Item", typeof(string));
    
                for (int i = 0; i < recCount; i++)
                {
                    string itemName= "item" + (i + 1);
                    dt.Rows[i]["Item"] = itemName;
    
                    ExternalFeedProducer myProducer = new ExternalFeedProducer(itemName,
                        Convert.ToInt32(dt.Rows[i]["ProductID"]), 
                        Convert.ToInt32(dt.Rows[i]["TotalQuantity"]), 
                        Convert.ToDouble(dt.Rows[i]["UnitPrice"]), 
                        Convert.ToString(dt.Rows[i]["ProductName"]),
                        _updateTimeMeans[i],
                        _updateTimeStdDevs[i]);
                    
                    _stockGenerators[itemName]= myProducer;
                    myProducer.SetFeedListener(_listener);
                    myProducer.Start();
                }
    
                _snapshotSender= new Thread(new ThreadStart(Run));
                _snapshotSender.Start();
            }
    
            private void Run() {
                IList snapshots= new ArrayList();
                do {
                    lock (_snapshotQueue) {
                        if (_snapshotQueue.Count == 0) 
                            Monitor.Wait(_snapshotQueue);
    
                        snapshots.Clear();
                        while (_snapshotQueue.Count > 0) {
                            ExternalFeedProducer myProducer= (ExternalFeedProducer) _snapshotQueue[0];
                            snapshots.Add(myProducer);
                            _snapshotQueue.RemoveAt(0);
                        }
                    }
    
                    foreach (ExternalFeedProducer myProducer in snapshots) {
                        _listener.OnEvent(myProducer.GetItemName(), myProducer.GetCurrentValues(true), true);
                    }
    
                } while (true);
            }
    
            public void SetFeedListener(IExternalFeedListener listener) {
                _listener= listener;
    
                foreach (ExternalFeedProducer myProducer in _stockGenerators.Values) {
                    myProducer.SetFeedListener(listener);
                }
            }
    
            /// <summary>
            /// Forces sending an event with a full snapshot for a stock.
            /// </summary>
            public void SendCurrentValues(string itemName) {
                ExternalFeedProducer myProducer= (ExternalFeedProducer) _stockGenerators[itemName];
                if (myProducer == null) return;
    
                lock (_snapshotQueue) {
                    _snapshotQueue.Add(myProducer);
                    Monitor.Pulse(_snapshotQueue);
                }
            }
        }
    
        public class ExternalFeedProducer {
            public string _itemName;
            private int _productID, _totalQuantity;
            private double _unitPrice,_mean, _stddev;
            private string _productName;
            
            private Random _random;
            private bool _haveNextNextGaussian;
            private double _nextNextGaussian;
    
            private IExternalFeedListener _listener;
            private Thread _thread;
    
            private SqlConnection conn;
            private SqlCommand comm;
    
            public ExternalFeedProducer(string name, int productID, int totalQuantity,
                double unitPrice, string productName, double updateTimeMean, double updateTimeStdDev)
            {
                _itemName = name;
                _productID = productID;
                _totalQuantity = totalQuantity;
                _unitPrice = unitPrice;
                _productName = productName;
                _mean = updateTimeMean;
                _stddev = updateTimeStdDev;
    
                _random = new Random();
                _haveNextNextGaussian = false;
                _nextNextGaussian = 0.0;
    
                ComputeNewValues();
            }
    
            public string GetItemName() {
                return _itemName;
            }
    
            public void SetFeedListener(IExternalFeedListener listener) {
                lock (this) {
                    _listener = listener;
                }
            }
    
            public void Start() {
                lock (this) {
                    if (_thread != null) return;
    
                    _thread = new Thread(new ThreadStart(Run));
                    _thread.Start();
                }
            }
    
            private void Run() {
                do {
                    int waitMillis= ComputeNextWaitTime();
                    Thread.Sleep(waitMillis);
    
                    ComputeNewValues();
                    if (_listener != null) 
                        _listener.OnEvent(_itemName, GetCurrentValues(false), false);
    
                } while (true);
            }
    
            /// <summary>
            /// Decides, for ease of simulation, the time at which the next
            /// update for the stock will happen.
            /// </summary>
            public int ComputeNextWaitTime() {
                lock (this) {
                    int millis;
                    do {
                        millis = (int) Gaussian(_mean, _stddev);
                    } while (millis <= 0);
                    return millis;
                }
            }
    
            public void ComputeNewValues() {
                lock (this) {
                    try
                    {
                        conn = new SqlConnection("Data Source=(local);Database=TestDB;Integrated Security=true;");
                        comm = new SqlCommand("Select TotalQuantity, UnitPrice from Products WHERE ProductID=" + _productID + ";", conn);
                        conn.Open();
                        SqlDataReader dr = comm.ExecuteReader();
                        while (dr.Read())
                        {
                            int totQty = Convert.ToInt32(dr[0]);
                            double unitP = Convert.ToDouble(dr[1]);
                            if (_totalQuantity != totQty)
                                _totalQuantity = totQty;
                            if (_unitPrice != unitP)
                                _unitPrice = unitP;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message.ToString());
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
    
            public IDictionary GetCurrentValues(bool fullData) {
                lock (this) {
                    IDictionary eventData = new Hashtable();
                    eventData["itemName"] = _itemName;
                    eventData["product_ID"] = _productID.ToString();
                    eventData["product_name"] = _productName;
                    eventData["total_quantity"] = _totalQuantity.ToString();
                    eventData["unit_price"] = _unitPrice.ToString();
    
                    return eventData;
                }
            }
    
            private double Gaussian(double mean, double stddev) {
                lock (this) {
                    double b= 0.0;
                    
                    if (_haveNextNextGaussian) {
                        _haveNextNextGaussian = false;
                        b= _nextNextGaussian;                
                    } 
                    else {
                        double v1, v2, s;
                        do { 
                            v1 = 2.0 * _random.NextDouble() - 1.0;
                            v2 = 2.0 * _random.NextDouble() - 1.0;
                            s = v1 * v1 + v2 * v2;
                        } while (s >= 1.0 || s == 0.0);
                        double multiplier = Math.Sqrt(-2.0 * Math.Log(s)/s);
                        _nextNextGaussian = v2 * multiplier;
                        _haveNextNextGaussian = true;
                        b= v1 * multiplier;
                    }
    
                    double val= b * stddev + mean;
                    return val;
                }
            }
    
            //private int Uniform(int min, int max) {
            //    lock (this) {
            //        int b = _random.Next(max + 1 - min);
                    
            //        int val= b + min;
            //        return b + min;
            //    }
            //}
    
            //private static void AddDecField(string fld, int val100, IDictionary target) {
            //    double v = (((double) val100) / 100);
            //    target[fld]= v.ToString().Replace(',','.');
            //}
        }
    }
    this is my html code
    Code:
     <!-- stocks table -->
      <table cellspacing="0" cellpadding="2" width="790" border="0" >
       <tr class="tabletitle">
         <td width="148" style="text-align: left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name</td>
         <td width="42">Product ID</td>
         <td width="64">Total Quantity</td>
         <td width="61">Unit Price</td>
    
        </tr>
        <!-- inline generation of the table rows HTML; just for convenience -->
        <script type="text/javascript">
          for (var i = 1; i <= 5; i++) {
            var suff = (i % 2 == 1) ? "A" : "B";
            document.write('<tr class="lscold'+suff+'">');
            document.write('<td nowrap style="text-align: left"><a href="#" onClick="return openPopup('+i+')"><img src="images/popup.gif" width="16" height="16" border="0" align="left" hspace="1" alt="Graphic Chart"><div class="stockname'+suff+'" source="lightstreamer" table="main" item="'+i+'" field="product_name">Loading...</div></a></td>');
            document.write('<td><div source="lightstreamer" table="main" item="'+i+'" field="product_ID">-</div></td>');
            document.write('<td><div source="lightstreamer" table="main" item="'+i+'" field="total_quantity">-</div></td>');
            document.write('<td><div source="lightstreamer" table="main" item="'+i+'" field="unit_price">-</div></td>');
            document.write('</tr>');
          }
        </script>
    Code:
     var schema = ["product_ID", "total_quantity", "unit_price", "product_name"];
      var page1Group = ["item1", "item2", "item3", "item4", "item5"];
      var page2Group = ["item6", "item7", "item8", "item9", "item10"];
      var actGroup = null;
      var imgString = '<img src="images/popup.gif" alt="Graphic Chart" width="16" height="16" align="left" border="0" hspace="1">';
      var imgUp = '<img src="images/quotes_up.gif" alt="up" width="20" height="8" border="0">';
      var imgDown = '<img src="images/quotes_down.gif" alt="down" width="20" height="8" border="0">';
      var doFade = false;
      if (location.search.indexOf("fade=ON") > -1) {
        doFade = true;
      }
    
      function changePage(groupNumber) {
        if (groupNumber == 1) {
          actGroup = page1Group;
          document.getElementById("switchP1").style.display = "none";
          document.getElementById("switchP2").style.display = "";
        } else if (groupNumber == 2) {
          actGroup = page2Group;
          document.getElementById("switchP1").style.display = "";
          document.getElementById("switchP2").style.display = "none";
        }
    
        // create an OverwriteTable with the specified group and schema
        var newTable = new OverwriteTable(actGroup, schema, "MERGE");
    
        newTable.setDataAdapter("MySample");
        newTable.setSnapshotRequired(true);
        newTable.setRequestedMaxFrequency(1.0);
        newTable.onItemUpdate = updateItem;
        newTable.onChangingValues = formatValues;
        newTable.setPushedHtmlEnabled(true);
        pushPage.addTable(newTable, "main");
      }
    this is my adapters.xml code
    Code:
    <?xml version="1.0"?>
     
    <adapters_conf id="MySample">
     
      <metadata_provider>
        <adapter_class>com.lightstreamer.adapters.metadata.LiteralBasedProvider</adapter_class>
      </metadata_provider>
     
      <data_provider>
        <adapter_class>com.lightstreamer.adapters.remote.data.NetworkedDataProvider</adapter_class>
        <param name="request_reply_port">6661</param>
        <param name="notify_port">6662</param>
      </data_provider>
     
    </adapters_conf>
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Jan 2011
    Location
    Navi Mumbai
    Posts
    30

    Finally i got it working now, its configuration problem, i haven't properly configured the Adapter Set.

 

 

Similar Threads

  1. Sample code for multiple data adapter access
    By h2c357 in forum Client APIs
    Replies: 1
    Last Post: September 8th, 2011, 08:55 AM
  2. Replies: 4
    Last Post: February 5th, 2010, 03:12 PM
  3. Error in Data Adapter
    By wwatts in forum Adapter APIs
    Replies: 1
    Last Post: July 9th, 2009, 08:38 AM
  4. Replies: 14
    Last Post: May 13th, 2008, 03:27 AM
  5. Replies: 2
    Last Post: March 19th, 2008, 10:19 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 03:50 PM.