示例#1
0
 @Override
 public Writable create(Object value, TypeConverter typeConverter, Holder<Integer> size) {
   Text writable = new Text();
   writable.set(typeConverter.convertTo(String.class, value));
   size.value = writable.getBytes().length;
   return writable;
 }
示例#2
0
 @Override
 public Writable create(Object value, TypeConverter typeConverter, Holder<Integer> size) {
   size.value = SIZE;
   BooleanWritable writable = new BooleanWritable();
   writable.set(typeConverter.convertTo(Boolean.class, value));
   return writable;
 }
示例#3
0
 @Override
 public Object read(Writable writable, Holder<Integer> size) {
   size.value = ((BytesWritable) writable).getLength();
   ByteBuffer bb = ByteBuffer.allocate(size.value);
   bb.put(((BytesWritable) writable).getBytes(), 0, size.value);
   return bb;
 }
示例#4
0
 @Override
 public Writable create(Object value, TypeConverter typeConverter, Holder<Integer> size) {
   BytesWritable writable = new BytesWritable();
   ByteBuffer bb = (ByteBuffer) value;
   writable.set(bb.array(), 0, bb.array().length);
   size.value = bb.array().length;
   return writable;
 }
示例#5
0
  private void sayHello() {
    if (_helloPrx == null) {
      return;
    }

    int delay = _delaySlider.getValue();
    try {
      if (!_deliveryMode.isBatch()) {
        _status.setText("Sending request");
        final DeliveryMode mode = _deliveryMode;
        java.util.concurrent.CompletableFuture<Void> f = _helloPrx.sayHelloAsync(delay);
        final Holder<Boolean> response = new Holder<Boolean>(false);
        f.whenComplete(
            (result, ex) -> {
              if (ex == null) {
                assert (!response.value);
                response.value = true;
                _status.setText("Ready");
              } else {
                assert (!response.value);
                response.value = true;
                handleException(ex);
              }
            });
        com.zeroc.Ice.Util.getInvocationFuture(f)
            .whenSent(
                (ss, ex) -> {
                  if (ex == null) {
                    if (mode.isOneway()) {
                      _status.setText("Ready");
                    } else if (!response.value) {
                      _status.setText("Waiting for response");
                    }
                  }
                });
      } else {
        _flush.setEnabled(true);
        _helloPrx.sayHello(delay);
        _status.setText("Queued sayHello request");
      }
    } catch (com.zeroc.Ice.LocalException ex) {
      handleException(ex);
    }
  }
示例#6
0
 @Override
 public long next(HdfsInputStream hdfsistr, Holder<Object> key, Holder<Object> value) {
   try {
     ByteArrayOutputStream bos = new ByteArrayOutputStream(hdfsistr.getChunkSize());
     byte buf[] = new byte[HdfsConstants.DEFAULT_BUFFERSIZE];
     int bytesRead = ((InputStream) hdfsistr.getIn()).read(buf);
     if (bytesRead >= 0) {
       bos.write(buf, 0, bytesRead);
       key.value = null;
       value.value = bos;
       return bytesRead;
     } else {
       key.value = null;
       value.value = null;
       return 0;
     }
   } catch (IOException ex) {
     throw new RuntimeCamelException(ex);
   }
 }
示例#7
0
 /**
  * Converts the parameters to be more native friendly.
  *
  * @param args the array of objects to be converted.
  */
 @SuppressWarnings("unchecked")
 protected void messageParameters(Object[] args) {
   for (int i = 0; i < args.length; i++) {
     if (args[i] instanceof Holder && params[i].getNoByRef() != null) {
       // massage the value of Holder, not the Holder itself
       Holder h = (Holder) args[i];
       h.value = params[i].getNoByRef().toNative(h.value);
     } else {
       args[i] = params[i].toNative(args[i]);
     }
   }
 }
示例#8
0
 @Override
 public long next(HdfsInputStream hdfsistr, Holder<Object> key, Holder<Object> value) {
   try {
     SequenceFile.Reader reader = (SequenceFile.Reader) hdfsistr.getIn();
     Holder<Integer> keySize = new Holder<Integer>();
     Writable keyWritable =
         (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), new Configuration());
     Holder<Integer> valueSize = new Holder<Integer>();
     Writable valueWritable =
         (Writable) ReflectionUtils.newInstance(reader.getValueClass(), new Configuration());
     if (reader.next(keyWritable, valueWritable)) {
       key.value = getObject(keyWritable, keySize);
       value.value = getObject(valueWritable, valueSize);
       return keySize.value + valueSize.value;
     } else {
       return 0;
     }
   } catch (Exception ex) {
     throw new RuntimeCamelException(ex);
   }
 }
示例#9
0
  private void nearest(
      final Node node, final Holder<Point2D> nearest, final Point2D p, final boolean vertical) {

    if (node == null) {
      return;
    } else if (node.key.compareTo(p) == 0) {
      nearest.value = node.key;
      return;
    } else if (p.distanceTo(node.key) < p.distanceTo(nearest.value)) {
      nearest.value = node.key;
    }

    if (onTheLeft(p, node.key, vertical)) {
      nearest(node.left, nearest, p, !vertical);
      if (distanceToVertical(p, node.key, vertical) < p.distanceTo(nearest.value)) {
        nearest(node.right, nearest, p, !vertical);
      }
    } else if (onTheRight(p, node.key, vertical)) {
      nearest(node.right, nearest, p, !vertical);
      if (distanceToVertical(p, node.key, vertical) < p.distanceTo(nearest.value)) {
        nearest(node.left, nearest, p, !vertical);
      }
    }
  }
示例#10
0
 @Override
 public Writable create(Object value, TypeConverter typeConverter, Holder<Integer> size) {
   InputStream is = null;
   try {
     is = typeConverter.convertTo(InputStream.class, value);
     ByteArrayOutputStream bos = new ByteArrayOutputStream();
     IOUtils.copyBytes(is, bos, HdfsConstants.DEFAULT_BUFFERSIZE, false);
     BytesWritable writable = new BytesWritable();
     writable.set(bos.toByteArray(), 0, bos.toByteArray().length);
     size.value = bos.toByteArray().length;
     return writable;
   } catch (IOException ex) {
     throw new RuntimeCamelException(ex);
   } finally {
     IOHelper.close(is);
   }
 }
示例#11
0
 @Override
 public Object read(Writable writable, Holder<Integer> size) {
   size.value = SIZE;
   return ((BooleanWritable) writable).get();
 }
示例#12
0
 @Override
 public Object read(Writable writable, Holder<Integer> size) {
   size.value = 0;
   return null;
 }
示例#13
0
 @Override
 public Writable create(Object value, TypeConverter typeConverter, Holder<Integer> size) {
   size.value = 0;
   return NullWritable.get();
 }
示例#14
0
 @Override
 public Object read(Writable writable, Holder<Integer> size) {
   size.value = ((Text) writable).getLength();
   return writable.toString();
 }