TROEventSessionManager

Overview

TROEventSessionManager implements a session manager that uses events to allow the use of custom code to access and store session data in user-defined ways.

Whenever the session manager needs to access or update session data, an event is fired.

The OnFindSession, OnReleaseSession, OnDeleteSession events are fired to access and store session data. These three events must be assigned for the session manager to be functional.

Location

 

constructor Create  override    (declared in TROCustomSessionManager)

Creates a new instance.

constructor Create(aOwner: TComponent)

Parameters:

  • aOwner: Owner.

Assign  override

Copies the contents of another, similar object.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

CheckProperties  virtual    (declared in TROCustomSessionManager)

Validates the session manager properties.

procedure CheckProperties

CheckSessionIsExpired (TGUID): boolean  overload    (declared in TROCustomSessionManager)

Checks state of given session or not.

function CheckSessionIsExpired(const aSessionID: TGUID): boolean

Parameters:

  • aSessionID: Session ID

CheckSessionIsExpired (TROSession): boolean  overload    (declared in TROCustomSessionManager)

Checks state of given session.

function CheckSessionIsExpired(aSession: TROSession): boolean

Parameters:

  • aSession: Given session.

Clearing  protected    (declared in TROCustomSessionManager)

internal flag that is set when session are clearing

property Clearing: boolean read write

ClearSessions    (declared in TROCustomSessionManager)

Discards all sessions within the session manager, so that any new call from a client will start with a fresh session.

procedure ClearSessions(OnlyExpired: boolean)

Parameters:

  • OnlyExpired: process only expired sessions or not.

CreateSession    (declared in TROCustomSessionManager)

Creates a new session with provided ID.

function CreateSession(const aSessionID: TGUID): TROSession

Parameters:

  • aSessionID: Session ID

CreateTimerByRequest  protected    (declared in TROCustomSessionManager)

Creates internal timer.

procedure CreateTimerByRequest

Critical    (declared in TROCustomSessionManager)

Default critical session.

property Critical: TCriticalSection read write

DeleteSession    (declared in TROCustomSessionManager)

Deletes the session with specified ID.

procedure DeleteSession(const aSessionID: TGUID; IsExpired: boolean)

Parameters:

  • aSessionID: Session ID
  • IsExpired: current state of session

DeleteTemporarySession    (declared in TROCustomSessionManager)

Deletes the temporary session.

procedure DeleteTemporarySession(var Session: TROSession)

Parameters:

  • Session: given session.

DoClearSessions  protected override

Discards all sessions within the session manager, so that any new call from a client will start with a fresh session.

procedure DoClearSessions(OnlyExpired: boolean)

Parameters:

  • OnlyExpired: process only expired sessions or not.

DoCreateSession  protected virtual    (declared in TROCustomSessionManager)

Creates a new session with provided ID.

function DoCreateSession(const aSessionID: TGUID): TROSession

Parameters:

  • aSessionID: Session ID

DoDeleteSession  protected override

Deletes the session with specified ID.

procedure DoDeleteSession(const aSessionID: TGUID; IsExpired: boolean)

Parameters:

  • aSessionID: Session ID
  • IsExpired: current state of session

DoFindSession  protected override

Finds session with the specified GUID

function DoFindSession(const aSessionID: TGUID; aUpdateTime: Boolean): TROSession

Parameters:

  • aSessionID: Session ID.
  • aUpdateTime: Update LastAccess of found session or not

DoGetAllSessions  protected override

Returns a string list containing the IDs of all currently active sessions.

procedure DoGetAllSessions(Dest: TStringList)

Parameters:

  • Dest: destination

DoGetAllSessionsIDs  protected virtual    (declared in TROCustomSessionManager)

function DoGetAllSessionsIDs: TROSessionIDs

DoGetSessionCount  protected override

Returns the session count.

function DoGetSessionCount: integer

DoIsSessionPresent  protected override

function DoIsSessionPresent(const aSessionID: TGUID): Boolean

