public CorrelationDetailsLoggingAssert(InternalClient internalClient) { this(internalClient.getConfig().getIotHubHostname(), internalClient.getConfig().getDeviceId(), internalClient.getConfig().getProtocol().toString(), internalClient.getConfig().getModuleId()); }
@Override public void sendEventAsync(Message message, IotHubEventCallback callback, Object callbackContext) throws IllegalArgumentException { //Codes_SRS_MODULECLIENT_34_040: [This function shall set the message's connection moduleId to the config's saved module id.] message.setConnectionModuleId(this.config.getModuleId()); //Codes_SRS_MODULECLIENT_34_041: [This function shall invoke super.sendEventAsync(message, callback, callbackContext).] super.sendEventAsync(message, callback, callbackContext); }
@Override public void logEvent(String event, Map<String, Object> producerConfig) { this.deviceClient.sendEventAsync(new Message(event), null, null); }
/** * @param props * @throws URISyntaxException * @throws IOException */ public AzureIoTHubLogger(final Map<String, Object> props) throws URISyntaxException, IOException { super(); this.deviceClient = new DeviceClient((String)props.get("connectionString"), IotHubClientProtocol.valueOf((String)props.get("protocol"))); this.deviceClient.open(); }
public IotHubTransportMessage(byte[] data, MessageType messageType, String messageId, String correlationId, MessageProperty[] messageProperties) { //Codes_SRS_IOTHUBTRANSPORTMESSAGE_34_017: [This constructor shall return an instance of IotHubTransportMessage with provided bytes, messagetype, correlationid, messageid, and application properties.] super(data); super.setMessageType(messageType); this.setMessageId(messageId); this.setCorrelationId(correlationId); for (MessageProperty messageProperty : messageProperties) { this.setProperty(messageProperty.getName(), messageProperty.getValue()); } }
private static boolean isErrorInjectionMessage(MessageAndResult messageAndResult) { MessageProperty[] properties = messageAndResult.message.getProperties(); for (int i = 0; i < properties.length; i++) { if (properties[i].getValue().equals(ErrorInjectionHelper.FaultCloseReason_Boom.toString()) || properties[i].getValue().equals(ErrorInjectionHelper.FaultCloseReason_Bye.toString())) { return true; } } return false; }
InternalClient(IotHubConnectionString iotHubConnectionString, IotHubClientProtocol protocol, String publicKeyCertificate, boolean isCertificatePath, String privateKey, boolean isPrivateKeyPath, long sendPeriodMillis, long receivePeriodMillis) throws URISyntaxException { // Codes_SRS_INTERNALCLIENT_34_078: [If the connection string or protocol is null, this function shall throw an IllegalArgumentException.] commonConstructorVerification(iotHubConnectionString, protocol); // Codes_SRS_INTERNALCLIENT_34_079: [This function shall save a new config using the provided connection string, and x509 certificate information.] this.config = new DeviceClientConfig(iotHubConnectionString, publicKeyCertificate, isCertificatePath, privateKey, isPrivateKeyPath); this.config.setProtocol(protocol); // Codes_SRS_INTERNALCLIENT_34_080: [This function shall save a new DeviceIO instance using the created config and the provided send/receive periods.] this.deviceIO = new DeviceIO(this.config, sendPeriodMillis, receivePeriodMillis); this.logger = new CustomLogger(this.getClass()); }
/** * 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); }
/** * Event handler for the connection unbound event. Sets the connection state to DISCONNECTED. * @param event The Proton Event object. */ @Override public void onConnectionUnbound(Event event) { logger.LogDebug("Entered in method %s", logger.getMethodName()); // Codes_SRS_AMQPSIOTHUBCONNECTION_12_010: [The function sets the state to closed.] this.state = IotHubConnectionStatus.DISCONNECTED; logger.LogDebug("Exited from method %s", logger.getMethodName()); }
/** * Ends the DeviceClient connection and destroy the thread. * @throws IOException if the DeviceClient cannot close the connection with the IoTHub. */ void stop() throws IOException { if (this.client != null) { this.client.closeNow(); } stopDevice = true; }
/** * Constructor. */ public Message() { initialize(); }
public void closeNow() throws IOException { //Codes_SRS_INTERNALCLIENT_21_008: [The closeNow shall closeNow the deviceIO connection.] this.deviceIO.close(); }
public ProductInfo getProductInfo() { // Codes_SRS_INTERNALCLIENT_34_071: [This function shall return the product info saved in config.] return this.config.getProductInfo(); }
protected void setConnectionStatusCallBack(final List<com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<IotHubConnectionStatus, Throwable>> actualStatusUpdates) { IotHubConnectionStatusChangeCallback connectionStatusUpdateCallback = new IotHubConnectionStatusChangeCallback() { @Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { actualStatusUpdates.add(new com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<>(status, throwable)); } }; this.internalClient.registerConnectionStatusChangeCallback(connectionStatusUpdateCallback, null); }
/** * Sets the given retry policy on the underlying transport * <a href="https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-client/devdoc/requirement_docs/com/microsoft/azure/iothub/retryPolicy.md"> * See more details about the default retry policy and about using custom retry policies here</a> * @param retryPolicy the new interval in milliseconds */ public void setRetryPolicy(RetryPolicy retryPolicy) { //Codes_SRS_INTERNALCLIENT_28_001: [The function shall set the device config's RetryPolicy .] this.config.setRetryPolicy(retryPolicy); }
/** * Set the length of time, in milliseconds, that any given operation will expire in. These operations include * reconnecting upon a connection drop and sending a message. * @param timeout the length in time, in milliseconds, until a given operation shall expire * @throws IllegalArgumentException if the provided timeout is 0 or negative */ public void setOperationTimeout(long timeout) throws IllegalArgumentException { // Codes_SRS_INTERNALCLIENT_34_070: [The function shall set the device config's operation timeout .] this.config.setOperationTimeout(timeout); }
InternalClient(IotHubConnectionString iotHubConnectionString, IotHubClientProtocol protocol, long sendPeriodMillis, long receivePeriodMillis) { /* Codes_SRS_INTERNALCLIENT_21_004: [If the connection string is null or empty, the function shall throw an IllegalArgumentException.] */ commonConstructorVerification(iotHubConnectionString, protocol); this.config = new DeviceClientConfig(iotHubConnectionString); this.config.setProtocol(protocol); this.deviceIO = new DeviceIO(this.config, sendPeriodMillis, receivePeriodMillis); this.logger = new CustomLogger(this.getClass()); }
/** * Constructor. * @param stream A stream to provide the body of the new Message instance. */ public Message(ByteArrayInputStream stream) { initialize(); }
InternalClient(IotHubAuthenticationProvider iotHubAuthenticationProvider, IotHubClientProtocol protocol, long sendPeriodMillis, long receivePeriodMillis) throws IOException, TransportException { this.config = new DeviceClientConfig(iotHubAuthenticationProvider); this.config.setProtocol(protocol); this.deviceIO = new DeviceIO(this.config, sendPeriodMillis, receivePeriodMillis); this.logger = new CustomLogger(this.getClass()); }