Exported and Imported Data in Connection Libraries

Advantages and Disadvantages

By exporting data, you provide the matching library process with direct access to the data, rather than the indirect type of access described in Global Objects in Server Libraries and Connection Objects in Connection Libraries earlier in this section. The following table compares these methods of providing data:

Capability

Exporting Data

Exporting Procedures That Access Global Data

Ease of Implementation

The importing program is given direct access to the data.

You have to implement library procedures that provide an interface to the data.

Maintainability

Changes to data structures, semantics, and access rules may require revision of all client programs.

Changes to data structures, semantics, and access rules may be hidden from client programs.

Processor Overhead

Low.

Somewhat higher, due to the cost of invoking a procedure.

Sharing

For a multiple-connection library, each connection exports a different instance of the data object.

For a multiple-connection library, all matching libraries receive indirect access to the same instance of the global variable.

However, exported procedures could provide access to connection objects, of which a different instance exists for each connection.

Writeability

The library can specify whether clients have read-write or read-only access to the variable.

The exported procedures can each contain logic to provide read-write or read-only access.

Importing Process Identity

The library provides the same access rights to all importing processes.

However, individual importing processes can reduce their own access rights by requesting read-only access to data that was exported with read-write access.

The exported procedures can include code to interrogate the identity of the importing process, and allow different actions for different clients.

Mutual Exclusion

Mutual exclusion is the ability of a process to secure exclusive access to data before updating it.

For a connection library providing indirect access to a global object, the exported procedures can be coded to always procure a global event before updating the global variable. In this way, the library can ensure that the event is updated by no more than one process at a time.

For data exported by connection libraries, mutual exclusion might not be necessary because each importing library receives a different instance of the exported data object. However, you might need to ensure mutual exclusion in any of the following cases:

  • The exporting connection library process and the importing connection library process both access the exported data object.

  • One of the importing library processes initiates internal tasks using the library through the same library declaration.

If mutual exclusion is necessary, the exporting connection library can export an event to be used together with the exported data object. Each importing process is expected to procure the event before updating the data object. However, the exporting connection library cannot enforce the use of this event.

Data Types That Can Be Exported

Currently, NEWP exports a more limited range of data types than ALGOL. For information about the types of data that can be exported and imported in ALGOL and NEWP, refer to Matching Data Types later in this section.

Specifying the Access Mode

Data can be exported with an access mode of read-only or read-write. Omitting an access mode assignment is the same as assigning read-only access. The access mode can be specified by both the exporting library and the importing library. The following table shows how the exported access mode and imported access mode combine to determine the actual access mode that is used:

Exported Access Mode

Imported Access Mode

Resulting Access Mode

READONLY or unspecified

READONLY or unspecified

READONLY

READONLY or unspecified

READWRITE

Objects cannot match.

READWRITE

READONLY or unspecified

READONLY

READWRITE

READWRITE

READWRITE

If the import and export objects do not match because of conflicting access modes, library linkage can still conclude successfully. The LINKLIBRARY result indicates that some requested objects were not available. If the client process attempts to use the imported data object, the client process is discontinued with the error message “OBJECT <object name> ACCESS MODE MISMATCH.” The client process can prevent this error by checking the availability of the data object with the ISVALID function, as described in Matching Connection Library Objects.

Data Type Matching

The exported data object and the imported data objects must be of the same or compatible types. Refer to Matching Data Types later in this section.

Syntax for Exporting Data

The following ALGOL statements export several data objects. Real array A receives the default access mode of read-only, and integer I is assigned an access mode of read-write.

TYPE CONNECTION BLOCK CL_TYPE;
   BEGIN
   REAL ARRAY A [0:10];
   INTEGER I;
   EVENT E1;

   EXPORT A (LINKCLASS = PROTECTED),
		  I AS “I2” (READWRITE),
		  E1;
   END;

CL_TYPE SINGLE LIBRARY CL_ONE (INTERFACENAME=“CLTESTLIB1.”);

Alternatively, the EXPORT statement can include a single access mode assignment that affects all the items in the export list, as in the following example:

EXPORT [READWRITE] A, I;

Syntax for Importing Data

The following ALGOL library statements import the data items that were exported by the previous example:

TYPE CONNECTION BLOCK CL_TYPE;
   BEGIN
   IMPORTED ARRAY A2[0] (ACTUALNAME = “A”);
   IMPORTED INTEGER I2 (READWRITE);
   IMPORTED EVENT E1;
   END;

CL_TYPE SINGLE LIBRARY CL_ONE (INTERFACENAME=“CLTESTLIB1.”);

Direct, Indirect, and Dynamic Data Provision

Connection libraries must use direct provision for any exported objects; indirect and dynamic provision are not permitted. For definitions of these various types of provision, refer to Methods of Providing Objects later in this section.

Limitations on Events

Events cannot be assigned an access mode. Exported events can be used in the same ways as any other event. However, the usage of imported events is restricted in the following ways:

Usage

Restriction

WAIT and WAITANDRESET statements

Imported events can be used in WAIT or WAITANDRESET statements only if the compiler control option WAITIMPORT has been set.

Interrupts

An imported event cannot be attached to an interrupt.

LOCK statements

An imported event cannot be used in statements of the form LOCK (<interlock>, <event>).

Direct I/O

An imported event cannot be used in direct I/O.

Parameters

An imported event cannot be passed as a parameter to a procedure.

If a program violates one of these restrictions, a syntax error results.