Interface that must be implemented in order to provide data updates to DataSource peers.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public interface IDataProvider
Public Interface IDataProvider
public interface class IDataProvider
Members
All Members | Methods | ||||
Icon | Member | Description |
---|---|---|
ReceiveDiscard(IDiscardEvent) |
Callback that informs the DataProvider that an earlier requested subject has now been discarded and it should stop sending data.
| |
ReceiveRequest(IRequestEvent) |
Callback that informs the DataProvider that a new request has been received and it should start sending data.
|
Thread Safety
The IDataProvider methods are not called on a dedicated worker thread. Therefore, if any of these methods are likely take a relatively long time to execute, they should be coded to run in a separate thread.
Examples
The example should a skeleton implementation of the IDataProvider interface. Typically, an IDataProvider implementation will require a reference to its IPublisher so it may emply that publisher for sending messages. In this example this is acheived by injecting the publisher into the IDataProvider via its constructor.
CopyC#
using System; using System.Collections.Generic; using Caplin.DataSource; using Caplin.DataSource.Messaging.Record; using Caplin.DataSource.Publisher; using Caplin.DataSource.Namespace; namespace DataSourceExamples.DataProvider { public class ExampleDataProvider : IDataProvider { private readonly IPublisher publisher; private readonly DataSource dataSource; public ExampleDataProvider(DataSource dataSource) { this.publisher = dataSource.CreateActivePublisher(new PrefixNamespace("/"), this); this.dataSource = dataSource; } public void ReceiveRequest(IRequestEvent ev) { // Subscribe to back end system. // ... // Create a message for the DataSource subject. IRecordType1Message message = publisher.MessageFactory.CreateRecordType1Message(ev.Subject); // Mark the message as containing an image. message.Image = true; // Add data to the message. message["Bid"] = "1.23"; // Send the image message to the newly subscribed DataSource peer. publisher.PublishInitialMessage(message); } public void ReceiveDiscard(IDiscardEvent ev) { // Unsubscribe from back end system // ... } // Once this IDataProvider subscribed to the back end system, // the back end pushes messages into this IDataProvider via this message // listener callback. public void OnDataUpdate(String subject, IDictionary<String, String> messageData) { // Create a message for the appropriate DataSource Subject. IRecordType1Message message = publisher.MessageFactory.CreateRecordType1Message(subject); // Transform the back end update's data into DataSource message fields. foreach (String name in messageData.Keys) { message[name] = messageData[name]; } // Publish the message. publisher.PublishToSubscribedPeers(message); } } }