Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Applied Java™ Patterns - Stephen Stelting, Olav Maassen.pdf
Скачиваний:
202
Добавлен:
24.05.2014
Размер:
2.84 Mб
Скачать

The Callback sequence diagram is shown in Figure 4.7.

Figure 4.7. Callback sequence diagram

Callback imposes some basic requirements on both client and server:

Client – The client must provide a callback interface for the server, so the server can contact the client when its request is done.

Server – Beyond the traditional calling interface for the client, the server needs some way to notify clients when processing is complete. In addition, the server must be able to process and possibly store client requests.

Benefits and Drawbacks

The Callback pattern’s major advantage is its improvement of a system’s operating efficiency, especially server performance. You can see most of the improvement in two areas:

Server-side processing – The server does not have to maintain communication threads to service waiting clients, so it can channel those resources into processing client requests or servicing other callers. Furthermore the processing can be performed when the server sees fit. It doesn’t have to process the request immediately.

Server communication – The server does not have to maintain an open connection while the client waits for its results. This means that a server can support a greater number of callers with its limited communication resources, such as sockets.

This is a major motivation for some to choose the Callback pattern for their systems. In cases where server load is large or unpredictable (such as on the Web), this capability offers substantial advantages to designers. In the most extreme cases, it can mean the difference between running a group of servers in parallel and using a single machine to service client requests.

162