Requests, request queues, and request handlers

All programs have some way in which to sequence their actions. In the CommonPoint application system, every document has access to a queue of system occurrences, called requests, and a request handler that distributes and executes the requests.

A request is an object with only one important member function: Do. A request encapsulates a target object and a call on a member function of the target object. When you execute the Do function, the request makes the call on the target object. This allows a client object in another thread to build a request that is later executed in the target object's thread.

A request queue is a first-in, first-out queue of requests with a very simple interface that allows you to add requests to the queue and remove requests from the queue. Request queues can safely receive requests from clients in multiple concurrent threads.

A request handler is an object that removes the next request from a request queue and executes the request's Do member function. This process of removing and executing a request is called dispatching the request.


Figure 22 illustrates how a request queue provides the simplicity of a single-threaded system within a multi-threaded environment. theView is a view object in a thread whose boundary is denoted with a dotted box. client1 and client2 are clients of the view, in other threads. Rather than directly calling theView's member functions, the clients package the function calls into requests (request1 and request2), then post the requests to the request queue associated with theView's thread. The request handler in theView's thread dispatches requests one at a time, eventually dispatching the requests to their target, theView.

For a typical program, you set up your document with a request queue and a request handler, then instruct the request handler to wait for requests and dispatch them as they become available. The higher-level document frameworks handle these steps for you, but if you choose to work directly with the View System, you need to do it yourself.

The request queue mechanism is necessary to serialize member function calls that originate from outside the view's thread of execution. Clients that share the same thread as the view can call the view's member functions directly.

NOTE Requests, request queues, and request handlers are not actually part of the Desktop frameworks. They are part of the CommonPoint application system High-Level Utilities, which the Desktop frameworks use.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker