Tutorial 7: Create an EGO Service and Query the Domain Name Server
This tutorial describes how to create and run an EGO service, and query the Domain Name Server (DNS) for host information. The DNS is a standard naming service under the control of the Service Director.
Using this tutorial, you will ...
- Open a connection to the EGO Web Service endpoint
- Retrieve and print out resource info
- Register the client with Platform EGO and print out the registration response
- Locate all clients and print out the client info
- Query all EGO services
- Create a service definition
- Create and start an EGO service
- Query the DNS
- Stop the EGO service
Underlying principles
In order to communicate with a service on a host cluster, its location must be known. Due to the nature of distributed computing, the service can be running on any host. Normally, when a service instance switches into the run state, the Service Controller sends a notification to the Service Director that includes location information of the service instance. The Service Director then adds the location record to its DNS server. In this sample, we create a service called "sample6Service". When this service is running, the Service Director automatically updates its DNS records to reflect the new service instance.
The service is created from a new thread (see Sample 6). Once the service is running, we query the Service Controller for service instance information. Then we query the Service Controller, via the Service Director, for the IP address of the host that the service in running on.
Step 1: Import class references
Import the necessary classes and interfaces that are required by the client to invoke the Web Service.
Step 2: Register the client
Refer to Tutorial 2: Step 3: Register the client.
Step 3: Retrieve resource information
Refer to Tutorial 1: Step 3: Retrieve resource information.
Step 4: Locate all clients
Refer to Tutorial 2: Step 4: Locate the client.
Step 5: Query all services
Refer to Tutorial 6: Step 5: Query all EGO services.
Step 6: Create a service definition
Refer to Tutorial 6: Step 6: Create a service definition.
Step 7: Create a Service Controller Client object
Create a ServiceControllerClient object that implements the Runnable interface. This object will interact with the Service Controller as a client. The ServiceControllerClient class contains a run() method that enables you to create and query a service; refer to Tutorial 6: Step 7: Create a Service Controller Client object for the sample code. Define a new thread (scThread) and pass the ServiceControllerClient object to it. When the start() method is called, a new thread will be spawned. The stop() method will disable and remove the service.
Block the main thread for 120 seconds while the service is created and started. As the service starts, the Service Controller notifies the client of service state changes.
Send a query to the Service Controller to retrieve service info. The response to a service query request with a null input argument consists of a structure that includes the total number of services, service names, descriptions, states, and host names amongst others.
ServiceControllerClient scClient = new ServiceControllerClient(client); Thread scThread = null; try { scThread = new Thread(scClient); scThread.start(); } catch(Exception e) {} Thread.sleep(120 *1000); try { client.queryService(null); } catch(Exception e) {}Step 8: Create and start an EGO service
Refer to Tutorial 6: Step 9: Create and start an EGO service.
Step 9: Query the DNS
With the service running, we pass the service name to the getByName() method, which is a member of the InetAddress class. This method returns an InetAddress object containing the IP address and name of the host where the service instance is running. The address is returned by the Service Director's DNS.
InetAddress address = client.queryDNS(client.serviceName); System.err.println("Service:" + client.serviceName + "Host:" + address.getHostName() + "Address:" + address.getHostAddress()); public InetAddress queryDNS(String name) { try { InetAddress address = InetAddress.getByName(name); return address; } catch (java.net.UnknownHostException uhe) { uhe.printStackTrace(); } return null; }Step 11: Stop an EGO service
Refer to Tutorial 6: Step 11: Stop an EGO service for more information about the stop() method of the ServiceControllerClient class.
Block the main thread for 120 seconds while the service is being stopped. Query the DNS again. There should no longer be a record in the DNS for the service instance. The current thread is then blocked until the ServiceControlClient is notified, which signals the conclusion of the stop() method.
try { scClient.stop(); } catch(Exception e) {} Thread.sleep(120 *1000); // The address must be removed address = client.queryDNS(client.serviceName); System.err.println("Service:" + client.serviceName + "Host:" + address.getHostName() + "Address:" + address.getHostAddress()); synchronized(scClient) {scClient.wait();}Run the client application
- Select Run > Run.
The Run dialog appears.
- In the Configurations list, either select a Java Application or click New for a new configuration.
For a new configuration, enter the configuration name.
- Enter the project name and Main class.
- Click the Arguments tab and enter the following arguments in the given order:
- URL of the web service gateway
- Port number (string) for the notification interface
- Client ID (string)
- Client description (string).
note:
Arguments must be separated by a space.
![]()
- Click Apply and then Run.
[ Top ]
[ Platform Documentation ]
Date Modified: July 12, 2006
Platform Computing: www.platform.com
Platform Support: support@platform.com
Platform Information Development: doc@platform.com
Copyright © 1994-2006 Platform Computing Corporation. All rights reserved.