Table of Contents

Class KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Namespace
MASES.KNet.Replicator
Assembly
MASES.KNet.dll

Provides a reliable dictionary, persisted in a COMPACTED Kafka topic and shared among applications

public class KNetCompactedReplicator<K, V, TJVMK, TJVMV> : IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, IDictionary<K, V>, ICollection<KeyValuePair<K, V>>, IEnumerable<KeyValuePair<K, V>>, IEnumerable, IDisposable where V : class

Type Parameters

K

The type of keys in the dictionary

V

The type of values in the dictionary. Must be a nullable type

TJVMK

The JVM type of K

TJVMV

The JVM type of V

Inheritance
KNetCompactedReplicator<K, V, TJVMK, TJVMV>
Implements
IKNetCompactedReplicator<K, V, TJVMK, TJVMV>
Derived
Inherited Members

Properties

AccessRights

Get or set AccessRightsType

public AccessRightsType AccessRights { get; set; }

Property Value

AccessRightsType

BootstrapServers

Get or set bootstrap servers

public string BootstrapServers { get; set; }

Property Value

string

ConsumePollTimeout

Get or set the poll timeout to be used for ConsumeAsync(long)

public long ConsumePollTimeout { get; set; }

Property Value

long

ConsumerConfig

public ConsumerConfigBuilder ConsumerConfig { get; set; }

Property Value

ConsumerConfigBuilder

ConsumerInstances

Get or set the number of KNetConsumer<K, V, TJVMK, TJVMV> instances to be used, null to allocate KNetConsumer<K, V, TJVMK, TJVMV> based on Partitions

public int? ConsumerInstances { get; set; }

Property Value

int?

Count

Gets the number of elements contained in this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

public int Count { get; }

Property Value

int

The number of elements contained in this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Exceptions

InvalidOperationException

The provided AccessRights do not include the Read flag

CurrentConsumersSyncState

Reports a snapshot of current sync state the value (true means it is in sync) associated to each consumer (the key).

public IReadOnlyDictionary<int, bool> CurrentConsumersSyncState { get; }

Property Value

IReadOnlyDictionary<int, bool>

Remarks

It is only a snapshot when the property is read and cannot reflect real conditions

CurrentPartitionLags

Reports a snapshot of current lags (the value) associated to each partition (the key).

public IReadOnlyDictionary<int, long> CurrentPartitionLags { get; }

Property Value

IReadOnlyDictionary<int, long>

Remarks

It is only a snapshot when the property is read and cannot reflect real conditions

GroupId

Get or set the group id, if not set a value is generated

public string GroupId { get; set; }

Property Value

string

IsAssigned

true if the instance was started

public bool IsAssigned { get; }

Property Value

bool

IsReadOnly

true if AccessRights do not include the Write flag

public bool IsReadOnly { get; }

Property Value

bool

IsStarted

true if the instance was started

public bool IsStarted { get; }

Property Value

bool

this[K]

Gets or sets the element with the specified keyy. null value removes the specified key

public V this[K key] { get; set; }

Parameters

key K

The key of the element to get or set

Property Value

V

The element with the specified key

Exceptions

InvalidOperationException

The call is get, and the provided AccessRights do not include the Read flag

InvalidOperationException

The call is set, and the provided AccessRights do not include the Write flag

ArgumentNullException

key is null

KeyNotFoundException

The call is get and key is not found

KeySerDes

Get or set an instance of ISerDes<T, TJVMT> to use in KNetCompactedReplicator<K, V, TJVMK, TJVMV>, by default it creates a default one based on K

public ISerDes<K, TJVMK> KeySerDes { get; set; }

Property Value

ISerDes<K, TJVMK>

KeySerDesSelector

The Type used to create an instance of KeySerDes"/>

public Type KeySerDesSelector { get; set; }

Property Value

Type

Keys

Gets an ICollection<T> containing the keys of this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

public ICollection<K> Keys { get; }

Property Value

ICollection<K>

ICollection<T> containing the keys of this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Exceptions

InvalidOperationException

The provided AccessRights do not include the Read flag

OnDelayedStore

It is called to request if the [K, V] can be stored in the IKNetCompactedReplicator<K, V, TJVMK, TJVMV> instance.

public Func<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, bool, KeyValuePair<K, V>, bool> OnDelayedStore { get; set; }

Property Value

Func<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, bool, KeyValuePair<K, V>, bool>

Remarks

The second parameter reports the current value that depends on values set to UpdateMode and if it contains the Delayed

Partitions

Get or set partitions to use when topic is created for the first time, otherwise reports the partiions of the topic

public int Partitions { get; set; }

Property Value

int

ProducerConfig

public ProducerConfigBuilder ProducerConfig { get; set; }

Property Value

ProducerConfigBuilder

ReplicationFactor

Get or set replication factor to use when topic is created for the first time, otherwise reports the replication factor of the topic

public short ReplicationFactor { get; set; }

Property Value

short

StateName

Get or set topic name

