Visual C++ 6 Unleashed

Visual C++ 6 Unleashed

By MICKEY WILLIAMS and David Bennett

COM+ and MTS Features

MTS introduced basic support for creating multitier applications with transaction support. MTS 1.0 was really an application that was layered on top of the Windows NT 4.0 operating system, and many features that are expected in a transaction support system weren't present.

COM+ is more tightly integrated than MTS and takes advantage of that integration to provide a wide range of features that simply weren't possible in MTS.

Understanding Contexts

The context is a new concept introduced with COM+ in Windows 2000. All COM and COM+ components execute in contexts, which are sets of execution attributes that define transaction, synchronization, and other characteristics for components. Each process is partitioned into one or more contexts, much as processes previously were portioned into apartments.

Today in Windows 2000, the apartment is now just one part of an object's context. Two components that are identical except for their apartment membership will live in separate contexts. In a similar way, components with different transaction support will execute in separate contexts.

Direct communication between contexts is not allowed. Instead, lightweight interception proxies are used as communication channels between components in separate contexts. These interception proxies work very much like the proxies used to marshal data between apartments prior to the introduction to COM+.

Interception proxies are not invoked explicitly. Instead, the operating system detects that components in incompatible contexts are attempting to communicate and marshals the communication via an interception proxy.

Concurrency in COM+

In COM, concurrency and synchronization were enforced using apartments. In reality, the apartment actually controlled thread affinity rather than concurrency; synchronization was a side effect of the thread-affinity restriction. In a single-threaded apartment (STA), only one thread is permitted to visit an apartment; therefore, it is not possible to have thread-synchronization issues. In a multi-threaded apartment (MTA), any thread in the apartment may visit a component, so thread-synchronization issues must be addressed by the component.

The problem with using apartments for synchronization is that the concept of an apartment is not fine-grained. In COM+, the apartment is still used, but it now is used for thread-affinity purposes. For synchronization, COM+ introduces the activity. An activity is a collection of one or more components grouped together. Only one call is permitted in a single activity at any given time. This method allows for fine-grained control over component synchronization, because it separates thread affinity from concurrency. In COM+, it is possible to have components that exist in an MTA and can be visited by multiple threads, while relying on the operating system for synchronization.

Just-In-Time Activation

One of the key features offered by MTS and COM+ is just-in-time (JIT) activation. With JIT activation, references to objects are created when a client creates an instance of a configured component. The COM+ (or MTS) runtime does not automatically create a real instance of the component, however, and waits until the client makes a method call toward the component. After the method call, the component is deactivated and returned to a pool of components available for the next method call.

Just-in-time activation enables many clients to share small pools of components in an efficient manner. Just-in-time activation is enabled automatically for components that support or require transactions. If you enable JIT activation, your component also is configured automatically to require synchronization.

What Is Object Pooling?

Object pooling is similar to JIT activation. In object pooling, the operating system pre allocates a pool of components that are ready to be used by clients. Object pooling is useful when clients are sensitive to the initial startup costs of activating components. When providing components for Web servers, for example, you will get better performance by taking advantage of object pooling.

Registering a COM+ Application

COM+ components are grouped into COM+ applications. The first step in registering one or more COM+ components is to create a COM+ application that contains the component(s).

To register a COM+ component, launch the COM+ MMC snap-in, and expand the tree below Component Services until you reach the COM+ applications node. Figure 32.1 shows the COM+ MMC snap-in with the Component Services tree expanded to show currently configured COM+ applications. New COM+ applications are added to this portion of the tree.

32fig01.jpg

Figure 32.1 The COM+ MMC snap-in.

You add new applications by right-clicking on the COM+ Applications icon. Choose New, Application from the context menu. The COM Application Install Wizard appears. Initially, a welcome message is displayed. If you click Next, you move to the second wizard page, shown in Figure 32.2.

32fig02.gif

Figure 32.2 Installing a COM+ application.

The page in Figure 32.2 offers two options:

This chapter does not cover redistributing and installing prebuilt COM+ applications. To create a new application, click the Create an Empty Application button. The next wizard page appears, as shown in Figure 32.3.

32fig03.gif

Figure 32.3 Defining the name and activation type.

You use this wizard page to enter the name of the COM+ application. You also can specify the type of activation to be used for the new application:

After filling in this wizard page, click Next to display a page that lets you set the application identity (see Figure 32.4).

32fig04.gif

Figure 32.4 Defining the name and application type.

You use this wizard page to specify the security principal that will be used to execute the COM+ application. For debugging and testing purposes, the easiest approach is to choose the interactive user option. For a COM+ application deployed in a production environment, you should specify a security context to be used to execute the application.

This is the last wizard page. Click Next to display a thank-you message.

Configuring Properties for a COM+ Application

After a COM+ application is installed, you can access the application's properties by right-clicking the COM+ application's icon and choosing Properties from the context menu. The application's properties sheet appears, as shown in Figure 32.5.

32fig05.gif

Figure 32.5 The COM+ application properties sheet.

