|
Chapter 17: LEGO MINDSTORMS
Overview
LEGO MINDSTORMS IS A "ROBOTICS INVENTION SYSTEM" that allows you to build LEGO toys with a programmable computer. This chapter looks at the issues involved in interfacing with a specialized hardware device, using MINDSTORMS as an example. |
||||
|
Further Uses of Entries
The primary
A good example of a "non-static" entry is
ServiceType
, which is an abstract subclass of
AbstractEntry
. This contains "human oriented" information about a service, and contains abstract
Another use is to define the user interface for a service. Services do not have or require
|
||||
|
LookupDiscoveryManager
An application (client or service) that wants to use a set of lookup services at fixed, known addresses, and also to use whatever lookup services it can find by multicast, can use the
LookupDiscoveryManager
utility class. Most of the
package net.jini.discovery;
public class LookupDiscoveryManager implements DiscoveryManagement,
DiscoveryGroupManagement,
DiscoveryLocatorManagement {
public LookupDiscoveryManager(String[] groups,
LookupLocator[] locators,
DiscoveryListener listener)
throws IOException;
}
This class
package discoverymgt;
import net.jini.discovery.LookupDiscoveryManager;
import net.jini.discovery.DiscoveryGroupManagement;
import net.jini.discovery.DiscoveryListener;
import net.jini.discovery.DiscoveryEvent;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.discovery.LookupLocator;
import java.net.MalformedURLException;
import java.io.IOException;
import java.rmi.RemoteException;
/**
* AllcastRegister.java
*/
public class AllcastRegister implements DiscoveryListener {
static public void main(String argv[]) {
new AllcastRegister();
// stay around long enough to receive replies
try {
Thread.currentThread().sleep(10000L);
} catch(java.lang.InterruptedException e) {
// do nothing
}
}
public AllcastRegister() {
LookupDiscoveryManager discover = null;
LookupLocator[] locators = null;
try {
locators = new LookupLocator[] {new LookupLocator("jini://localhost")};
} catch(MalformedURLException e) {
e.printStackTrace();
System.exit(1);
}
try {
discover = new _
LookupDiscoveryManager(DiscoveryGroupManagement.ALL_GROUPS,
locators,
this);
} catch(IOException e) {
System.err.println(e.toString());
e.printStackTrace();
System.exit(1);
}
}
public void discovered(DiscoveryEvent evt) {
ServiceRegistrar[] registrars = evt.getRegistrars();
for (int n = 0; n < registrars.length; n++) {
ServiceRegistrar registrar = registrars[n];
try {
System.out.println("found a service locator at " +
registrar.getLocator().getHost());
} catch(RemoteException e) {
e.printStackTrace();
continue;
}
// the code takes separate routes from here for client or service
}
}
public void discarded(DiscoveryEvent evt) {
}
} // AllcastRegister
|
||||