The target of a connection is identified by a protocol-specific implementation of the ConnectorAddress interface. This object contains all the information that a connector client needs to establish a connection with the target agent. All address objects specify a host name and port number. An RMI address adds the required service name, and HTTP-based addresses have an optional authentication field (see 23.1 Password-Based Authentication (Legacy Connectors)). In addition, the ConnectorType string identifies the protocol without needing to introspect the address object.
In our example, the target of the connection is an active legacy RMI connector server identified by an RmiConnectorAddress object. We use the default constructor to instantiate a default address object, but otherwise, these parameters can be specified in a constructor or through setter methods. The default values of the information contained in the RmiConnectorAddress object are the following:
The ConnectorType identifies the protocol that is used; its value is SUN RMI for the RmiConnectorAddress class.
The default RMI port is 1099, as given by the static variable RMI_CONNECTOR_PORT in the ServiceName class.
The Host is the name of the host where the target agent is running; by default, its value is the local host.
The Name attribute specifies the RMI registry service name of the adaptor server. Its default value is name=RmiConnectorServer, which is the value of the RMI_CONNECTOR_SERVER static variable in the ServiceName class.
The RmiConnectorAddress object is used as the parameter to the connect method of the RmiConnectorClient instance. This method tries to establish the connection and throws an exception if there is a communication or addressing error. Otherwise, when the connect method returns, the connector client is ready to perform management operations on the designated agent.
The code segment shown inExample 21–3 is taken from the ClientWithoutProxy class in the examples directory.
echo("\t>> Instantiate the RMI connector client..."); connectorClient = new RmiConnectorClient(); echo("\t>> Instantiate a default RmiConnectorAddress object..."); RmiConnectorAddress address = new RmiConnectorAddress(); // display the default values echo("\t\tTYPE\t= " + address.getConnectorType()); echo("\t\tPORT\t= " + address.getPort()); echo("\t\tHOST\t= " + address.getHost()); echo("\t\tSERVER\t= " + address.getName()); echo("\t<< done <<"); echo("\t>> Connect the RMI connector client to the agent..."); try { connectorClient.connect( address ); } catch(Exception e) { echo("\t!!! RMI connector client could not connect to the agent !!!"); e.printStackTrace(); System.exit(1); } |