Java Reference
In-Depth Information
After creating the template, the constructor starts a lookup service-finding
process by creating a LookupDiscoveryManager instance. This object actively
searches for Jini lookup services across the network. The constructor adds the
client class as a DiscoveryListener and will be notified via the discovered()
callback when a lookup service is found. When a lookup service is found, the cli-
ent is notified and can search that lookup service for an instance of the JINICon-
nector service.
As mentioned in the previous paragraph, the discovered() method is invoked by
the LookupDiscoveryManager when a lookup service is found. Now that the client
has a reference to a lookup service, it uses the ServiceTemplate object created in
the constructor to search for the JINIConnector service. Service matches are
returned from the lookup service in a ServiceMatches object that contains an
array of ServiceItem objects. A ServiceItem object contains the actual Jini ser-
vice that matched the search (in this case, an instance of JINIConnector ). At this
point, your client acquires a reference to the Jini service for use. It stores the ref-
erence in a class member called server .
The getMBeanCount() method is the first of two methods implemented on the cli-
ent side to correspond to remote MBean server methods. It simply invokes the
identically named method on the JINIConnector service and returns the result.
The final method implemented in the JINIConnectorClient class is create-
MBean() (which corresponds to the remote MBean server createMBean() method
that is identically declared). This method is singled out here as an example of
using the JINIConnectorException class.
When this method is invoked, like getMBeanCount() , it simply invokes the same
method on the JINIConnector service. However, unlike the getMBeanCount()
method, it must be prepared to throw a variety of exceptions back to the user. To
accomplish this, you use the JINIConnectorClient exception class. When the
method catches a JINIConnectorException exception, it acquires the wrapped
server-side exception, casts it to the appropriate type (the getWrappedException()
method returns the type Exception ), and throws it.
Recall that we stubbed out the remaining methods declared in the MBeanServer
interface. They are included below the comment block in order to successfully
compile the connector client class.
We include a main() method to use in a quick test later. The main() method cre-
ates a JINIConnectorClient instance and uses it to connect to a remote MBean
server, get the MBean count, and create an instance of the HelloWorld MBean.
C
D
E
F
G
Search WWH ::




Custom Search