Parameters:

  • aSessionID:

DoNotifySessionsChangesListener  protected virtual    (declared in TROCustomSessionManager)

Notifies attached listeners about changes

procedure DoNotifySessionsChangesListener(const aSessionID: TGUID; aSessionAction: TROSessionsActions; Sender: TObject)

Parameters:

  • aSessionID: Session ID
  • aSessionAction: action
  • Sender: sender

DoReleaseSession  protected override

Releases the previously acquired session.

procedure DoReleaseSession(aSession: TROSession; NewSession: boolean)

Parameters:

  • aSession: given session
  • NewSession: newly created session or not

DoTimerTick  protected virtual    (declared in TROCustomSessionManager)

Clears expired sessions.

procedure DoTimerTick(CurrentTickCount: cardinal)

Parameters:

  • CurrentTickCount: ignored

FindSession    (declared in TROCustomSessionManager)

Finds session with the specified GUID

function FindSession(const aSessionID: TGUID; aUpdateTime: Boolean): TROSession

Parameters:

  • aSessionID: Session ID.
  • aUpdateTime: Update LastAccess of found session or not

GetAllSessions  overload    (declared in TROCustomSessionManager)

function GetAllSessions: TROSessionIDs

GetAllSessions (TStringList)  overload    (declared in TROCustomSessionManager)

Returns a string list containing the IDs of all currently active sessions. Depending on the session manager and on your application architecture, this list can be huge, especially when using a database based session list that is shared by a large server farm. Obtaining the full list of sessions can be a costly process.

procedure GetAllSessions(Dest: TStringList)

Parameters:

  • Dest: destination

GetSessionCount    (declared in TROCustomSessionManager)

Returns the session count.

function GetSessionCount: integer

IsSessionPresent    (declared in TROCustomSessionManager)

function IsSessionPresent(const aSessionID: TGUID): Boolean

Parameters:

  • aSessionID:

KillTimer  protected    (declared in TROCustomSessionManager)

Kills internal timer

procedure KillTimer

MaxSessions    (declared in TROCustomSessionManager)

Specifies the maximum number of sessions that will be allowed. -1 (the default) indicates that no limit on number of sessions will be enforced. Allowing a server to run without enforcing any limit on the number of sessions might pose a security risk, as malicious clients could theoretically start an infinite number of sessions by performing repeated requests with changing Client IDs, until server memory is depleted. You should make sure to either set a limit, or tie session creation to user authentication, so that only valid client users can obtain a session(and possibly only one session per login).

property MaxSessions: integer read write

OnBeforeDeleteSession    (declared in TROCustomSessionManager)

Fires before deleting session.

property OnBeforeDeleteSession: TDeleteSessionEvent read write
delegate: procedure OnBeforeDeleteSession(const aSessionID: TGUID; IsExpired: boolean)

OnClearSessions

Fired when the session storage should be cleared. Depending on the value of the OnlyExpired parameter, the event handler should either clear the entire session list (on false), or only remove those sessions that have expired (on true).

property OnClearSessions: TClearSessionsEvent read write
delegate: procedure OnClearSessions(SessionManager: TROCustomSessionManager; OnlyExpired: boolean)

OnCustomCreateSession    (declared in TROCustomSessionManager)

Fires before the session is created. It allows to return existing session for given session ID

property OnCustomCreateSession: TROCustomSessionCreationEvent read write
delegate: procedure OnCustomCreateSession(const aSessionID: TGUID; var Session: TROSession)

OnDeleteSession

Fired when a specific session should be deleted, either because it has expired or it has explicitly been destroyed. This event handler should remove the session from storage.

property OnDeleteSession: TDeleteSessionEvent read write
delegate: procedure OnDeleteSession(const aSessionID: TGUID; IsExpired: boolean)

OnException    (declared in TROCustomSessionManager)

Fires when an exception is occuring

property OnException: TROSessionExceptionEvent read write
delegate: procedure OnException(aSessionID: TGUID; anException: Exception; var aRetry: Boolean)

