Skip to content

Instantly share code, notes, and snippets.

@psigen
Created November 18, 2015 16:07
Show Gist options
  • Save psigen/4e2fae8915a898296ee2 to your computer and use it in GitHub Desktop.
Save psigen/4e2fae8915a898296ee2 to your computer and use it in GitHub Desktop.
Registry Test Application
package com.platypus;
import com.platypus.crw.FunctionObserver;
import com.platypus.crw.udp.UdpVehicleServer;
import com.platypus.crw.udp.UdpVehicleService;
import com.platypus.crw.udp.VehicleRegistryService;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.Map;
public class Main {
public static void main(String[] args) throws InterruptedException {
// Register with the default "registry.senseplatypus.com" server.
InetSocketAddress registryAddress = new InetSocketAddress(
"registry.senseplatypus.com", VehicleRegistryService.DEFAULT_UDP_PORT);
// Create a *fake* vehicle and connect it to the registry.
UdpVehicleService service = new UdpVehicleService();
service.addRegistry(registryAddress);
// Create a simple proxy (as would be used in a GUI) and connect it to the registry.
UdpVehicleServer server = new UdpVehicleServer();
server.setRegistryService(registryAddress);
// Print the dummy vehicle's currently set registries.
System.out.println("Vehicle registered at:");
for (InetSocketAddress address : service.listRegistries()) {
System.out.println("\t" + address);
}
// Loop forever printing connections on the dummy GUI.
while (true) {
Thread.sleep(1000);
server.getVehicleServices(new FunctionObserver<Map<SocketAddress, String>>() {
@Override
public void completed(final Map<SocketAddress, String> socketAddressStringMap) {
System.out.println("Found:");
for (Map.Entry<SocketAddress, String> entry: socketAddressStringMap.entrySet()) {
System.out.println("\t" + entry);
}
}
@Override
public void failed(final FunctionError functionError) {
System.err.println("Failed to connect to registry.");
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment