Tabnine Logo
CommandClient
Code IndexAdd Tabnine to your IDE (free)

How to use
CommandClient
in
org.eclipse.hono.client

Best Java code snippets using org.eclipse.hono.client.CommandClient (Showing top 10 results out of 315)

origin: eclipse/hono

private Void closeCommandClient(final CommandClient commandClient) {
  LOG.trace("Close command client to device [{}:{}]", tenantId, deviceId);
  commandClient.close(closeHandler -> {
  });
  return null;
}
origin: eclipse/hono

private CommandClient setCommandTimeOut(final CommandClient commandClient) {
  commandClient.setRequestTimeout(commandTimeoutInMs);
  return commandClient;
}
origin: eclipse/hono

private Future<Void> processCommand(final Command command) {
  LOG.info("Command sent to device... [request will timeout in {} seconds]", requestTimeoutInSecs);
  final Future<CommandClient> commandClient = client.getOrCreateCommandClient(tenantId, deviceId);
  return commandClient
      .map(this::setRequestTimeOut)
      .compose(c -> {
        if (command.isOneWay()) {
          return c
              .sendOneWayCommand(command.getName(), command.getContentType(), Buffer.buffer(command.getPayload()), null)
              .map(ok -> c);
        } else {
          return c
              .sendCommand(command.getName(), command.getContentType(), Buffer.buffer(command.getPayload()), null)
              .map(this::printResponse)
              .map(ok -> c);
        }
      })
      .map(this::closeCommandClient)
      .otherwise(error -> {
        LOG.error("Error sending command: {}", error.getMessage());
        if (commandClient.succeeded()) {
          return closeCommandClient(commandClient.result());
        } else {
          return null;
        }
      });
}
origin: eclipse/hono

private void sendCommandAndReceiveResponse(final String tenantId, final String deviceId) {
  client.getOrCreateCommandClient(tenantId, deviceId)
      .map(this::setCommandTimeOut)
      .compose(commandClient -> commandClient
          .sendCommand(sampler.getCommand(), Buffer.buffer(sampler.getCommandPayload()))
          .map(commandResponse -> {
            final String commandResponseText = Optional.ofNullable(commandResponse.getPayload())
                .orElse(Buffer.buffer()).toString();
            LOG.debug("Command response from device [{}:{}] received [{}]", tenantId,
                deviceId, commandResponseText);
            synchronized (lock) {
              successCount.incrementAndGet();
              bytesReceived.addAndGet(sampler.getCommandPayload().getBytes().length);
              bytesSent.addAndGet(commandResponseText.getBytes().length);
            }
            return commandResponse;
          })
          .map(x -> closeCommandClient(commandClient, tenantId, deviceId))
          .recover(error -> {
            if (triggerType.equals("device")
                || devicesReadyToReceiveCommands.contains(deviceId)) {
              errorCount.incrementAndGet();
            }
            LOG.error("Error processing command [{}] to device [{}:{}]", error.getMessage(), tenantId,
                deviceId);
            closeCommandClient(commandClient, tenantId, deviceId);
            return Future.failedFuture(error);
          }));
}
origin: eclipse/hono

commandClient.sendOneWayCommand(command, commandBuffer).map(statusResult -> {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Successfully sent one-way command payload: [{}] and received status [{}].", commandBuffer.toString(), statusResult);
origin: eclipse/hono

commandClient.sendCommand(command, "application/json", commandBuffer, buildCommandProperties()).map(result -> {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Successfully sent command payload: [{}].", commandBuffer.toString());
origin: eclipse/hono

private Void closeCommandClient(final CommandClient commandClient, final String tenantId, final String deviceId) {
  commandClient
      .close(closeHandler -> LOG.debug("CommandClient to device [{}:{}] is closed.", tenantId, deviceId));
  return null;
}
origin: eclipse/hono

private CommandClient setRequestTimeOut(final CommandClient commandClient) {
  commandClient.setRequestTimeout(TimeUnit.SECONDS.toMillis(requestTimeoutInSecs));
  return commandClient;
}
origin: eclipse/hono

private void closeCommandClient(final CommandClient commandClient, final TimeUntilDisconnectNotification ttdNotification) {
  // do not close the command client if device stays connected
  commandClient.close(v -> {
    if (LOG.isDebugEnabled()) {
      LOG.trace("Closed commandClient for [{}].", ttdNotification.getTenantAndDeviceId());
    }
  });
}
origin: eclipse/hono

/**
 * Create a command client for the device for that a {@link TimeUntilDisconnectNotification} was received, if no such
 * command client is already active.
 * @param notification The notification that was received for the device.
 */
private Future<CommandClient> createCommandClientAndSendCommand(final TimeUntilDisconnectNotification notification) {
  return honoClient.getOrCreateCommandClient(notification.getTenantId(), notification.getDeviceId())
      .map(commandClient -> {
        commandClient.setRequestTimeout(calculateCommandTimeout(notification));
        // send the command upstream to the device
        if (SEND_ONE_WAY_COMMANDS) {
          sendOneWayCommandToAdapter(commandClient, notification);
        } else {
          sendCommandToAdapter(commandClient, notification);
        }
        return commandClient;
      }).otherwise(t -> {
        LOG.error("Could not create command client", t);
        return null;
      });
}
org.eclipse.hono.clientCommandClient

Javadoc

A client for accessing Hono's Command and Control API.

An instance of this interface is always scoped to a specific tenant and device.

Most used methods

  • close
  • sendCommand
    Sends a command to a device and expects a response. A device needs to be (successfully) registered b
  • setRequestTimeout
  • sendOneWayCommand
    Sends a one-way command to a device, i.e. there is no response from the device expected. A device ne

Popular in Java

  • Start an intent from android
  • getSharedPreferences (Context)
  • putExtra (Intent)
  • getResourceAsStream (ClassLoader)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now