DataSource.NET  7.1.5.312018
Caplin.DataSource.Publisher.ICachedPublisher Interface Reference

This implementation of IPublisher uses the DataSource.NET data cache so that the IDataProvider implementation does not have to directly manipulate the data in IMessages. More...

Inheritance diagram for Caplin.DataSource.Publisher.ICachedPublisher:
Caplin.DataSource.Publisher.IPublisher

Additional Inherited Members

- Public Member Functions inherited from Caplin.DataSource.Publisher.IPublisher
void PublishInitialMessage (IMessage message)
 Publishes the initial message of the data for a Subject to peers that have just requested (subscribed to) that subject. More...
 
void PublishMappingMessage (IMappingMessage mapping)
 Publishes to all peers subscribed to a subject a message that instructs the remote peer to request an alternate subject in order to satisfy the subscription. More...
 
void PublishSubjectErrorEvent (ISubjectErrorEvent ev)
 Publishes to all peers subscribed to a subject an event detailing an error in the subscription for that subject. Typically an IDataProvider will use this to notify the remote peers that an string they are subscribed to is no longer available. More...
 
void PublishSubjectStatusEvent (ISubjectStatusEvent ev)
 Publishes to all subscribed peers an event about the change in status of a subject. More...
 
void PublishToSubscribedPeers (IMessage message)
 Publishes a message to subscribed peers (that is, the peers that have already received an initial image). More...
 
- Properties inherited from Caplin.DataSource.Publisher.IPublisher
IMessageFactory MessageFactory [get]
 Gets the IMessageFactory used to create the messages that are published via this publisher. More...
 

Detailed Description

This implementation of IPublisher uses the DataSource.NET data cache so that the IDataProvider implementation does not have to directly manipulate the data in IMessages.

This implementation of IPublisher is particularly useful when for dealing with complex DataSource data types, such as Container objects.

An ICachedPublisher passes just the initial subscription request and the final discard from DataSource peers to the IDataProvider. Requests from other peers following the initial request are satisfied by the DataSource.NET cache. This means that the IDataProvider implementation will only receive a single request and a single discard, and it does not need to keep track of the number of requests and discards that the DataSource application has received.

To satisfy subscription requests, the ICachedPublisher queries the ICacheManager for the initial message data and all subsequent update messages. For this to work properly:

  1. Your IDataProvider implementation must create the initial cache entry for an string as it knows what type of data the string refers to. It is also the IDataProvider's responsibility to delete the ICachedObject, if it is appropriate to your system, when the discard is received. If the IDataProvider does not create an ICachedObject in the ICacheManager on the first request for an string, no ICachedObject will be present for it. Subsequently, the ICachedPublisher will not be able to respond to further requests that it would normally handle without the help of the IDataProvider. This may result with the remote Peer timing out its request and not receiving any data.
  2. On each data update from the data providing entity the IDataProvider must update the Caplin.DataSource.Cache.ICachedObject element (for the appropriate string) of the cache using its Update method.
  3. Use the ICachedObjects to obtain all IMessages that are to be published; using the CreateUpdateMessageWithOnlyChangedFields method when sending updates and the CreateImageMessage method when sending images.
  4. Publish updates from the data providing entity using the Caplin.DataSource.Publisher.IPublisher.PublishToSubscribedPeers method as you would for all other publishers, and the initial image (for the sole request only) using the Caplin.DataSource.Publisher.IPublisher.PublishInitialImage. For all other requests that are handled by the ICachedPublisher for you, the ICachedPublisher will send out an initial image automatically using the cache.

Typically the IDataProvider may also wish to delete the cache entry when the data providing entity reports that the data for that string is no longer available. In such a case it is commonly desirable to send an Caplin.DataSource.ISubjectErrorEvent with a SubjectError field set to DeleteObject to inform subscribed peers that the data has been removed from the system.

The following is a simple example of an IDataProvider written for a CachedPublisher. Similar implementations of IDataProvider can be used with the SimplePublisher with the caveat that request/discard counting would be required.

namespace DataSourceExamples.Publisher
{
// Example IDataProvider using a cached publisher which sends back an initial image for all requested records.
public class CachePublisherDataProvider : IDataProvider
{
ICachedPublisher publisher;
DataSource dataSource;
public CachePublisherDataProvider(DataSource dataSource, ICachedPublisher publisher)
{
this.dataSource = dataSource;
this.publisher = publisher;
publisher.DataProvider = this;
}
#region IDataProvider Members
public void ReceiveRequest(IRequestEvent ev)
{
// Create a cached Record.
ICachedRecord cachedRecord = dataSource.CacheManager.GetCachedRecord(ev.Subject);
// Set some fields on the cache.
cachedRecord["Bid"] = "100";
cachedRecord["Ask"] = "102";
// Obtain a cached image and send out the initial update.
publisher.PublishInitialImage(cachedRecord.CreateImageMessage());
}
public void ReceiveDiscard(IDiscardEvent ev)
{
// Delete the cached record, it's no longer required.
dataSource.CacheManager.DeleteCachedObject(ev.Subject);
}
#endregion
}
}

Generated on Sun Oct 21 2018 12:33:23 for DataSource.NET