Topic Path: Symbol Reference > Classes > TIdCustomTCPServer Class > TIdCustomTCPServer Properties > Scheduler Property
TIdCustomTCPServer.Scheduler Property

Identifies the thread-based or fiber-based scheduler used in the server.

property Scheduler: TIdScheduler;

Scheduler is a TIdScheduler property that provides the mechanism used for thread or fiber management for client connections to the server. The Scheduler handles creation, execution, and termination of tasks for client connections found in Contexts

There are two basic types of Schedulers available for TIdCustomTCPServer: Thread-based and Fiber-based. Each is designed to work with a specific type of executable task that represents the client connections. 

The default Scheduler implementation in TIdCustomTCPServer uses a Thread to represent each client connection (TIdSchedulerOfThread). The default Scheduler (TIdSchedulerOfThreadDefault) allows creating and executing Thread-based tasks for client connections to the Server. 

There are further Scheduler refinements (in descendant classes) that allow a pool of pre-allocated Threads, or Threads which perform scheduling for dependent Fibers. Use TIdSchedulerOfThreadPool or TIdSchedulerOfFiber to access one of the alternative scheduler implementation. 

TIdCustomTCPServer requires that a Scheduler be assigned to allow creating and managing the executable tasks for client connections to the server. If a TIdScheduler (or descendant class) instance has not been assigned to the Scheduler property at startup, an instance of TIdSchedulerOfThreadDefault is created and assigned to the property. The ImplicitScheduler property is set to True to indicate that the Scheduler is managed by the TIdCustomTCPServer instance. 

Assigning a new value to Scheduler causes an implicitly created Scheduler to be freed. A reference to the new Scheduler instance is also maintained an existing IOHandler

While the server is running (Active contain True), Scheduler is used in the listener threads for the server acquire a new Yarn (thread or fiber) for client connection requests. If the connection request is accepted in IOHandler and MaxConnections has not been exceeded, a new ContextClass instance is created and added to Contexts using the TIdTCPConnecion, TIdYarn, and Contexts values for the clients executable task. The Scheduler is used to start execution of the task using its TIdYarn and TIdContext values. If an exception occurs in the listener thread, the Scheduler is used to terminate the TIdYarn for the client connection. 

During shutdown of the server (when Active is set to False), all active Yarns (threads or fibers) for the client connections are terminated using the TerminateAllYarns method in the Scheduler. When ImplicitScheduler contains True, the Scheduler is set to Nil to prevent any further access to its scheduling capabilities.

Copyright 1993-2006, Chad Z. Hower (aka Kudzu) and the Indy Pit Crew. All rights reserved.
Post feedback to the Indy Docs Newsgroup.