コード例 #1
0
  @Override
  public byte[] toBinary() {
    int byteBufferLength = 20 + (2 * orderedSfcIndexToTierId.size());
    final List<byte[]> orderedSfcBinaries = new ArrayList<byte[]>(orderedSfcs.length);
    final List<byte[]> dimensionBinaries = new ArrayList<byte[]>(baseDefinitions.length);
    for (final SpaceFillingCurve sfc : orderedSfcs) {
      final byte[] sfcBinary = PersistenceUtils.toBinary(sfc);
      byteBufferLength += (4 + sfcBinary.length);
      orderedSfcBinaries.add(sfcBinary);
    }
    for (final NumericDimensionDefinition dimension : baseDefinitions) {
      final byte[] dimensionBinary = PersistenceUtils.toBinary(dimension);
      byteBufferLength += (4 + dimensionBinary.length);
      dimensionBinaries.add(dimensionBinary);
    }
    final ByteBuffer buf = ByteBuffer.allocate(byteBufferLength);
    buf.putInt(orderedSfcs.length);
    buf.putInt(baseDefinitions.length);
    buf.putInt(orderedSfcIndexToTierId.size());
    buf.putLong(maxEstimatedDuplicateIds);
    for (final byte[] sfcBinary : orderedSfcBinaries) {
      buf.putInt(sfcBinary.length);
      buf.put(sfcBinary);
    }
    for (final byte[] dimensionBinary : dimensionBinaries) {
      buf.putInt(dimensionBinary.length);
      buf.put(dimensionBinary);
    }
    for (final Entry<Integer, Byte> entry : orderedSfcIndexToTierId.entrySet()) {
      buf.put(entry.getKey().byteValue());
      buf.put(entry.getValue());
    }

    return buf.array();
  }
コード例 #2
0
  @Override
  public byte[] toBinary() {
    final byte[] indexStrategyBytes = PersistenceUtils.toBinary(indexStrategy);
    final byte[] coordinateRangesBinary = new ArrayOfArrays(coordinateRanges).toBinary();

    final ByteBuffer buf =
        ByteBuffer.allocate(coordinateRangesBinary.length + indexStrategyBytes.length + 4);

    buf.putInt(indexStrategyBytes.length);
    buf.put(indexStrategyBytes);
    buf.put(coordinateRangesBinary);
    return buf.array();
  }
コード例 #3
0
  @Override
  protected void addObject(final ByteArrayId id, final ByteArrayId secondaryId, final T object) {
    addObjectToCache(id, secondaryId, object);

    try {

      final Writer writer = accumuloOperations.createWriter(getTablename(), true);
      synchronized (this) {
        if (!iteratorsAttached) {
          iteratorsAttached = true;
          final IteratorConfig[] configs = getIteratorConfig();
          if ((configs != null) && (configs.length > 0)) {
            accumuloOperations.attachIterators(getTablename(), true, true, true, null, configs);
          }
        }
      }

      final Mutation mutation = new Mutation(new Text(id.getBytes()));
      final Text cf = getSafeText(getColumnFamily());
      final Text cq = getSafeText(getColumnQualifier(object));
      final byte[] visibility = getVisibility(object);
      if (visibility != null) {
        mutation.put(
            cf, cq, new ColumnVisibility(visibility), new Value(PersistenceUtils.toBinary(object)));
      } else {
        mutation.put(cf, cq, new Value(PersistenceUtils.toBinary(object)));
      }
      writer.write(mutation);
      try {
        writer.close();
      } catch (final IOException e) {
        LOGGER.warn("Unable to close metadata writer", e);
      }
    } catch (final TableNotFoundException e) {
      LOGGER.error("Unable add object", e);
    }
  }