OnFindSession

Fired when session data for a specific session is needed. It is up to the event handler to obtain this data from storage or create a new session if necessary.

property OnFindSession: TFindSessionEvent read write
delegate: procedure OnFindSession(const aSessionID: TGUID; out aSession: TROSession)

OnGetAllSessions

Fired to obtain a list of all available session IDs, when GetAllSessions is called.

property OnGetAllSessions: TGetAllSessionsEvent read write
delegate: procedure OnGetAllSessions(SessionManager: TROCustomSessionManager; aDest: TStringList)

OnGetSessionCount

Fired to obtain the total number of sessions available.

property OnGetSessionCount: TGetSessionCountEvent read write
delegate: function OnGetSessionCount(SessionManager: TROCustomSessionManager): integer

OnIsSessionExpiredEvent

property OnIsSessionExpiredEvent: TIsSessionExpiredEvent read write
delegate: function OnIsSessionExpiredEvent(SessionManager: TROCustomSessionManager; const aSessionID: TGUID): Boolean

OnIsSessionPresentEvent

property OnIsSessionPresentEvent: TIsSessionPresentEvent read write
delegate: function OnIsSessionPresentEvent(SessionManager: TROCustomSessionManager; const aSessionID: TGUID): Boolean

OnMaxSessionsReached    (declared in TROCustomSessionManager)

Fires when maximum count of allowed sessions is reached

property OnMaxSessionsReached: TROMaxSessionsReachedEvent read write
delegate: procedure OnMaxSessionsReached(var aFail: Boolean)

OnReleaseSession

Fired when a specific session is released. This event handler should store the data so the future calls to OnFindSession can access it.

property OnReleaseSession: TReleaseSessionEvent read write
delegate: procedure OnReleaseSession(var aSession: TROSession; NewSession: boolean)

OnSessionCreated    (declared in TROCustomSessionManager)

Gets triggered after a new Session has been created. You can use it to perform initialization functions or fill the session with default values.

property OnSessionCreated: TSessionEvent read write
delegate: procedure OnSessionCreated(const aSession: TROSession)

OnSessionDeleted    (declared in TROCustomSessionManager)

Gets triggered after the Session has been deleted. You can use it to perform some finalization functions.

property OnSessionDeleted: TDeleteSessionEvent read write
delegate: procedure OnSessionDeleted(const aSessionID: TGUID; IsExpired: boolean)

RegisterSessionsChangesListener  protected virtual    (declared in TROCustomSessionManager)

Attaches a new IROSessionsChangesListener listener.

procedure RegisterSessionsChangesListener(aListener: IROSessionsChangesListener)

Parameters:

  • aListener: New listener

ReleaseSession    (declared in TROCustomSessionManager)

Releases the previously acquired session.

procedure ReleaseSession(var aSession: TROSession; NewSession: boolean)

Parameters:

  • aSession: given session
  • NewSession: newly created session or not

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned RO components.

procedure ROFreeNotification(AComponent: TComponent)

Parameters:

  • AComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Disables destruction notification for specified RO component.

procedure RORemoveFreeNotification(AComponent: TComponent)

Parameters:

  • AComponent: component

SessionCheckInterval

Internal for checking session in minutes. default value is 15 minutes.

property SessionCheckInterval:

SessionDuration

The time, in minutes, that sessions will persist before timing out (default is 15 minutes).The timeout for each individual session will be reset every time the session is accessed; after SessionDuration minutes have passed without access to the session, it will be discarded. The exact handling of the timeout processing depends on the implementation of the specific session manager, which might check session timeouts at intervals. Therefore, sessions might live slightly longer then the specified timeout.

property SessionDuration:

TestLastAccess  protected    (declared in TROCustomSessionManager)

function TestLastAccess(const aLastAccess: TDateTime): Boolean

Parameters:

  • aLastAccess:

UnRegisterSessionsChangesListener  protected virtual    (declared in TROCustomSessionManager)