You use the first tab on the properties sheet, the General tab, to specify the name and description of the application. The GUID associated with the application also is displayed.

You use the Security tab, shown in Figure 32.6, to specify security attributes for the application, including these:

32fig06.gif

Figure 32.6 The Security tab.

You use the Identity tab, shown in Figure 32.7, to specify the security principal that will be used to execute the COM+ application.

32fig07.gif

Figure 32.7 The Identity tab.

The Activation tab specifies how the application will be activated (see Figure 32.8). You have the same options you had when the application was created: The application may be activated in the client's process, a library application, or a process managed by COM+—a server application.

32fig08.gif

Figure 32.8 The Activation tab.

The Queuing tab specifies characteristics for queued components (see Figure 32.9). You can choose from two check boxes:

32fig09.gif

Figure 32.9 The Queuing tab.

You use the Advanced tab, shown in Figure 32.10, to specify various advanced options for the COM+ application:

32fig10.gif

Figure 32.10 The Advanced tab.

Registering a COM+ Component

When a COM+ application is created, it has no components associated with it. After your COM+ application is installed and configured, your next step is to add one or more components to the COM+ application.

To install a COM+ component, expand the tree under the COM+ application node in the COM+ MMC snap-in. Right-click on the Components folder, and then choose New, Component from the context menu. The COM+ Component Install Wizard appears. Click Next to move from the welcome page and begin working with the wizard (see Figure ).

32fig11.gif

Figure 32.11 The COM+ Component Install Wizard.

This wizard page has three options:

In most cases, you will add new components to your COM+ application by clicking the Install New Components button.

After clicking one of the options on the wizard page just described, the File Open dialog box appears. Navigate to the DLL that houses your COM+ component, and click the Open button. The wizard page shown in Figure 32.12 appears.

32fig12.gif

Figure 32.12 The COM+ Component Install Wizard.

This wizard page displays the components found in the selected module. This is the last wizard page; to move to the thank-you page, click Next. Click Finish on the thank-you page to dismiss the wizard.

Configuring Properties for a COM+ Component

After registration, you can configure a COM+ component via its properties sheet, which you can display by right-clicking on the component in the COM+ Explorer snap-in and choosing Properties from the context menu. The properties sheet includes six properties pages you can use to configure the component (see Figure ).

32fig13.gif

Figure 32.13 The Object Pro perties dialog box.

General Properties

The General Properties page displays information about the COM+ component, such as its description, class ID, location, and application GUID.

Transactions Properties

You use the Transactions Properties page to define the transaction requirements for a COM+ object (see Figure 32.14).

32fig14.gif

Figure 32.14 The Transactions Properties page.

The transaction support required for the COM+ object may be one of the following values:

If you select the Required or Requires New option for transaction support, you can override the default transaction timeout by enabling the Override Global Transaction Timeout Value check box. Checking this box enables the edit control that collects the new transaction timeout value.

Security Properties

You use the Security Properties page to define the security attributes for a COM+ component (see Figure 32.15).

32fig15.gif

Figure 32.15 The Security Properties page.

To take advantage of component-level security, you must enable the Enforce Component Level Access Checks check box. In addition, component and process-level access checking must have been enabled for the COM+ application.

Roles defined for the application are listed in the lower half of the Properties page. Each role that is explicitly granted access to this component has a check next to its name.

Activation Properties

You use the Activation Properties page to define the activation semantics for a COM+ component (see Figure 32.16).

32fig16.gif

Figure 32.16 The Activation Properties page.

You can enable object pooling by enabling the Enable Object Pooling check box. If this option is enabled, you may optionally specify the minimum and maximum size of the object pool, as well as the amount of time allowed for object creation. If no object can be provided to a caller before this timeout expires, an error is returned to the caller.

You can enable object construction with the Support Object Construction check box. When this option is enabled, a construction string is passed to the component if the component supports the IObjectConstruction interface.

You can enable just-in-time activation using the Activation Properties page. This option is required for components that support or require transaction support.

To view event and statistic information about your component, enable the Component Supports Events and Statistics check box.

The last check box, Must Be Activated in Caller's Context, prevents a component from being created via a proxy. If a caller attempts to activate the component from an incom patible context, the call will fail instead of activating the component through a proxy.

Concurrency Properties

You use the Concurrency Properties page to define the concurrency and synchronization semantics for a COM+ component (see Figure 32.17).

32fig17.gif

Figure 32.17 The Concurrency Properties page.

You cannot change the threading model for the COM+ object by using this Properties page; the threading model is displayed for informational purposes only.

The synchronization support required for the COM+ object may be one of the following values:

If just-in-time activation is enabled for the component, only the Required and Requires New options are available.

Advanced Properties

You can use the Advanced Properties page to define the exception component class to be used for queued components. If defined, this class is used instead of sending messages to the dead letter queue. The exception class is expected to support the same queued interfaces as the original class.

The Advanced Properties page has no effect for non-queued components.

Share ThisShare This

Informit Network