public string StateName { get; set; }

Property Value

string

TopicConfig

Get or set TopicConfigBuilder to use when topic is created for the first time

public TopicConfigBuilder TopicConfig { get; set; }

Property Value

TopicConfigBuilder

UpdateMode

Get or set UpdateModeTypes

public UpdateModeTypes UpdateMode { get; set; }

Property Value

UpdateModeTypes

ValueSerDes

Get or set an instance of ISerDes<T, TJVMT> to use in KNetCompactedReplicator<K, V, TJVMK, TJVMV>, by default it creates a default one based on V

public ISerDes<V, TJVMV> ValueSerDes { get; set; }

Property Value

ISerDes<V, TJVMV>

ValueSerDesSelector

The Type used to create an instance of ValueSerDes"/>

public Type ValueSerDesSelector { get; set; }

Property Value

Type

Values

Gets an ICollection<T> containing the values of this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

public ICollection<V> Values { get; }

Property Value

ICollection<V>

ICollection<T> containing the values of this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Exceptions

InvalidOperationException

The provided AccessRights do not include the Read flag

Methods

Add(KeyValuePair<K, V>)

Adds or updates the item in this and others KNetCompactedReplicator<K, V, TJVMK, TJVMV> in the way defined by the UpdateModeTypes provided

public void Add(KeyValuePair<K, V> item)

Parameters

item KeyValuePair<K, V>

The item to add or updates. Value == null means remove key

Exceptions

ArgumentNullException

item.Key is null

InvalidOperationException

The provided AccessRights do not include the Write flag

Add(K, V)

Adds or updates the key in this and others KNetCompactedReplicator<K, V, TJVMK, TJVMV> in the way defined by the UpdateModeTypes provided

public void Add(K key, V value)

Parameters

key K

The object to use as the key of the element to add

value V

The object to use as the value of the element to add. null means remove key

Exceptions

ArgumentNullException

key is null

InvalidOperationException

The provided AccessRights do not include the Write flag

Clear()

Clears this KNetCompactedReplicator<K, V, TJVMK, TJVMV>, resetting all partitions' sync

public void Clear()

Exceptions

InvalidOperationException

The provided AccessRights do not include the Read flag

ConsumerMetrics<TMetric>()

public IReadOnlyDictionary<int, Map<MetricName, TMetric>> ConsumerMetrics<TMetric>() where TMetric : Metric

Returns

IReadOnlyDictionary<int, Map<MetricName, TMetric>>

An IReadOnlyDictionary<TKey, TValue> where the key is the current allocated KNetConsumer<K, V, TJVMK, TJVMV> and value is a Map of MetricName and TMetric

Type Parameters

TMetric

Extends Metric

Contains(KeyValuePair<K, V>)

Determines whether this KNetCompactedReplicator<K, V, TJVMK, TJVMV> contains the specified item

public bool Contains(KeyValuePair<K, V> item)

Parameters

item KeyValuePair<K, V>

The item to locate in this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Returns

bool

true if this KNetCompactedReplicator<K, V, TJVMK, TJVMV> contains an element item; otherwise, false

Exceptions

ArgumentNullException

item.Key is null

InvalidOperationException

The provided AccessRights do not include the Read flag

ContainsKey(K)

Determines whether this KNetCompactedReplicator<K, V, TJVMK, TJVMV> contains an element with the specified key

public bool ContainsKey(K key)

Parameters

key K

The key to locate in this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Returns

bool

true if this KNetCompactedReplicator<K, V, TJVMK, TJVMV> contains an element with key; otherwise, false

Exceptions

ArgumentNullException

key is null

InvalidOperationException

The provided AccessRights do not include the Read flag

CopyTo(KeyValuePair<K, V>[], int)

Copies the elements of this KNetCompactedReplicator<K, V, TJVMK, TJVMV> to an Array, starting at a particular Array index

public void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex)

Parameters

array KeyValuePair<K, V>[]

The one-dimensional Array that is the destination of the elements copied from this KNetCompactedReplicator<K, V, TJVMK, TJVMV>. The Array must have zero-based indexing

arrayIndex int

The zero-based index in array at which copying begins

Exceptions

ArgumentNullException

array is null

ArgumentOutOfRangeException

arrayIndex is less than zero

ArgumentException

array is multidimensional. -or- The number of elements in the source KNetCompactedReplicator<K, V, TJVMK, TJVMV> is greater than the available space from arrayIndex to the end of the destination array. -or- The type of the source KNetCompactedReplicator<K, V, TJVMK, TJVMV> cannot be cast automatically to the type of the destination array

InvalidOperationException

The provided AccessRights do not include the Read flag

Dispose()

Release all managed and unmanaged resources

public void Dispose()

Flush()

Waits until all outstanding produce requests and delivery report callbacks are completed

public void Flush()

GetEnumerator()

Returns an enumerator that iterates through this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

public IEnumerator<KeyValuePair<K, V>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<K, V>>

