TROSCClientWorker

Overview

This is the super channel worker class designed to use on the client side.
This class is used internally, users will never intercat with it.

Location

 

constructor Create (TROBaseSuperConnection)    (declared in TROBaseSuperChannelWorker)

Creates the worker instance.

constructor Create(ABaseSuperConnection: TROBaseSuperConnection)

Parameters:

  • ABaseSuperConnection: The connection object to be associated with the worker, TROBaseSuperConnection instance.

Creates the worker instance.

constructor Create(aOwner: TROBaseSuperTCPChannel; ABaseSuperConnection: TROBaseSuperConnection)

Parameters:

  • aOwner: The super channel instance that the worker works for.
  • ABaseSuperConnection: The connection object that worker will use for communication.

BaseSuperConnection  protected    (declared in TROBaseSuperChannelWorker)

Provides read-only access to the connection object (incoming or outgoing) that is paired with the worker object. The connection object is a TROBaseSuperConnection descendant and is assigned by the constructor.

property BaseSuperConnection: TROBaseSuperConnection read write

BeginWriteLock    (declared in TROBaseSuperChannelWorker)

Acquires a lock using the internal synchronization object, used to synchronize write access to the underlying socket.

procedure BeginWriteLock

ClientID    (declared in TROBaseSuperChannelWorker)

Gets or set the client unique identifer.

property ClientID: TGuid read write

Connected  protected override

Called after the connection to the remote party established to do any specific actions at this moment.

procedure Connected

Disconnect    (declared in TROBaseSuperChannelWorker)

Instructs the connection object to disconnect.

procedure Disconnect

Disconnected  protected override

Called after the connection to the remote party is disconnected to do any specific actions at this moment.

procedure Disconnected(var RestartLoop: Boolean)

Parameters:

  • RestartLoop: If set to true indicates that the connection is going to be reestablished.

DoExecute    (declared in TROBaseSuperChannelWorker)

The main processing method that is executed on a background thread.

procedure DoExecute

EndWriteLock    (declared in TROBaseSuperChannelWorker)

Releases a lock using the internal synchronization object, used to synchronize write access to the underlying socket.

procedure EndWriteLock

GenerateId    (declared in TROBaseSuperChannelWorker)

Used to generate a new package identifier in a thread safe manner. The package id is actually an order number of the data package (remote requests transmitted from clients to servers and events data transmitted from servers to clients) transmitted since the superchannel start. It increments from 1 to MaxInt for clients and decrements from -1 down to -MaxInt for servers. This method acquires a write lock prior to generate a new package id.

function GenerateId: Integer

GetDefaultResponse  protected virtual    (declared in TROBaseSuperChannelWorker)

Returns a string that is transmitted to the socket in case of any superchannel protocol error. Superchannel protocol errors can happen when the remote party behavior differs from the one expected according to the superchannel protocol. Usually this happens when non-super channel is used on the remote side or remote superchannel implementation has errors.

function GetDefaultResponse: string

Idle  protected override

This method is executed when the channel enters idle state: existing connection is disconnected and a new one is not established yet.

procedure Idle

IncomingData  protected override

This method is called when the data package has been read from the socket.

procedure IncomingData(Id: Integer; aData: TStream)

Parameters:

  • Id: The package id received.
  • aData: The stream containing the incoming data, payload only.

IsConnected    (declared in TROBaseSuperChannelWorker)

Allows to get or set the connected state flag that indicates wether the connection associated with the worker is established.

property IsConnected: Boolean read write

IsServer  protected    (declared in TROBaseSuperChannelWorker)

Allows to get or set the flag that allows to distinguish client side worker from server ones. The value for this flag is set once by the constructor code of the derived class and is used by the unified code that supports superchannel protocol.

property IsServer: Boolean read write

LastData  protected    (declared in TROBaseSuperChannelWorker)

Allows to get the last channel activity date and time. This value is reset every time the channel is about to send a data package or received one.

property LastData: TDateTime read write

MaxPackageSize    (declared in TROBaseSuperChannelWorker)

Determines the maximum size of the package that can be transmitted through the channel. The worker code compares this value to the data size to be transmitted and throws an exception in case of oversize.

property MaxPackageSize: Integer read write

OnProgress    (declared in TROBaseSuperChannelWorker)

This event is fired while buffered data transmission is performed (IntSendData and ReadStream methods). The event is fired after each data portion transmitted.

property OnProgress: TProgressEvent read write
delegate: procedure OnProgress(iSender: TObject; iType: TProgressType; iDirection: TProgressDirection; iTransferred: integer; iTotal: integer)

Owner

Provides read-only access to the super channel instance that the worker works for.

property Owner: TROBaseSuperTCPChannel read write

PingFrequency  protected    (declared in TROBaseSuperChannelWorker)

Determines the time interval in seconds between attempts to send a ping package (such packages are used to make sure the remote party is up ad running, has nothing to with ICMP pings).

property PingFrequency: Integer read write

PingTimeout  protected    (declared in TROBaseSuperChannelWorker)

