DataSource.NET  8.0.3.290770-7760911e
Caplin.DataSource.Publisher.ICachingPublisher Interface Reference

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

Inherited by Caplin.DataSource.Publisher.CachingPublisher.

Public Member Functions

void Publish (IMessage message)
 Publishes a message to subscribed peers. 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 ICachingDataProvider 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...
 

Properties

ICachedMessageFactory CachedMessageFactory [get]
 Gets the IMessageFactory used to create the messages that are published via this publisher. More...
 

Detailed Description

This publisher implementation uses the DataSource.NET data cache so that the ICachingDataProvider implementation does not have to directly manipulate the data in IMessages.

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

An ICachingPublisher passes just the initial subscription request and the final discard from DataSource peers to the ICachingDataProvider. Requests from other peers following the initial request are satisfied by the DataSource.NET cache. This means that the ICachingDataProvider 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 ICachingPublisher queries the ICacheManager for the initial message data and all subsequent update messages. For this to work properly:

Publish updates from the data providing entity using the Caplin.DataSource.Publisher.ICachingPublisher.Publish method. For all other requests that are handled by the ICachingPublisher for you, the ICachingPublisher will send out an initial image automatically using the cache.

Typically the ICachingDataProvider 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 ICachingDataProvider written for a CachingPublisher.

namespace DataSourceExamples.Publisher
{
// Example ICachingDataProvider using a cached publisher which sends back an initial image for all requested records.
public class CachingPublisherDataProvider : ICachingDataProvider
{
ICachingPublisher publisher;
public CachingPublisherDataProvider(DataSource dataSource, ICachingPublisher publisher)
{
this.publisher = publisher;
this.publisher = dataSource.CreateCachingPublisher(new PrefixNamespace("/"), this);
}
#region ICachingDataProvider Members
public void ReceiveRequest(string subject)
{
// Create a Record.
IRecordType1Message record = publisher.CachedMessageFactory.CreateRecordType1Message(subject);
// Set some fields on the cache.
record["Bid"] = "100";
record["Ask"] = "102";
// Publishing the initial message adds the it to the cache
publisher.Publish(record);
}
public void ReceiveDiscard(string subject)
{
// The publisher will remove the cache entry when the last peer unsubscribes
}
public void SetPublisher(ICachingPublisher publisher)
{
}
#endregion
}
}

Member Function Documentation

void Caplin.DataSource.Publisher.ICachingPublisher.Publish ( IMessage  message)

Publishes a message to subscribed peers.

Parameters
messageThe message to be published. This may be an image or an update.
void Caplin.DataSource.Publisher.ICachingPublisher.PublishSubjectErrorEvent ( ISubjectErrorEvent  ev)

Publishes to all peers subscribed to a subject an event detailing an error in the subscription for that subject. Typically an ICachingDataProvider will use this to notify the remote peers that an string they are subscribed to is no longer available.

Parameters
evThe ISubjectErrorEvent to be published.
void Caplin.DataSource.Publisher.ICachingPublisher.PublishSubjectStatusEvent ( ISubjectStatusEvent  ev)

Publishes to all subscribed peers an event about the change in status of a subject.

Parameters
evThe subject status event to be published.

Property Documentation

ICachedMessageFactory Caplin.DataSource.Publisher.ICachingPublisher.CachedMessageFactory
get

Gets the IMessageFactory used to create the messages that are published via this publisher.

The message factory.


Generated on Wed Jul 31 2024 17:13:02 for DataSource.NET