-
February 8th, 2008, 06:14 PM
#1
Building a new Adapter using .NET
I am new to using ligtstreamer. I have a requirement to connect to read data off TIBCO EMS. Following the example in C:\tibco\ams\1.1\DOCS-SDKs\sdk_adapter_java\examples\StockListDemo_JMS_D ataAdapter\src_adapter\com\lightstreamer\adapters\ stocklist_jms\StockQuotesJMSAdapter.java, I am trying to build a new adapter. I need some help.
Let me give a step by step implementation of what I have done. Please tell me where I am going wrong.
1) I create a new classlibrary project called LSAdapters.
2) To this I add a class DatawareAdapter.vb
3) I have included the code, I have used.Basically I am adding it to Namespace Test.Lightstreamer.Adapters
4) The code compiles fine. It creates a LSAdapters.dll
5) I create a directory called DatawareAdapter under ams install directory (C:\tibco\ams\1.1\adapters). i create a folder called lib and copy all the dlls from my bin folder to lib directory.
6) I created a new adapter.xml which is as follows.
7) When i start the service , it is giving me aclass not found error . What am I doing wrong?
java.lang.ClassNotFoundException: Test.Lightstreamer.Adapters.DatawareAdapter
at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at com.lightstreamer.a.p.loadClass(p.java)
at com.lightstreamer.f.o.a(o.java)
at com.lightstreamer.f.o.a(o.java)
at com.lightstreamer.f.o.a(o.java)
at com.lightstreamer.f.m.a(m.java)
at com.lightstreamer.f.m.a(m.java)
at com.lightstreamer.LS.main(LS.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.tanukisoftware.wrapper.WrapperSimpleApp.run(Wr apperSimpleApp.java:292)
at java.lang.Thread.run(Thread.java:595)
<?xml version="1.0"?>
<adapters_conf id="DWEMS">
<metadata_provider>
<adapter_class>com.lightstreamer.adapters.metadata .LiteralBasedProvider</adapter_class>
</metadata_provider>
<data_provider>
<adapter_class>Test.Lightstreamer.Adapters.Datawar eAdapter</adapter_class>
<param name="loggerName">c:\temp\StatusLog.txt</param>
<param name="msgPoolSize">15</param>
<param name="recoveryPauseMillis">2000</param>
<!--EMS example configuration -->
<param name="jmsUrl">tcp://xxxx:7222</param>
<param name="initialContextFactory">com.tibco.tibjms.nami ng.TibjmsInitialContextFactory</param>
<param name="topicConnectionFactory">TopicConnectionFacto ry</param>
<param name="queueConnectionFactory">QueueConnectionFacto ry</param>
<param name="topicName">topic.sample</param>
<param name="queueName">xxxx</param>
<!-- JBoss Messaging example configuration -->
<!--
<param name="jmsUrl">jnp://localhost:1099</param>
<param name="initialContextFactory">org.jnp.interfaces.Na mingContextFactory</param>
<param name="topicConnectionFactory">ConnectionFactory</param>
<param name="queueConnectionFactory">ConnectionFactory</param>
<param name="topicName">topic/stocksTopic</param>
<param name="queueName">queue/stocksQueue</param>
-->
</data_provider>
</adapters_conf>
Imports Microsoft.VisualBasic
Imports Lightstreamer.Interfaces.Data
Imports TIBCO.EMS
Imports System.Data
Imports Tva.IO
Namespace Test.Lightstreamer.Adapters
Public Class DatawareAdapter
Implements IMessageListener, IExceptionListener
Private listener As IItemEventListener
Private subscribedItems As IDictionary
Private loggerName As String
Private logger As LogFile
Private msgPoolSize As Integer
Private userName As String = "xxxx"
Private password As String = "xxxxx"
Private connection As Connection
Private session As Session
Private msgConsumer As MessageConsumer
Private destination As Destination
Public Sub DatawareAdapter()
End Sub
Public Sub Init(ByVal parameters As System.Collections.IDictionary, ByVal configFile As String)
loggerName = getParam(parameters, "loggerName", False, "c:\temp\StatusLog.txt")
logger = New LogFile(loggerName)
'load EMS connections parameters
Dim providerURL As String = getParam(parameters, "jmsUrl", True, "")
Dim topic As String = getParam(parameters, "topicName", True, "")
Dim queue As String = getParam(parameters, "queueName", True, "")
'the size of the message pool
Me.msgPoolSize = getParam(parameters, "msgPoolSize", False, 15)
logger.AppendLine("Configuration read.")
Dim factory As ConnectionFactory = New TIBCO.EMS.ConnectionFactory(providerURL)
connection = factory.CreateConnection(userName, password)
Session = Connection.CreateSession(False, Session.AUTO_ACKNOWLEDGE)
Connection.ExceptionListener = Me
destination = session.CreateTopic(topic)
'msgConsumer = session.CreateConsumer(destination)
Dim topicSubcriber As TopicSubscriber = session.CreateDurableSubscriber(destination, "lightstreamerAdapter")
topicSubcriber.MessageListener = Me
Connection.Start()
logger.AppendLine("EMSAdapter ready.")
End Sub
'Public Function IsSnapshotAvailable(ByVal itemName As String) As Boolean Implements Lightstreamer.Interfaces.Data.IDataProvider.IsSnap shotAvailable
' If (Not itemName.StartsWith("item")) Then
' Throw New SubscriptionException("Unexpected item: " + itemName)
' End If
' Return True
'End Function
Public Sub SetListener(ByVal eventListener As IItemEventListener)
Me.listener = eventListener
End Sub
Public Sub Subscribe(ByVal itemName As String)
logger.AppendLine("Subscribing to " & itemName)
If (Not itemName.StartsWith("item")) Then
Throw New SubscriptionException("Unexpected item: " + itemName)
End If
SyncLock (subscribedItems)
If subscribedItems.Contains(itemName) Then Return
End SyncLock
End Sub
Public Sub Unsubscribe(ByVal itemName As String)
If (Not itemName.StartsWith("item")) Then
Throw New SubscriptionException("Unexpected item: " + itemName)
End If
SyncLock (subscribedItems)
If subscribedItems.Contains(itemName) Then Return
subscribedItems.Remove(itemName)
End SyncLock
End Sub
Public Sub OnMessage(ByVal message As TIBCO.EMS.Message) Implements TIBCO.EMS.IMessageListener.OnMessage
Dim dt As New DataTable
Dim eventData As IDictionary = New Hashtable()
For Each row As DataRow In GetDataSet(CType(message, TextMessage).Text).Tables(0).Rows
eventData("PointId") = row("ID")
eventData("Value") = row("value")
eventData("TimeTag") = row("TimeTag")
Next
listener.Update("PointId", eventData, True)
End Sub
Public Sub OnException(ByVal exception As TIBCO.EMS.EMSException) Implements TIBCO.EMS.IExceptionListener.OnException
' tibcoFeed.feedstop()
End Sub
Public Function GetDataSet(ByVal xmlData As String) As DataSet
Dim dataSet As New DataSet
Dim xmlReader As System.Xml.XmlTextReader
xmlReader = New System.Xml.XmlTextReader(xmlData, System.Xml.XmlNodeType.Document, Nothing)
xmlReader.ReadOuterXml()
' Read the outer XML into the Dataset
dataSet.ReadXml(xmlReader)
Return dataSet
End Function
Private Function getParam(ByVal params As System.Collections.IDictionary, ByVal toGet As String, ByVal required As Boolean, ByVal defaultValue As Integer) As Integer
Dim resInt As Integer
Dim res As String = params.Item("toGet").ToString
If res Is Nothing Then
If required Then
Throw New DataProviderException(toGet & "is missing.")
Else
If Not logger Is Nothing Then
logger.AppendLine("WARNING:" & toGet & "is missing. Using Default")
End If
resInt = defaultValue
End If
Else
Try
resInt = Integer.Parse(res)
Catch ex As Exception
If Not logger Is Nothing Then
logger.AppendLine("ERROR:" & toGet & "is not a valid number. Using defualt")
End If
resInt = defaultValue
End Try
End If
If Not logger Is Nothing Then
logger.AppendLine(toGet & "Value is : " & resInt)
End If
Return resInt
End Function
Private Function getParam(ByVal params As System.Collections.IDictionary, ByVal toGet As String, ByVal required As Boolean, ByVal defaultValue As String) As Integer
Dim res As String = params.Item("toGet").ToString
If res Is Nothing Then
If required Then
Throw New DataProviderException(toGet & "is missing.")
Else
If Not logger Is Nothing Then
logger.AppendLine("WARNING:" & toGet & "is missing. Using Default")
End If
res = defaultValue
End If
End If
If Not logger Is Nothing Then
logger.AppendLine(toGet & "Value is : " & res)
End If
Return res
End Function
End Class
End Namespace
-
February 11th, 2008, 10:39 AM
#2
Hi,
It seems your are using TIBCO AMS, not Lightstreamer directly. Lightstreamer has an OEM agreement with TIBCO Software. Please contact TIBCO for any support regarding TIBCO Ajax Message Service.
Regards,
Alessandro
Similar Threads
-
By sjohn in forum Adapter SDKs
Replies: 3
Last Post: January 7th, 2010, 08:57 AM
-
By tuongkha in forum Adapter SDKs
Replies: 2
Last Post: March 19th, 2008, 10:19 AM
-
By ebarnhorst in forum Adapter SDKs
Replies: 1
Last Post: May 7th, 2007, 05:07 PM
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 11:19 AM.
Bookmarks