Determines the time interval in seconds for remote party to answer a ping request package (such packages are used to make sure the remote party is up and running, has nothing to with ICMP pings). If ping request was not answered than the connection is considered broken so the client side reconnects and the server side removes the lost connection data from the memory.

property PingTimeout: Integer read write

ProcessOption  protected    (declared in TROBaseSuperChannelWorker)

Called to process protocol options agreement packages.

procedure ProcessOption(Data: TStream)

Parameters:

  • Data: The stream containing the options agreement package.

ReadStream  protected    (declared in TROBaseSuperChannelWorker)

Performs the buffered read from the associated connection object (finally from the socket).

function ReadStream(aDest: TStream; aLen: Integer): Boolean

Parameters:

  • aDest: The stream to place the data into.
  • aLen: The number of bytes to read.

SendError    (declared in TROBaseSuperChannelWorker)

The method to send the higher level error messages to the remote party. Used to transmit package errors such as the package oversize.

procedure SendError(Id: Integer; Error: Byte)

Parameters:

  • Id: The package id to use when sending data.
  • Error: The error code.

SendOptions  protected    (declared in TROBaseSuperChannelWorker)

Sends the protocol options agreement package.

procedure SendOptions(aData: ROUTF8String)

Parameters:

  • aData: The package content, in the string form.

SendPackage    (declared in TROBaseSuperChannelWorker)

Sends the package to the channel. The IntSendData method is used. For convenience this method is able to generate a new package id and acquire a write lock.

function SendPackage(aData: TStream; Id: Integer): IROPackageAck

Parameters:

  • aData: The data to send, payload only.
  • Id: The package id to use, 0 may be passed to generate and use a new id.

SetAckDetails  protected override

procedure SetAckDetails(Id: Integer; Oke: Boolean; ErrorNo: Integer)

Parameters:

  • Id:
  • Oke:
  • ErrorNo:

SkipAck    (declared in TROBaseSuperChannelWorker)

property SkipAck: Boolean read write

SupportsOptions  protected    (declared in TROBaseSuperChannelWorker)

Called when the remote party initiates the protocol options agreement. Calls SendOptions to send the required options information.

procedure SupportsOptions

WaitForAck    (declared in TROBaseSuperChannelWorker)

The utility method to wait for acknowledgement package from the remote party and analyzes it's content. Throws exceptions if any errors detected.

class procedure WaitForAck(pkg: IROPackageAck; Timeout: Integer)

Parameters:

  • pkg: The object describing acknowledgement package.
  • Timeout: Package wait timeout.

 

BaseSuperConnection  protected    (declared in TROBaseSuperChannelWorker)

Provides read-only access to the connection object (incoming or outgoing) that is paired with the worker object. The connection object is a TROBaseSuperConnection descendant and is assigned by the constructor.

property BaseSuperConnection: TROBaseSuperConnection read write

ClientID    (declared in TROBaseSuperChannelWorker)

Gets or set the client unique identifer.

property ClientID: TGuid read write

IsConnected    (declared in TROBaseSuperChannelWorker)

Allows to get or set the connected state flag that indicates wether the connection associated with the worker is established.

property IsConnected: Boolean read write

IsServer  protected    (declared in TROBaseSuperChannelWorker)

Allows to get or set the flag that allows to distinguish client side worker from server ones. The value for this flag is set once by the constructor code of the derived class and is used by the unified code that supports superchannel protocol.

property IsServer: Boolean read write

LastData  protected    (declared in TROBaseSuperChannelWorker)

Allows to get the last channel activity date and time. This value is reset every time the channel is about to send a data package or received one.

property LastData: TDateTime read write

MaxPackageSize    (declared in TROBaseSuperChannelWorker)

Determines the maximum size of the package that can be transmitted through the channel. The worker code compares this value to the data size to be transmitted and throws an exception in case of oversize.

property MaxPackageSize: Integer read write

Owner

Provides read-only access to the super channel instance that the worker works for.

property Owner: TROBaseSuperTCPChannel read write

PingFrequency  protected    (declared in TROBaseSuperChannelWorker)

Determines the time interval in seconds between attempts to send a ping package (such packages are used to make sure the remote party is up ad running, has nothing to with ICMP pings).

property PingFrequency: Integer read write

PingTimeout  protected    (declared in TROBaseSuperChannelWorker)

Determines the time interval in seconds for remote party to answer a ping request package (such packages are used to make sure the remote party is up and running, has nothing to with ICMP pings). If ping request was not answered than the connection is considered broken so the client side reconnects and the server side removes the lost connection data from the memory.

property PingTimeout: Integer read write

SkipAck    (declared in TROBaseSuperChannelWorker)

property SkipAck: Boolean read write

 

WaitForAck    (declared in TROBaseSuperChannelWorker)

The utility method to wait for acknowledgement package from the remote party and analyzes it's content. Throws exceptions if any errors detected.

class procedure WaitForAck(pkg: IROPackageAck; Timeout: Integer)

