C# Class KafkaNet.KafkaTcpSocket

The TcpSocket provides an abstraction from the main driver from having to handle connection to and reconnections with a server. The interface is intentionally limited to only read/write. All connection and reconnect details are handled internally.
Inheritance: IKafkaTcpSocket
Show file Open project: gigya/KafkaNetClient Class Usage Examples

Public Methods

Method Description
Dispose ( ) : void
KafkaTcpSocket ( IKafkaLog log, KafkaNet.Model.KafkaEndpoint endpoint, int maxRetry, System.TimeSpan maximumReconnectionTimeout = null, KafkaNet.Model.StatisticsTrackerOptions statisticsTrackerOptions = null ) : KafkaNet.Common

Construct socket and open connection to a specified server.

ReadAsync ( int readSize ) : Task

Read a certain byte array size return only when all bytes received.

ReadAsync ( int readSize, CancellationToken cancellationToken ) : Task

Read a certain byte array size return only when all bytes received.

WriteAsync ( KafkaDataPayload payload ) : Task

Convenience function to write full buffer data to the server.

WriteAsync ( KafkaDataPayload payload, CancellationToken cancellationToken ) : Task

Write the buffer data to the server.

Private Methods

Method Description
DedicatedSocketTask ( ) : Task

Stop all pendding task when can not establish connection in max retry, but keep trying to recove and connect to this connection. Only the broker router can dispose of it.

EnqueueReadTask ( int readSize, CancellationToken cancellationToken ) : Task
EnqueueWriteTask ( KafkaDataPayload payload, CancellationToken cancellationToken ) : Task
GetStreamAsync ( ) : Task
ProcessNetworkstreamTasks ( NetworkStream netStream ) : Task
ProcessNetworkstreamTasksReadTask ( NetworkStream netStream ) : Task
ProcessNetworkstreamsSendTask ( NetworkStream netStream ) : Task
ProcessReadTaskAsync ( NetworkStream netStream, SocketPayloadReadTask readTask ) : Task
ProcessSentTasksAsync ( NetworkStream netStream, SocketPayloadSendTask sendTask ) : Task
RaiseServerDisconnectedEvent ( ) : void
ReEstablishConnectionAsync ( ) : Task

(Re-)establish the Kafka server connection. Assumes that the caller has already obtained the _clientLock

SetExceptionToAllPendingTasks ( Exception ex ) : void
ThrowTaskExceptionIfFaulted ( Task task ) : Task
UseStatisticsTracker ( ) : bool
WrappedException ( Exception ex ) : Exception

Method Details

Dispose() public method

public Dispose ( ) : void
return void

KafkaTcpSocket() public method

Construct socket and open connection to a specified server.
public KafkaTcpSocket ( IKafkaLog log, KafkaNet.Model.KafkaEndpoint endpoint, int maxRetry, System.TimeSpan maximumReconnectionTimeout = null, KafkaNet.Model.StatisticsTrackerOptions statisticsTrackerOptions = null ) : KafkaNet.Common
log IKafkaLog Logging facility for verbose messaging of actions.
endpoint KafkaNet.Model.KafkaEndpoint The IP endpoint to connect to.
maxRetry int
maximumReconnectionTimeout System.TimeSpan The maximum time to wait when backing off on reconnection attempts.
statisticsTrackerOptions KafkaNet.Model.StatisticsTrackerOptions
return KafkaNet.Common

ReadAsync() public method

Read a certain byte array size return only when all bytes received.
public ReadAsync ( int readSize ) : Task
readSize int The size in bytes to receive from server.
return Task

ReadAsync() public method

Read a certain byte array size return only when all bytes received.
public ReadAsync ( int readSize, CancellationToken cancellationToken ) : Task
readSize int The size in bytes to receive from server.
cancellationToken System.Threading.CancellationToken A cancellation token which will cancel the request.
return Task

WriteAsync() public method

Convenience function to write full buffer data to the server.
public WriteAsync ( KafkaDataPayload payload ) : Task
payload KafkaDataPayload The buffer data to send.
return Task

WriteAsync() public method

Write the buffer data to the server.
public WriteAsync ( KafkaDataPayload payload, CancellationToken cancellationToken ) : Task
payload KafkaDataPayload The buffer data to send.
cancellationToken System.Threading.CancellationToken A cancellation token which will cancel the request.
return Task