Detaches a previously attached aListener.

procedure UnRegisterSessionsChangesListener(aListener: IROSessionsChangesListener)

Parameters:

  • aListener: Known listener

 

Clearing  protected    (declared in TROCustomSessionManager)

internal flag that is set when session are clearing

property Clearing: boolean read write

Critical    (declared in TROCustomSessionManager)

Default critical session.

property Critical: TCriticalSection read write

MaxSessions    (declared in TROCustomSessionManager)

Specifies the maximum number of sessions that will be allowed. -1 (the default) indicates that no limit on number of sessions will be enforced. Allowing a server to run without enforcing any limit on the number of sessions might pose a security risk, as malicious clients could theoretically start an infinite number of sessions by performing repeated requests with changing Client IDs, until server memory is depleted. You should make sure to either set a limit, or tie session creation to user authentication, so that only valid client users can obtain a session(and possibly only one session per login).

property MaxSessions: integer read write

SessionCheckInterval

Internal for checking session in minutes. default value is 15 minutes.

property SessionCheckInterval:

SessionDuration

The time, in minutes, that sessions will persist before timing out (default is 15 minutes).The timeout for each individual session will be reset every time the session is accessed; after SessionDuration minutes have passed without access to the session, it will be discarded. The exact handling of the timeout processing depends on the implementation of the specific session manager, which might check session timeouts at intervals. Therefore, sessions might live slightly longer then the specified timeout.

property SessionDuration:

 

constructor Create  override    (declared in TROCustomSessionManager)

Creates a new instance.

constructor Create(aOwner: TComponent)

Parameters:

  • aOwner: Owner.

Assign  override

Copies the contents of another, similar object.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

CheckProperties  virtual    (declared in TROCustomSessionManager)

Validates the session manager properties.

procedure CheckProperties

CheckSessionIsExpired (TGUID): boolean  overload    (declared in TROCustomSessionManager)

Checks state of given session or not.

function CheckSessionIsExpired(const aSessionID: TGUID): boolean

Parameters:

  • aSessionID: Session ID

CheckSessionIsExpired (TROSession): boolean  overload    (declared in TROCustomSessionManager)

Checks state of given session.

function CheckSessionIsExpired(aSession: TROSession): boolean

Parameters:

  • aSession: Given session.

ClearSessions    (declared in TROCustomSessionManager)

Discards all sessions within the session manager, so that any new call from a client will start with a fresh session.

procedure ClearSessions(OnlyExpired: boolean)

Parameters:

  • OnlyExpired: process only expired sessions or not.

CreateSession    (declared in TROCustomSessionManager)

Creates a new session with provided ID.

function CreateSession(const aSessionID: TGUID): TROSession

Parameters:

  • aSessionID: Session ID

CreateTimerByRequest  protected    (declared in TROCustomSessionManager)

Creates internal timer.

procedure CreateTimerByRequest

DeleteSession    (declared in TROCustomSessionManager)

Deletes the session with specified ID.

procedure DeleteSession(const aSessionID: TGUID; IsExpired: boolean)

Parameters:

  • aSessionID: Session ID
  • IsExpired: current state of session

DeleteTemporarySession    (declared in TROCustomSessionManager)

Deletes the temporary session.

procedure DeleteTemporarySession(var Session: TROSession)

Parameters:

  • Session: given session.

DoClearSessions  protected override

Discards all sessions within the session manager, so that any new call from a client will start with a fresh session.

procedure DoClearSessions(OnlyExpired: boolean)

Parameters:

  • OnlyExpired: process only expired sessions or not.

DoCreateSession  protected virtual    (declared in TROCustomSessionManager)

Creates a new session with provided ID.

function DoCreateSession(const aSessionID: TGUID): TROSession

Parameters:

  • aSessionID: Session ID

DoDeleteSession  protected override

Deletes the session with specified ID.

procedure DoDeleteSession(const aSessionID: TGUID; IsExpired: boolean)

