Component development using the COM specification is a major influence on the
way applications are designed nowadays. However, a significant percentage of
component development today is ‘stateful’ in nature (defined a little
later). Unfortunately, when these stateful components are used in an enterprise
environment under Object Request Brokers (ORBs) like Microsoft Transaction
Server (MTS), they’re unable to scale these components well, because of this
statefulness. Thus, one of the major challenges in writing components for MTS is
to ensure that they’re stateless in nature.
This article will help you understand the concepts of stateful and stateless
components, and will explain why MTS components should be stateless. We’ll
also take you through the working of stateful and stateless components using an
example.
What is statefulness?
A stateful component, by definition, is a component which maintains its state
in between calls to properties and methods. The term ‘state’ refers to the
current set of values of the various internal data members of the component. For
example, the text box control in VB is a stateful component. When you set the
‘text’ property of the control to some value, say ‘nauheed’, and then
change the font property; the change in font is reflected across, and the font
of the current contents of the ‘text’ property take on the font you just
changed to. In this example, the component–the textbox control–knew where
the change in the font should be applied–to the contents of the text property
of the component.
Likewise, let’s say you use the Winsock control and set the RemoteHost
property to ‘www.pcquest.com’, the
RemotePort property to 80, and then call the Connect method to connect to the
remote system, followed by a ‘SendData’ to transmit some information. The
Connect method will attempt to connect to www.pcquest.com
on port 80. That is, the Connect method knows which system it has to connect to
and on which port. This information or state was maintained by the component in
between setting the properties to their respective values and the call to the
Connect method. Assuming that a connection was made successfully, the SendData
method transmits information to the remote system across the TCP connection
established by the Connect method. So, the details or the state regarding the
established connection was maintained by the component for the call to SendData,
which used the connection to transmit information. So, Winsock is a stateful
component.
What is statelessness?
A stateless component, as the name implies, is a component that doesn’t
maintain its state in between calls to its properties and methods. Continuing
with our example of the Winsock control, had it been stateless, then all the
details (state information), like which system and port to connect to, and what
data to be sent, would have to be packed as parameters of a single SendData
method of the component. A stateless SendData method would look something like
this:
Function SendData(byval RHost as string, byval RPort as integer, byval data
as string) as boolean
Here, the SendData method itself makes a connection to the remote system (in
contrast to the Connect method in the stateful example) and sends the data.
Statelessness implies that a different state can be maintained during each
call to a method of a stateless component. So, while the first call to stateless
SendData can send data to www.pcquest. com on port 80, the second call can send
data to say, www.123.com on port 2000. Hence, if you have to change the state in
the stateful SendData example, you’ll need to change the values of the
properties of the component, before calling SendData again.
Typical layout of the Windows 95/98/Me registry
<+> My Computer
-<+> HKEY_CLASSES_ROOT (HKCR): Software settings, DDE,
OLE, drag-n-drop, Win31 backward compatibility, shortcut settings and
subkeys for every defined file association, also found at HKEY_LOCAL_MACHINE SOFTWARE\Classes.-<+> HKEY_CURRENT_USER (HKCU): Currently logged on user
configuration settings, also found at HKEY_USERS.Subkeys:
-<+> AppEvents: Assigned system and applications sound
events settings.-<+> Control Panel: Control Panel settings, similar to
those defined in System.ini, Win.ini, and Control.ini in Windows/WfWG 3.xx.-<+> Identitites: Created and used by MS Outlook Express
4/5 and its Address Book.-<+> InstallLocationsMRU (Most Recently Used):
Installation and Startup folders paths.
-<+> Keyboard: Current keyboard layout.
-<+> Network: Network connection settings.
-<+> RemoteAccess: Current logon location settings, if
using Dial-Up Networking (DUN).*-<+> Software: Software configuration settings for the
currently logged on user, sorted by vendor or developer.-<+> HKEY_LOCAL_MACHINE (HKLM): User independent hardware
and software machine specific information: bus type, device drivers,
keyboard layout etc. Subkeys:-<+> Config: System and software configuration.
-<+> Drivers: Used by the Device Manager to keep track of
active loaded drivers for hardware peripherals like plug-n-play devices, PC
cards, PCMCIA etc.-<+> Enum: Hardware devices’ information and settings.
-<+> Hardware: Serial communication port(s)’
information and settings.-<+> Network: Information and settings about network(s)
the user is currently logged on to.-<+> Security: Network security information and settings.
-<+> SOFTWARE: Software-specific information and settings
sorted by developer or vendor.*-<+> System: System startup, device driver, and
operating system information and settings.-<+> HKEY_USERS (HKU): Information about desktop and user
specific settings for each user who logs on to the same Windows 9x/Me
system. Each user has a separate subkey here. If there is only one user, the
only subkey is ".Default".-<+> HKEY_CURRENT_CONFIG (HKCC): Information about the
current hardware profile used by the local computer at startup, pointing to
HKEY_LOCAL_ MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\Current.*-<+> HKEY_DYN_DATA (HKDD): Virtual key (exists only in
memory) created every time Windows 9x/Me initializes; dynamic configuration
data about installed plug-n-play devices. Changes constantly when hardware
devices are added, swapped or removed on-the-fly.-<+> Config Manager: Hardware problem codes and status.
*-<+> PerfStats: System and network performance
statistics.
Registry editors
To modify the registry, you need to use a Registry Editor,
which would be one of the following:
-
Regedit.exe (Windows 95/98/Me/NT/2000): located in
%WinBootDir%, -
Regedt32.exe (Windows NT/2000): located in %System
Root%\System32\Config, or -
a third-party Registry editing tool like Registrar Lite
(freeware).
The Windows 95/98/NT/2000/Me Registry Editor is a tool used
to display, search, modify, create, delete, save, import, and export the
registry’s (sub)keys and values (see table).
Value |
API Code |
Description |
REG_ERROR |
-1 |
Error request value |
REG_NONE |
0 |
Null value |
REG_SZ |
1 |
Null terminated Unicode string Value |
REG_EXPAND_SZ |
2 |
Null terminated unexpanded Unicode/ANSI environment string |
REG_BINARY |
3 |
Binary value of any form/length |
REG_DWORD |
4 |
32-bit numerical value |
REG_DWORD_LITTLE_ |
4 |
32-bit numerical value |
REG_DWORD_BIG_ |
5 |
32-bit reversed numerical value |
REG_LINK |
6 |
Symbolic Unicode link string value |
REG_MULTI_SZ |
7 |
Array of multiple Unicode strings separated/ended by null |
REG_RESOURCE_LIST |
8 |
Device driver list of resources in Resource Map |
REG_FULL_RESOURCE_ |
9 |
List of hardware resources in Hardware Description |
REG_RESOURCE_ |
10 |
Device driver list of resource requirements in Resource |
You can use either RegEdit’s or RegEdt32’s interface in
protected mode Windows environment from within the Windows GUI. Alternatively,
you can use REGEDIT’s DOS based (Windows 95/98/ME) command line parameters in
real mode MS-DOS from outside Windows.
To learn how to use the regedit.exe available DOS mode
switches, run the following from native MS-DOS:
RegEdit.exe versus RegEdt32.exe comparison
REGEDIT.EXE |
REGEDT32.EXE |
Single window display |
Separate Hive Key window display |
Key and Value level Search |
Key level Search only |
Handles only simple Value types |
Handles also complex Value types |
Only Read and Write mode |
Optional Read Only mode |
No Security mode |
Optional Permissions Security mode |
No Security control |
Full Security control |
Text REG files export and import |
Text REG files export only |
No binary REG files export or import |
Binary REG files export and import |
Creates/renames/deletes only Subkeys |
Creates/renames/deletes also Hive Keys |
Opens at last accessed (Sub)Key level |
Opens at Root level only |
Creating a shortcut to the registry editor
To create a RegEdit shortcut, right-click on an empty raised
Taskbar spot. Select Properties, click Start Menu>Programs, and click the ‘Add...’
button. Browse to your main Windows folder, double-click on regedit.exe, and
click the Next button. Double-click Start Menu>Programs> Accessories>
System Tools, click the Next button, and type Registry Editor in the ‘Select
name for the shortcut’ box. Click the Finish button.
If you are not familiar with ‘messing around’ with your
Registry, don’t attempt to make any changes. However, if you are familiar
enough with your system registry’s "innards" and would like to tweak
it for maximum performance, but don’t like to modify your registry directly,
an alternative is to use one of the free Windows 9x/NT/2000/Me
system-cum-registry tweakers. Some of these are:
-
Xteq X-Setup: tweaks more than 700 system or registry
settings -
Microsoft TweakUI 1.33: More information on this is
available at http://home.aol.com/AXCEL216/98-3.htm#TWK98 -
DirectControl: tweaks DirectX, video, audio, and 3D
settings -
CacheMan: tweaks disk and file cache settings.
Words of caution
When editing the registry, backup all your hard drives to a
safe location before making any system changes (for details on how to do this,
go to http://home.aol.com/axcel216/newtip12.htm#
regbak). Remember that when you
add, delete or modify a registry (sub)key or value using RegEdit, all changes
take place instantly, and you aren’t prompted for confirmation upon saving
changes to before closing the registry editor. Take extreme caution when
modifying your system settings, because faulty registry changes may result in
computer crashes, lockups, or permanent data loss, and may cause you to
reinstall the entire operating system. And, always have your most recent system
backup ready.
Reprinted with permission from http://home.aol.com/AXCEL216/reg.htm