Java Dynamic Management Kit 3.2 Programming Guide
[ Previous ][ Fast Back ]Chapter 7. Adaptor Clients [ Next ]

Initializing an Adaptor Client

Initializing an adaptor client consists of:

Adding an Adaptor Client to the Manager

To add an adaptor client to a manager, create an instance of the Java class that implements the adaptor client you want to use.

Adaptor Client

Java Class

RMI

com.sun.jaw.impl.adaptor.rmi.AdaptorClient

HTTP/TCP

com.sun.jaw.impl.adaptor.http.AdaptorClient

HTTP/UDP

com.sun.jaw.impl.adaptor.udp.AdaptorClient

HTTP/SSL

com.sun.jaw.impl.adaptor.https.AdaptorClient

IIOP

com.sun.jaw.impl.adaptor.iiop.AdaptorClient

The constructor of each of these classes is a public constructor that takes no parameters. This enables you to instantiate an adaptor client without hard-coding its Java class. Example 7-1 shows how to do this: the class of the adaptor client to be instantiated is specified in a string. In this example, the string is given, however, you could obtain such information from command-line arguments, a name server, or a directory service. The example also shows a classic instantiation of an adaptor object.

Example 7-1. Instantiating an Adaptor Client
// Instantiates an HTTP/TCP adaptor client from its class name
//
String adaptorName = "com.sun.jaw.impl.adaptor.http.AdaptorClient";
Class adaptorClass = Class.forName( adaptorName );

AdaptorMO AdaptorClient = (AdaptorMO) adaptorClass.newInstance();

// or instantiate in the normal way from it's object
//
AdaptorMO AnotherAdaptorClient =
    new com.sun.jaw.impl.adaptor.http.AdaptorClient();

If you want to use more than one RMI adaptor per client (or agent), you must run the rmiregistry command, specifying the port number that the new adaptor is going to use:
prompt% rmiregistry portNumber

Where portNumber refers to the port number for the new RMI adaptor.

Connecting an Adaptor Client

An adaptor client must be connected to the adaptor server of the same protocol in an agent. To connect an adaptor client, make sure that the manager invokes the connect() method of the adaptor client. In the connect() method you have to specify:

Such information could be provided by a name server or directory service at the same time the Java class name of the adaptor client is given. Example 7-2 shows how to connect an adaptor client to an agent.

Example 7-2. Connecting an Adaptor Client
// Connect the client's adaptor to a server
try {
    AdaptorClient.connect( authInfo, host, port, logicalName );
}

When a manager invokes the connect() method, it is possible that no messages are exchanged between the adaptor client and the agent. Whether this happens depends on the underlying communication mechanism used by the adaptor client.

Authentication

Authentication is supported by HTTP adaptor clients and servers. Whether an adaptor client requires login/password information is determined by the adaptor server. The authentication information is initialized as part of the connection. Each time one of the AdaptorMO methods is invoked, the login/password information is verified. If the login/password information is invalid at any time (it can change on the server even after the initial authentication), an UnauthorizedSecurityException is thrown. The client must disconnect and then reconnect.

The client sends a request to the server to login to the server. If login/password information is defined for the adaptor server (see Authentication in Chapter 5) the server responds with a request for login/password information. The client sends its login/password information, which is compared by the server with the information for users with login/passwords authenticated by the server.

To add an adaptor client with login/password information to a manager, create an instance of the Java class that implements the adaptor. The classes are shown on Adding an Adaptor Client to the Manager. To add login/password authentication, create an instance of the AuthInfo class. Example 7-3 shows the instantiation of an HTTP/TCP adaptor client and an authentication information object.

Example 7-3. Authentication for an Adaptor Client
import com.sun.jaw.impl.adaptor.comm.*

// Set up the HTTP adaptor client.
//
com.sun.jaw.impl.adaptor.http.AdaptorClient adaptor = new
    com.sun.jaw.impl.adaptor.http.AdaptorClient();

// Initialize the client authentication info.
//
AuthInfo authinfo = new AuthInfo( "username", "password" );

// Initialize communication with the remote object server.
//
try {
    adaptor.connect( authinfo, agentHost, agentPort,
                     ServiceName.APT_HTTP );
}
catch ( UnauthorizedSecurityException use ) {
    System.err.println(
        "Authentication Failed. Invalid login/password" );
}

If the server has no login/password information defined, client authentication is not performed. Where authentication is not performed, any client is able to connect to the server.


[ Previous ][ Home ][ Next ]
Supported Protocols[ Up ]Operations on an Agent