示例#1
0
  /**
   * Decodes the provided ASN.1 element as a stop client response message.
   *
   * @param messageID The message ID to use for this message.
   * @param element The ASN.1 element containing the StopClientResponse sequence.
   * @return The stop client response message decoded from the ASN.1 element.
   * @throws SLAMDException If the provided ASN.1 element cannot be decoded as a stop client
   *     response message.
   */
  public static StopClientResponseMessage decodeStopClientResponse(
      int messageID, ASN1Element element) throws SLAMDException {
    ASN1Sequence responseSequence = null;
    try {
      responseSequence = element.decodeAsSequence();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("Could not decode ASN.1 element as a sequence", ae);
    }

    ASN1Element[] elements = responseSequence.getElements();
    if (elements.length != 2) {
      throw new SLAMDException("A stop client response message must have " + "two elements");
    }

    int responseCode = 0;
    try {
      responseCode = elements[0].decodeAsInteger().getIntValue();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("Could not decode the first element as an " + "integer", ae);
    }

    String responseMessage = null;
    try {
      responseMessage = elements[1].decodeAsOctetString().getStringValue();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("Could not decode the second element as an " + "octet string", ae);
    }

    return new StopClientResponseMessage(messageID, responseCode, responseMessage);
  }
示例#2
0
  /**
   * Decodes the provided ASN.1 element as a status request message.
   *
   * @param messageID The message ID to use for this message.
   * @param element The ASN.1 element containing the StatusRequest sequence.
   * @return The status request message decoded from the ASN.1 element.
   * @throws SLAMDException If the provided ASN.1 element cannot be decoded as a status request
   *     message.
   */
  public static StatusRequestMessage decodeStatusRequest(int messageID, ASN1Element element)
      throws SLAMDException {
    ASN1Sequence requestSequence = null;
    try {
      requestSequence = element.decodeAsSequence();
    } catch (ASN1Exception ae) {
      throw new SLAMDException(
          "Could not decode the provided ASN.1 element " + "as a sequence", ae);
    }

    ASN1Element[] elements = requestSequence.getElements();
    if (elements.length == 0) {
      return new StatusRequestMessage(messageID);
    } else if (elements.length != 1) {
      throw new SLAMDException("A status request may have at most one element");
    }

    String jobID = null;
    try {
      jobID = elements[0].decodeAsOctetString().getStringValue();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("Could not decode the first element as an " + "octet string", ae);
    }

    return new StatusRequestMessage(messageID, jobID);
  }
示例#3
0
  /**
   * Decodes the provided ASN.1 element as a server shutdown message.
   *
   * @param messageID The message ID to use for this message.
   * @param element The ASN.1 server shutdown element.
   * @return The server shutdown message decoded from the ASN.1 element.
   * @throws SLAMDException If the provided ASN.1 element cannot be decoded as a server shutdown
   *     message.
   */
  public static ServerShutdownMessage decodeShutdown(int messageID, ASN1Element element)
      throws SLAMDException {
    try {
      ASN1Null nullElement = element.decodeAsNull();
    } catch (ASN1Exception ae) {
      throw new SLAMDException("The server shutdown element cannot be " + "decoded as a null", ae);
    }

    return new ServerShutdownMessage(messageID);
  }