Source:
public LeshanClientExample(final String localHostName, final int localPort, final String serverHostName, final int serverPort) { ObjectsInitializer initializer = new ObjectsInitializer(); initializer.setClassForObject(3, Device.class); initializer.setInstanceForObject(6, locationInstance); List<ObjectEnabler> enablers = initializer.createMandatory(); enablers.addAll(initializer.create(6)); final InetSocketAddress clientAddress = new InetSocketAddress(localHostName, localPort); final InetSocketAddress serverAddress = new InetSocketAddress(serverHostName, serverPort); final LeshanClient client = new LeshanClient(clientAddress, serverAddress, new ArrayList<LwM2mObjectEnabler>( enablers)); client.start(); final String endpointIdentifier = UUID.randomUUID().toString(); RegisterResponse response = client.send(new RegisterRequest(endpointIdentifier)); System.out.println("Device Registration (Success? " + response.getCode() + ")"); if (response.getCode() == ResponseCode.CREATED) { System.out.println("\tDevice: Registered Client Location '" + response.getRegistrationID() + "'"); registrationID = response.getRegistrationID(); } else { System.err.println("\tDevice Registration Error: " + response.getCode()); System.err .println("If you're having issues connecting to the LWM2M endpoint, try using the DTLS port instead"); } Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if (registrationID != null) { System.out.println("\tDevice: Deregistering Client '" + registrationID + "'"); client.send(new DeregisterRequest(registrationID), 1000); client.stop(); } } }); Scanner scanner = new Scanner(System.in); System.out.println("Press 'w','a','s','d' to change reported Location."); while (scanner.hasNext()) { String nextMove = scanner.next(); locationInstance.moveLocation(nextMove); } scanner.close(); }

Target:
public LeshanClientExample(final String localHostName, final int localPort, final String serverHostName, final int serverPort) { ObjectsInitializer initializer = new ObjectsInitializer(); initializer.setClassForObject(3, Device.class); initializer.setInstanceForObject(6, locationInstance); List<ObjectEnabler> enablers = initializer.createMandatory(); enablers.addAll(initializer.create(6)); final InetSocketAddress clientAddress = new InetSocketAddress(localHostName, localPort); final InetSocketAddress serverAddress = new InetSocketAddress(serverHostName, serverPort); final LeshanClient client = new LeshanClient(clientAddress, serverAddress, new ArrayList<LwM2mObjectEnabler>( enablers)); client.start(); final String endpointIdentifier = UUID.randomUUID().toString(); RegisterResponse response = client.send(new RegisterRequest(endpointIdentifier)); if (response == null) { System.out.println("Registration request timeout"); return; } System.out.println("Device Registration (Success? " + response.getCode() + ")"); if (response.getCode() != ResponseCode.CREATED) { System.err .println("If you're having issues connecting to the LWM2M endpoint, try using the DTLS port instead"); return; } registrationID = response.getRegistrationID(); System.out.println("\tDevice: Registered Client Location '" + registrationID + "'"); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if (registrationID != null) { System.out.println("\tDevice: Deregistering Client '" + registrationID + "'"); client.send(new DeregisterRequest(registrationID), 5000); client.stop(); } } }); Scanner scanner = new Scanner(System.in); System.out.println("Press 'w','a','s','d' to change reported Location."); while (scanner.hasNext()) { String nextMove = scanner.next(); locationInstance.moveLocation(nextMove); } scanner.close(); }