An enumerator for this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Exceptions

InvalidOperationException

The provided AccessRights do not include the Read flag

ProducerMetrics<TMetric>()

public Map<MetricName, TMetric> ProducerMetrics<TMetric>() where TMetric : Metric

Returns

Map<MetricName, TMetric>

A Map of MetricName and TMetric

Type Parameters

TMetric

Extends Metric

Remove(KeyValuePair<K, V>)

Removes the item from this and others KNetCompactedReplicator<K, V, TJVMK, TJVMV> in the way defined by the UpdateModeTypes provided

public bool Remove(KeyValuePair<K, V> item)

Parameters

item KeyValuePair<K, V>

Item to be removed

Returns

bool

true if the removal request is delivered to the others KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Exceptions

ArgumentNullException

item.Key is null

InvalidOperationException

The provided AccessRights do not include the Write flag

Remove(K)

Removes the key from this and others KNetCompactedReplicator<K, V, TJVMK, TJVMV> in the way defined by the UpdateModeTypes provided

public bool Remove(K key)

Parameters

key K

The key of the element to remove

Returns

bool

true if the removal request is delivered to the others KNetCompactedReplicator<K, V, TJVMK, TJVMV>

Exceptions

ArgumentNullException

key is null

InvalidOperationException

The provided AccessRights do not include the Write flag

Start()

Start this KNetCompactedReplicator<K, V, TJVMK, TJVMV>: create the StateName topic if not available, allocates Producer and Consumer, sets serializer/deserializer

public void Start()

Exceptions

InvalidOperationException

Some errors occurred

StartAndWait(int)

Start this KNetCompactedReplicator<K, V, TJVMK, TJVMV>: create the StateName topic if not available, allocates Producer and Consumers, sets serializer/deserializer Then waits its synchronization with StateName topic which stores dictionary data

public bool StartAndWait(int timeout = -1)

Parameters

timeout int

The number of milliseconds to wait, or Infinite to wait indefinitely

Returns

bool

true if the current instance synchronize within the given timeout; otherwise, false

Exceptions

InvalidOperationException

Some errors occurred or the provided AccessRights do not include the Read flag

SyncWait(int)

Waits that KNetCompactedReplicator<K, V, TJVMK, TJVMV> is synchronized to the StateName topic which stores dictionary data

public bool SyncWait(int timeout = -1)

Parameters

timeout int

The number of milliseconds to wait, or Infinite to wait indefinitely

Returns

bool

true if the current instance synchronize within the given timeout; otherwise, false

Exceptions

InvalidOperationException

The provided AccessRights do not include the Read flag

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

TryGetValue(K, out V)

Attempts to get the value associated with the specified key from this KNetCompactedReplicator<K, V, TJVMK, TJVMV>

public bool TryGetValue(K key, out V value)

Parameters

key K

The key of the value to get

value V

When this method returns, contains the object from this KNetCompactedReplicator<K, V, TJVMK, TJVMV> that has the specified key, or the default value of the type if the operation failed

Returns

bool

true if the key was found in this KNetCompactedReplicator<K, V, TJVMK, TJVMV>; otherwise, false

Exceptions

ArgumentNullException

key is null

InvalidOperationException

The provided AccessRights do not include the Read flag

WaitForStateAssignment(int)

Waits for all paritions assignment of the StateName topic which stores dictionary data

public bool WaitForStateAssignment(int timeout = -1)

Parameters

timeout int

The number of milliseconds to wait, or Infinite to wait indefinitely

Returns

bool

true if the current instance receives a signal within the given timeout; otherwise, false

Exceptions

InvalidOperationException

The provided AccessRights do not include the Read flag

Events

OnLocalAdd

Called when a [K, V] is added on this IKNetCompactedReplicator<K, V, TJVMK, TJVMV>

public event Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>> OnLocalAdd

Event Type

Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>>

OnLocalRemove

Called when a [K, V] is removed from this IKNetCompactedReplicator<K, V, TJVMK, TJVMV>

public event Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>> OnLocalRemove

Event Type

Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>>

OnLocalUpdate

Called when a [K, V] is updated on this IKNetCompactedReplicator<K, V, TJVMK, TJVMV>

public event Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>> OnLocalUpdate

Event Type

Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>>

OnRemoteAdd

Called when a [K, V] is added by consuming data from the others IKNetCompactedReplicator<K, V, TJVMK, TJVMV>

public event Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>> OnRemoteAdd

Event Type

Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>>

OnRemoteRemove

Called when a [K, V] is removed by consuming data from the others IKNetCompactedReplicator<K, V, TJVMK, TJVMV>

public event Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>> OnRemoteRemove

Event Type

Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>>

OnRemoteUpdate

Called when a [K, V] is updated by consuming data from the others IKNetCompactedReplicator<K, V, TJVMK, TJVMV>

public event Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>> OnRemoteUpdate

Event Type

Action<IKNetCompactedReplicator<K, V, TJVMK, TJVMV>, KeyValuePair<K, V>>