Parameters:

  • aSessionID: Session ID
  • IsExpired: current state of session

DoFindSession  protected override

Finds session with the specified GUID

function DoFindSession(const aSessionID: TGUID; aUpdateTime: Boolean): TROSession

Parameters:

  • aSessionID: Session ID.
  • aUpdateTime: Update LastAccess of found session or not

DoGetAllSessions  protected override

Returns a string list containing the IDs of all currently active sessions.

procedure DoGetAllSessions(Dest: TStringList)

Parameters:

  • Dest: destination

DoGetAllSessionsIDs  protected virtual    (declared in TROCustomSessionManager)

function DoGetAllSessionsIDs: TROSessionIDs

DoGetSessionCount  protected override

Returns the session count.

function DoGetSessionCount: integer

DoIsSessionPresent  protected override

function DoIsSessionPresent(const aSessionID: TGUID): Boolean

Parameters:

  • aSessionID:

DoNotifySessionsChangesListener  protected virtual    (declared in TROCustomSessionManager)

Notifies attached listeners about changes

procedure DoNotifySessionsChangesListener(const aSessionID: TGUID; aSessionAction: TROSessionsActions; Sender: TObject)

Parameters:

  • aSessionID: Session ID
  • aSessionAction: action
  • Sender: sender

DoReleaseSession  protected override

Releases the previously acquired session.

procedure DoReleaseSession(aSession: TROSession; NewSession: boolean)

Parameters:

  • aSession: given session
  • NewSession: newly created session or not

DoTimerTick  protected virtual    (declared in TROCustomSessionManager)

Clears expired sessions.

procedure DoTimerTick(CurrentTickCount: cardinal)

Parameters:

  • CurrentTickCount: ignored

FindSession    (declared in TROCustomSessionManager)

Finds session with the specified GUID

function FindSession(const aSessionID: TGUID; aUpdateTime: Boolean): TROSession

Parameters:

  • aSessionID: Session ID.
  • aUpdateTime: Update LastAccess of found session or not

GetAllSessions  overload    (declared in TROCustomSessionManager)

function GetAllSessions: TROSessionIDs

GetAllSessions (TStringList)  overload    (declared in TROCustomSessionManager)

Returns a string list containing the IDs of all currently active sessions. Depending on the session manager and on your application architecture, this list can be huge, especially when using a database based session list that is shared by a large server farm. Obtaining the full list of sessions can be a costly process.

procedure GetAllSessions(Dest: TStringList)

Parameters:

  • Dest: destination

GetSessionCount    (declared in TROCustomSessionManager)

Returns the session count.

function GetSessionCount: integer

IsSessionPresent    (declared in TROCustomSessionManager)

function IsSessionPresent(const aSessionID: TGUID): Boolean

Parameters:

  • aSessionID:

KillTimer  protected    (declared in TROCustomSessionManager)

Kills internal timer

procedure KillTimer

RegisterSessionsChangesListener  protected virtual    (declared in TROCustomSessionManager)

Attaches a new IROSessionsChangesListener listener.

procedure RegisterSessionsChangesListener(aListener: IROSessionsChangesListener)

Parameters:

  • aListener: New listener

ReleaseSession    (declared in TROCustomSessionManager)

Releases the previously acquired session.

procedure ReleaseSession(var aSession: TROSession; NewSession: boolean)

Parameters:

  • aSession: given session
  • NewSession: newly created session or not

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned RO components.

procedure ROFreeNotification(AComponent: TComponent)

Parameters:

  • AComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Disables destruction notification for specified RO component.

procedure RORemoveFreeNotification(AComponent: TComponent)

Parameters:

  • AComponent: component

TestLastAccess  protected    (declared in TROCustomSessionManager)

function TestLastAccess(const aLastAccess: TDateTime): Boolean

Parameters:

  • aLastAccess:

UnRegisterSessionsChangesListener  protected virtual    (declared in TROCustomSessionManager)

Detaches a previously attached aListener.

