DataSource.NET  6.2.20.310828
Caplin.DataSource.Publisher.IDataProvider Interface Reference

Interface that must be implemented in order to provide data updates to DataSource peers. More...

Inherited by Caplin.DataSource.Channel.ChannelProvider.

Public Member Functions

void ReceiveDiscard (IDiscardEvent discardEvent)
 Callback that informs the DataProvider that an earlier requested subject has now been discarded and it should stop sending data. More...
 
void ReceiveRequest (IRequestEvent requestEvent)
 Callback that informs the DataProvider that a new request has been received and it should start sending data. More...
 

Detailed Description

Interface that must be implemented in order to provide data updates to DataSource peers.

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.

using System;
using System.Collections.Generic;
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);
}
}
}

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.

Member Function Documentation

void Caplin.DataSource.Publisher.IDataProvider.ReceiveDiscard ( IDiscardEvent  discardEvent)

Callback that informs the DataProvider that an earlier requested subject has now been discarded and it should stop sending data.

Parameters
discardEventThe event that describes the discard (which peer and which subject).

The action that an IDataProvider should take when ReceiveDiscard() is called depends on the type of Caplin.DataSource.Publisher.IPublisher that is being used by the DataSource application.

If the IPublisher is an Caplin.DataSource.Publisher.IActivePublisher the IDataProvider should maintain a record of the peers subscribing to each particular subject. When a peer discard the subject, the IDataProvider should delete the peer from its listm but continue to publish updates for the subject. When there are no more peers subscribing to the subject, the IDataProvider must stop publishing updates.

If the IPublisher is an Caplin.DataSource.Publisher.IBroadcastPublisher, ReceiveDiscard is never called.

void Caplin.DataSource.Publisher.IDataProvider.ReceiveRequest ( IRequestEvent  requestEvent)

Callback that informs the DataProvider that a new request has been received and it should start sending data.

Parameters
requestEventThe event that describes the request (which peer and which subject).

The action that an IDataProvider should take when ReceiveRequest() is called depends on the type of Caplin.DataSource.Publisher.IPublisher that is being used by the DataSource application.

If the IPublisher is an Caplin.DataSource.Publisher.IActivePublisher the IDataProvider should record the peer that has issued the request, and if it is the first request for the subject, it should start sending data. The list of subscribed peers is used to determine when the IDataProvider should stop sending data (see Caplin.DataSource.Publisher.IDataProvider.ReceiveDiscard.

If the IPublisher is an Caplin.DataSource.Publisher.IBroadcastPublisher, ReceiveRequest is never called.


Generated on Wed Jan 24 2018 12:22:40 for DataSource.NET