Example #1
0
  public Sample readerReadNext(Reader reader, GID instanceGID)
      throws CommunicationException, DataTypeUnsupportedException {
    Sample result = null;
    this.checkConnection();

    try {
      String xmlEntity = entitySerializer.serializeEntity(reader);
      String xmlSample =
          this.jniReaderReadNext(
              xmlEntity,
              Long.toString(instanceGID.getLocalId()),
              Long.toString(instanceGID.getSystemId()));
      this.checkConnection();
      result = untypedSampleDeserializer.deserializeSample(xmlSample, reader.getDataType());
    } catch (CMException e) {
      throw new CommunicationException(e.getMessage());
    } catch (TransformationException e) {
      throw new CommunicationException("Could not read next sample.");
    }
    return result;
  }
  /**
   * Administrates the Sample info oof the supplied Sample. It replaces the possible previous info.
   *
   * @param data The Sample, which info must be administrated.
   * @return true if the supplied Sample and its Message are not null, false otherwise.
   */
  public boolean setData(Sample data) {
    currentValue = data;
    boolean success = false;

    if (enabled) {
      Message msg = data.getMessage();
      int row = 0;

      if (msg != null) {
        State state = data.getState();

        this.setValueAt(this.getSampleState(state), row++, 1);
        this.setValueAt(this.getViewState(state), row++, 1);
        this.setValueAt(this.getInstanceState(state), row++, 1);
        this.setValueAt(this.getValidDataState(state), row++, 1);
        this.setValueAt(Long.toString(data.getDisposeCount()), row++, 1);
        this.setValueAt(Long.toString(data.getNoWritersCount()), row++, 1);

        String date = "(" + new Date(data.getInsertTimeSec() * 1000) + ")";
        this.setValueAt(
            Long.toString(data.getInsertTimeSec())
                + "s. "
                + Long.toString(data.getInsertTimeNanoSec())
                + "ns. "
                + date,
            row++,
            1);

        date = "(" + new Date(msg.getWriteTimeSec() * 1000) + ")";
        this.setValueAt(
            Long.toString(msg.getWriteTimeSec())
                + "s. "
                + Long.toString(msg.getWriteTimeNanoSec())
                + "ns. "
                + date,
            row++,
            1);

        long sec = data.getInsertTimeSec() - msg.getWriteTimeSec();
        long nsec = data.getInsertTimeNanoSec() - msg.getWriteTimeNanoSec();

        if (nsec < 0) {
          sec--;

          String strNsec = Long.toString(nsec);
          StringBuffer buf = new StringBuffer();
          buf.append("1");
          for (int i = 0; i < (strNsec.length() - 1); i++) {
            buf.append("0");
          }
          String strOne = buf.toString();

          long one = Long.parseLong(strOne);

          /*Add up, because nsec is negative.*/
          nsec = one + nsec;
        }

        this.setValueAt(Long.toString(sec) + "s. " + Long.toString(nsec) + "ns.", row++, 1);

        GID gid = msg.getWriterGid();

        if (gid != null) {
          this.setValueAt(Long.toString(gid.getLocalId()), row++, 1);
          this.setValueAt(Long.toString(gid.getSystemId()), row++, 1);
        } else {
          this.setValueAt("N/A", row++, 1);
          this.setValueAt("N/A", row++, 1);
          this.setValueAt("N/A", row++, 1);
        }
        gid = msg.getInstanceGid();

        if (gid != null) {
          this.setValueAt(Long.toString(gid.getLocalId()), row++, 1);
          this.setValueAt(Long.toString(gid.getSystemId()), row++, 1);
        } else {
          this.setValueAt("N/A", row++, 1);
          this.setValueAt("N/A", row++, 1);
          this.setValueAt("N/A", row++, 1);
        }
        this.setValueAt(Long.toString(msg.getSampleSequenceNumber()), row++, 1);

        if (msg.getQos() != null) {
          this.setValueAt(msg.getQos().getReliabilityKind().toString(), row++, 1);
        } else {
          this.setValueAt("N/A", row++, 1);
        }

        success = true;
      }
    } else {
      success = true;
    }
    return success;
  }