procedure UnRegisterSessionsChangesListener(aListener: IROSessionsChangesListener)

Parameters:

  • aListener: Known listener

 

OnBeforeDeleteSession    (declared in TROCustomSessionManager)

Fires before deleting session.

property OnBeforeDeleteSession: TDeleteSessionEvent read write
delegate: procedure OnBeforeDeleteSession(const aSessionID: TGUID; IsExpired: boolean)

OnClearSessions

Fired when the session storage should be cleared. Depending on the value of the OnlyExpired parameter, the event handler should either clear the entire session list (on false), or only remove those sessions that have expired (on true).

property OnClearSessions: TClearSessionsEvent read write
delegate: procedure OnClearSessions(SessionManager: TROCustomSessionManager; OnlyExpired: boolean)

OnCustomCreateSession    (declared in TROCustomSessionManager)

Fires before the session is created. It allows to return existing session for given session ID

property OnCustomCreateSession: TROCustomSessionCreationEvent read write
delegate: procedure OnCustomCreateSession(const aSessionID: TGUID; var Session: TROSession)

OnDeleteSession

Fired when a specific session should be deleted, either because it has expired or it has explicitly been destroyed. This event handler should remove the session from storage.

property OnDeleteSession: TDeleteSessionEvent read write
delegate: procedure OnDeleteSession(const aSessionID: TGUID; IsExpired: boolean)

OnException    (declared in TROCustomSessionManager)

Fires when an exception is occuring

property OnException: TROSessionExceptionEvent read write
delegate: procedure OnException(aSessionID: TGUID; anException: Exception; var aRetry: Boolean)

OnFindSession

Fired when session data for a specific session is needed. It is up to the event handler to obtain this data from storage or create a new session if necessary.

property OnFindSession: TFindSessionEvent read write
delegate: procedure OnFindSession(const aSessionID: TGUID; out aSession: TROSession)

OnGetAllSessions

Fired to obtain a list of all available session IDs, when GetAllSessions is called.

property OnGetAllSessions: TGetAllSessionsEvent read write
delegate: procedure OnGetAllSessions(SessionManager: TROCustomSessionManager; aDest: TStringList)

OnGetSessionCount

Fired to obtain the total number of sessions available.

property OnGetSessionCount: TGetSessionCountEvent read write
delegate: function OnGetSessionCount(SessionManager: TROCustomSessionManager): integer

OnIsSessionExpiredEvent

property OnIsSessionExpiredEvent: TIsSessionExpiredEvent read write
delegate: function OnIsSessionExpiredEvent(SessionManager: TROCustomSessionManager; const aSessionID: TGUID): Boolean

OnIsSessionPresentEvent

property OnIsSessionPresentEvent: TIsSessionPresentEvent read write
delegate: function OnIsSessionPresentEvent(SessionManager: TROCustomSessionManager; const aSessionID: TGUID): Boolean

OnMaxSessionsReached    (declared in TROCustomSessionManager)

Fires when maximum count of allowed sessions is reached

property OnMaxSessionsReached: TROMaxSessionsReachedEvent read write
delegate: procedure OnMaxSessionsReached(var aFail: Boolean)

OnReleaseSession

Fired when a specific session is released. This event handler should store the data so the future calls to OnFindSession can access it.

property OnReleaseSession: TReleaseSessionEvent read write
delegate: procedure OnReleaseSession(var aSession: TROSession; NewSession: boolean)

OnSessionCreated    (declared in TROCustomSessionManager)

Gets triggered after a new Session has been created. You can use it to perform initialization functions or fill the session with default values.

property OnSessionCreated: TSessionEvent read write
delegate: procedure OnSessionCreated(const aSession: TROSession)

OnSessionDeleted    (declared in TROCustomSessionManager)

Gets triggered after the Session has been deleted. You can use it to perform some finalization functions.

property OnSessionDeleted: TDeleteSessionEvent read write
delegate: procedure OnSessionDeleted(const aSessionID: TGUID; IsExpired: boolean)

See Also