Parameters:

  • pkg: The object describing acknowledgement package.
  • Timeout: Package wait timeout.

 

constructor Create (TROBaseSuperConnection)    (declared in TROBaseSuperChannelWorker)

Creates the worker instance.

constructor Create(ABaseSuperConnection: TROBaseSuperConnection)

Parameters:

  • ABaseSuperConnection: The connection object to be associated with the worker, TROBaseSuperConnection instance.

Creates the worker instance.

constructor Create(aOwner: TROBaseSuperTCPChannel; ABaseSuperConnection: TROBaseSuperConnection)

Parameters:

  • aOwner: The super channel instance that the worker works for.
  • ABaseSuperConnection: The connection object that worker will use for communication.

BeginWriteLock    (declared in TROBaseSuperChannelWorker)

Acquires a lock using the internal synchronization object, used to synchronize write access to the underlying socket.

procedure BeginWriteLock

Connected  protected override

Called after the connection to the remote party established to do any specific actions at this moment.

procedure Connected

Disconnect    (declared in TROBaseSuperChannelWorker)

Instructs the connection object to disconnect.

procedure Disconnect

Disconnected  protected override

Called after the connection to the remote party is disconnected to do any specific actions at this moment.

procedure Disconnected(var RestartLoop: Boolean)

Parameters:

  • RestartLoop: If set to true indicates that the connection is going to be reestablished.

DoExecute    (declared in TROBaseSuperChannelWorker)

The main processing method that is executed on a background thread.

procedure DoExecute

EndWriteLock    (declared in TROBaseSuperChannelWorker)

Releases a lock using the internal synchronization object, used to synchronize write access to the underlying socket.

procedure EndWriteLock

GenerateId    (declared in TROBaseSuperChannelWorker)

Used to generate a new package identifier in a thread safe manner. The package id is actually an order number of the data package (remote requests transmitted from clients to servers and events data transmitted from servers to clients) transmitted since the superchannel start. It increments from 1 to MaxInt for clients and decrements from -1 down to -MaxInt for servers. This method acquires a write lock prior to generate a new package id.

function GenerateId: Integer

GetDefaultResponse  protected virtual    (declared in TROBaseSuperChannelWorker)

Returns a string that is transmitted to the socket in case of any superchannel protocol error. Superchannel protocol errors can happen when the remote party behavior differs from the one expected according to the superchannel protocol. Usually this happens when non-super channel is used on the remote side or remote superchannel implementation has errors.

function GetDefaultResponse: string

Idle  protected override

This method is executed when the channel enters idle state: existing connection is disconnected and a new one is not established yet.

procedure Idle

IncomingData  protected override

This method is called when the data package has been read from the socket.

procedure IncomingData(Id: Integer; aData: TStream)

Parameters:

  • Id: The package id received.
  • aData: The stream containing the incoming data, payload only.

ProcessOption  protected    (declared in TROBaseSuperChannelWorker)

Called to process protocol options agreement packages.

procedure ProcessOption(Data: TStream)

Parameters:

  • Data: The stream containing the options agreement package.

ReadStream  protected    (declared in TROBaseSuperChannelWorker)

Performs the buffered read from the associated connection object (finally from the socket).

function ReadStream(aDest: TStream; aLen: Integer): Boolean

Parameters:

  • aDest: The stream to place the data into.
  • aLen: The number of bytes to read.

SendError    (declared in TROBaseSuperChannelWorker)

The method to send the higher level error messages to the remote party. Used to transmit package errors such as the package oversize.

procedure SendError(Id: Integer; Error: Byte)

Parameters:

  • Id: The package id to use when sending data.
  • Error: The error code.

SendOptions  protected    (declared in TROBaseSuperChannelWorker)

Sends the protocol options agreement package.

procedure SendOptions(aData: ROUTF8String)

Parameters:

  • aData: The package content, in the string form.

SendPackage    (declared in TROBaseSuperChannelWorker)

Sends the package to the channel. The IntSendData method is used. For convenience this method is able to generate a new package id and acquire a write lock.

function SendPackage(aData: TStream; Id: Integer): IROPackageAck

Parameters:

  • aData: The data to send, payload only.
  • Id: The package id to use, 0 may be passed to generate and use a new id.

SetAckDetails  protected override

procedure SetAckDetails(Id: Integer; Oke: Boolean; ErrorNo: Integer)

Parameters:

  • Id:
  • Oke:
  • ErrorNo:

SupportsOptions  protected    (declared in TROBaseSuperChannelWorker)

Called when the remote party initiates the protocol options agreement. Calls SendOptions to send the required options information.

procedure SupportsOptions

 

OnProgress    (declared in TROBaseSuperChannelWorker)

This event is fired while buffered data transmission is performed (IntSendData and ReadStream methods). The event is fired after each data portion transmitted.

property OnProgress: TProgressEvent read write
delegate: procedure OnProgress(iSender: TObject; iType: TProgressType; iDirection: TProgressDirection; iTransferred: integer; iTotal: integer)