ToolTalk User's Guide

Scope Attributes

Applications that use the ToolTalk service to communicate usually have something in common – the applications are running in the same session, or they are interested in the same file or data. To register this interest, applications join sessions or files (or both) with the ToolTalk service. This file and session information is used by the ToolTalk service with the message patterns to determine which applications should receive a message.


Note –

The scope attributes are restricted to NFS and UFS files systems; file scoping does not work across file systems (for example, a tmpfs file system.)


File Scope

When a message is scoped to a file, only those applications that have joined the file (and match the remaining attributes) will receive the message. Applications that share interest in a file do not have to be running in the same session.

File-based Scoping in Patterns

Table 8–2 describes the types of scopes that use files which you can use to scope messages with patterns.

Table 8–2 Scoping a Message with Patterns to a File

Type of Scope 

Description 

TT_FILE

Scopes to the specified file only. You can set a session attribute on this type of pattern to provide a file-in-session-like scoping but a tt_session_join call will not update the session attribute of a pattern that is scoped to TT_FILE.

TT_BOTH

Scopes to the union of interest in the file and the session. A pattern with only this scope will match messages that are scoped to the file, or scoped to the session, or scoped to both the file and the session.

TT_FILE_IN_SESSION

Scopes to the intersection of interest in the file and the session. A pattern with only this scope will only match messages that are scoped to both the file and session.

To scope to the union of TT_FILE_IN_SESSION and TT_SESSION, add both scopes to the same pattern, as shown in Example 8–1.


Example 8–1 Scoping to Union of TT_FILE_IN_SESSION and TT_SESSION

	tt_open();

	Tt_pattern pat = tt_create_pattern();
	tt_pattern_scope_add(pat, TT_FILE_IN_SESSION);
	tt_pattern_scope_add(pat, TT_SESSION);
	tt_pattern_file_add(pat, file);
	tt_pattern_session_add(pat, tt_default_session());
	tt_pattern_register(pat);


File-based Scoping in Messages

Messages have the same types of file-based scoping mechanisms as patterns. Table 8–3 describes these scopes.

Table 8–3 Scoping Mechanisms for Messages

Type of Scope 

Description 

TT_FILE

Scopes the message to all clients that have registered interest in a file.  

TT_BOTH

Scopes the message to all clients that have registered interest in the message's session, the message's file, or the message's session and file.  

TT_FILE_IN_SESSION

Scopes the message to all clients that have registered interest in both the message's file and session.  

TT_SESSION + tt_message_file_set()

Scopes the message to every client that has registered interest in the message's session. When the message is received by a client whose pattern matches, the receiving client can call tt_message_file to get the file name.

When a message is scoped to TT_FILE or TT_BOTH, the ToolTalk client library checks the database server for all sessions that have clients that are interested in the file and sends the message to all of the interested ToolTalk sessions. The ToolTalk sessions then match the messages to the appropriate clients. The message sender is not required to explicitly call to tt_file_join.

If a message that is scoped to TT_FILE_IN_SESSION or TT_SESSION contains a file, the database server is not contacted and the message is sent only to clients that are scoped to the message's session.

Session Scope

When a message is scoped to a session, only those applications that have connected to that session are considered as potential recipients.


Example 8–2 Setting a Session

Tt_message m= tt_message_create();
tt_message_scope_set(m, TT_SESSION);
tt_message_file_set(m, file);


The first line creates message. The second line adds scope to message, and the last line adds file attribute that does not affect message scope.

File-In-Session Scope

Applications can be very specific about the distribution of a message by specifying TT_FILE_IN_SESSION for the message scope. Only those applications that have joined both the file and the session indicated are considered potential recipients.

Applications can also scope a message to every client that has registered interest in the message's session by specifying TT_SESSION with tt_message_file_set for the message scope. When the message is received by a client whose pattern matches, the receiving client can get the file name by calling tt_message_file.


Example 8–3 Setting a File

Tt_message m= tt_message_create();
tt_message_scope_set(m, TT_FILE_IN_SESSION);
tt_message_file_set(m, file);


The first line creates message. The second line adds scope. The third line adds file to message scope.