System.out.format("Using communication protocol %s.\n", protocol.name()); ModuleClient client = new ModuleClient(connString, protocol); if (pathToCertificate != null) client.setOption("SetCertificatePath", pathToCertificate); client.setMessageCallback(callback, counter); client.setMessageCallback(callback, counter); client.setOption("SetSASTokenExpiryTime", time); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallbackLogger(), new Object()); client.open(); System.out.println(msgStr); EventCallback eventCallback = new EventCallback(); client.sendEventAsync(msg, eventCallback, msg); client.closeNow();
String moduleIdToInvokeOn = args.length > 4 ? args[4] : null; ModuleClient client = ModuleClient.createFromEnvironment(protocol); client.open(); client.closeNow();
public void getTwin(String connectionId, Handler<AsyncResult<Object>> handler) { System.out.printf("getTwin with %s%n", connectionId); ModuleClient client = getClient(connectionId); if (client == null) { handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); } else { this._deviceTwinPropertyCallback.setHandler(handler); try { client.getTwin(); } catch(IOException e) { this._deviceTwinPropertyCallback.setHandler(null); handler.handle(Future.failedFuture(e)); } } }
protocol.name()); ModuleClient client = new ModuleClient(connString, protocol); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallbackLogger(), new Object()); client.open(); client.subscribeToMethod(new SampleDeviceMethodCallback(), null, new DeviceMethodStatusCallBack(), null); client.closeNow(); System.out.println("Shutting down..."); client.closeNow(); System.out.println("Shutting down...");
public void connect(String transportType, String connectionString, Certificate caCertificate, Handler<AsyncResult<ConnectResponse>> handler) { System.out.printf("Connect called with transport %s%n", transportType); IotHubClientProtocol protocol = this.transportFromString(transportType); if (protocol == null) { handler.handle(Future.failedFuture(new MainApiException(500, "invalid transport"))); return; } try { ModuleClient client = new ModuleClient(connectionString, protocol); String cert = caCertificate.getCert(); if (cert != null && cert != "") { client.setOption("SetCertificateAuthority", cert); } openClientWithRetry(client); this._clientCount++; String connectionId = "moduleClient_" + this._clientCount; this._map.put(connectionId, client); ConnectResponse cr = new ConnectResponse(); cr.setConnectionId(connectionId); handler.handle(Future.succeededFuture(cr)); } catch (InterruptedException | ModuleClientException | URISyntaxException e) { handler.handle(Future.failedFuture(e)); } }
client.subscribeToTwinDesiredProperties(null); }); System.out.println("calling startTwin"); client.startTwin(this._deviceTwinStatusCallback, null, this._deviceTwinPropertyCallback, null);
protocol.name()); ModuleClient client = new ModuleClient(connString, protocol); System.out.println("Successfully created an IoT Hub client."); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallbackLogger(), new Object()); client.open(); client.startTwin(new DeviceTwinStatusCallBack(), null, new onProperty(), null); do client.subscribeToTwinDesiredProperties(desiredProperties); client.getTwin(); // For each desired property in the Service, the SDK will call the appropriate callback with the value and version. client.sendReportedProperties(reportProperties); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("HomeSecurityCamera", CAMERA.DETECTED_BURGLAR)); }}); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("HomeSecurityCamera", CAMERA.SAFELY_WORKING)); }}); client.sendReportedProperties(new HashSet<Property>() {{ add(new Property("BedroomRoomLights", null)); }}); client.closeNow(); System.out.println("Shutting down..."); client.closeNow();
this.client = new ModuleClient(connectionString, protocol); this.client = new ModuleClient(connectionString, protocol, publicCert, false, privateKey, false);
try moduleClient = new ModuleClient(connectionString, protocol); moduleClient.setOption_SetCertificatePath(alternativeDefaultTrustedCert); ModuleClient moduleClient = new ModuleClient(iotHubAuthenticationProvider, protocol, SEND_PERIOD_MILLIS, getReceivePeriod(protocol)); moduleClient.setTrustedCertificates(trustCertificates);
internalClient = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, deviceState.sCDeviceForRegistryManager, deviceState.sCModuleForRegistryManager), this.testInstance.protocol); internalClient = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, deviceState.sCDeviceForRegistryManager, deviceState.sCModuleForRegistryManager), this.testInstance.protocol, testInstance.publicKeyCert, ((ModuleClient) internalClient).startTwin(new DeviceTwinStatusCallBack(), deviceState, deviceState.dCDeviceForTwin, deviceState);
private void _closeConnection(String connectionId) { System.out.printf("Disconnect for %s%n", connectionId); ModuleClient client = getClient(connectionId); if (client != null) { this._deviceTwinPropertyCallback.setHandler(null); this._deviceTwinStatusCallback.setHandler(null); try { client.closeNow(); this._map.remove(connectionId); } catch (IOException e) { // ignore it, but keep it as an open connection so we can close it again later. System.out.printf("Exception on close: %s%n", e.toString()); e.printStackTrace(); } } }
public synchronized IotHubMessageResult execute(Message msg, Object context) { System.out.println("MessageCallback called"); this._client.setMessageCallback(this._inputName, null, null); String result = new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET); System.out.printf("result = %s%n", result); try { if (this._handler != null) { this._handler.handle(Future.succeededFuture(result)); } } catch (Exception e) { System.out.printf("Ignoring exception %s%n", e.toString()); } return IotHubMessageResult.COMPLETE; } }
/** * Create a module client instance from your environment variables * @return the created module client instance * @throws ModuleClientException if the module client cannot be created */ public static ModuleClient createFromEnvironment() throws ModuleClientException { return createFromEnvironment(IotHubClientProtocol.AMQPS); }
/** * Sends a message to a particular outputName asynchronously * * @param outputName the outputName to route the message to * @param message the message to send * @param callback the callback to be fired when the message is acknowledged by the service * @param callbackContext the context to be included in the callback when fired * @throws IllegalArgumentException if the provided outputName is null or empty */ public void sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext, String outputName) throws IllegalArgumentException { if (outputName == null || outputName.isEmpty()) { //Codes_SRS_MODULECLIENT_34_001: [If the provided outputName is null or empty, this function shall throw an IllegalArgumentException.] throw new IllegalArgumentException("outputName cannot be null or empty"); } //Codes_SRS_MODULECLIENT_34_002: [This function shall set the provided message with the provided outputName.] message.setOutputName(outputName); //Codes_SRS_MODULECLIENT_34_003: [This function shall invoke super.sendEventAsync(message, callback, callbackContext).] this.sendEventAsync(message, callback, callbackContext); }
public void enableMethods(String connectionId, Handler<AsyncResult<Void>> handler) { ModuleClient client = getClient(connectionId); if (client == null) { handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); } else { IotHubEventCallbackImpl callback = new IotHubEventCallbackImpl(); callback.setHandler(handler); try { client.subscribeToMethod(this._methodCallback, null, callback, null); } catch (IOException e) { handler.handle(Future.failedFuture(e)); } } }
((ModuleClient)client).startTwin(deviceTwinStatusCallBack, deviceTwinStatusCallbackContext, deviceTwin, propertyCallBackContext);
ModuleClient moduleClient = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, device, module), protocol); DeviceTestManager moduleClientSasTestManager = new DeviceTestManager(moduleClient); deviceTestManagers.add(moduleClientSasTestManager); ModuleClient moduleClientX509 = new ModuleClient(DeviceConnectionString.get(iotHubConnectionString, deviceX509, moduleX509), protocol, publicKeyCert, false, privateKey, false); DeviceTestManager moduleClientX509TestManager = new DeviceTestManager(moduleClientX509); deviceTestManagers.add(moduleClientX509TestManager);
public void waitForInputMessage(String connectionId, String inputName, Handler<AsyncResult<String>> handler) { System.out.printf("waitForInputMessage with %s, %s%n", connectionId, inputName); ModuleClient client = getClient(connectionId); if (client == null) { handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); } else { MessageCallback callback = new MessageCallback(client, inputName, handler); System.out.printf("calling setMessageCallback%n"); client.setMessageCallback(inputName, callback, null); } }
public void connectFromEnvironment(String transportType, Handler<AsyncResult<ConnectResponse>> handler) { System.out.printf("ConnectFromEnvironment called with transport %s%n", transportType); IotHubClientProtocol protocol = this.transportFromString(transportType); if (protocol == null) { handler.handle(Future.failedFuture(new MainApiException(500, "invalid transport"))); return; } try { ModuleClient client = ModuleClient.createFromEnvironment(protocol); openClientWithRetry(client); this._clientCount++; String connectionId = "moduleClient_" + this._clientCount; this._map.put(connectionId, client); ConnectResponse cr = new ConnectResponse(); cr.setConnectionId(connectionId); handler.handle(Future.succeededFuture(cr)); } catch (ModuleClientException | InterruptedException e) { handler.handle(Future.failedFuture(e)); } }
private void sendEventHelper(String connectionId, Message msg, Handler<AsyncResult<Void>> handler) { System.out.println("inside sendEventHelper"); ModuleClient client = getClient(connectionId); if (client == null) { handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); } else { EventCallback callback = new EventCallback(handler); System.out.printf("calling sendEventAsync%n"); client.sendEventAsync(msg, callback, null); } }