Package org.apache.hadoop.io

Examples of org.apache.hadoop.io.Writable


      int id = dis.readInt();                    // try to read an id
       
      if (LOG.isDebugEnabled())
        LOG.debug(" got #" + id);
           
      Writable param = (Writable)ReflectionUtils.newInstance(paramClass, conf);           // read param
      param.readFields(dis);       
       
      Call call = new Call(id, param, this);
      synchronized (callQueue) {
        if (callQueue.size() >= maxQueueSize) {
          Call oldCall = (Call) callQueue.removeFirst();
View Full Code Here


            LOG.debug(getName() + ": has #" + call.id + " from " +
                      call.connection);
         
          String errorClass = null;
          String error = null;
          Writable value = null;
         
          CurCall.set(call);
          try {
            value = call(call.param);             // make the call
          } catch (Throwable e) {
            LOG.info(getName()+", call "+call+": error: " + e, e);
            errorClass = e.getClass().getName();
            error = StringUtils.stringifyException(e);
          }
          CurCall.set(null);
           
          DataOutputStream out = call.connection.out;
          synchronized (out) {
            try {
              out.writeInt(call.id);                // write call id
              out.writeBoolean(error!=null);        // write error flag
              if (error == null) {
                value.write(out);
              } else {
                WritableUtils.writeString(out, errorClass);
                WritableUtils.writeString(out, error);
              }
              out.flush();
View Full Code Here

  private Object[] readPartitions(FileSystem fs, Path p, Class<?> keyClass,
      Configuration conf) throws IOException {
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, p, conf);
    ArrayList<Object> parts = new ArrayList<Object>();
    Writable key = (Writable)ReflectionUtils.newInstance(keyClass, conf);
    NullWritable value = NullWritable.get();
    while (reader.next(key, value)) {
      parts.add(key);
      key = (Writable)ReflectionUtils.newInstance(keyClass, conf);
    }
View Full Code Here

      int id = dis.readInt();                    // try to read an id
       
      if (LOG.isDebugEnabled())
        LOG.debug(" got #" + id);
           
      Writable param = ReflectionUtils.newInstance(paramClass, conf);           // read param
      param.readFields(dis);       
       
      Call call = new Call(id, param, this);
      callQueue.put(call);              // queue the call; maybe blocked here
    }
View Full Code Here

            LOG.debug(getName() + ": has #" + call.id + " from " +
                      call.connection);
         
          String errorClass = null;
          String error = null;
          Writable value = null;
         
          CurCall.set(call);
          UserGroupInformation previous = UserGroupInformation.getCurrentUGI();
          UserGroupInformation.setCurrentUGI(call.connection.ticket);
          try {
            value = call(call.param, call.timestamp);             // make the call
          } catch (Throwable e) {
            LOG.info(getName()+", call "+call+": error: " + e, e);
            errorClass = e.getClass().getName();
            error = StringUtils.stringifyException(e);
          }
          UserGroupInformation.setCurrentUGI(previous);
          CurCall.set(null);

          if (buf.size() > buffersize) {
            // Allocate a new BAOS as reset only moves size back to zero but
            // keeps the buffer of whatever the largest write was -- see
            // hbase-900.
            buf = new ByteArrayOutputStream(buffersize);
          } else {
            buf.reset();
          }
          DataOutputStream out = new DataOutputStream(buf);
          out.writeInt(call.id);                // write call id
          out.writeBoolean(error != null);      // write error flag

          if (error == null) {
            value.write(out);
          } else {
            WritableUtils.writeString(out, errorClass);
            WritableUtils.writeString(out, error);
          }
          call.setResponse(ByteBuffer.wrap(buf.toByteArray()));
View Full Code Here

        boolean isError = in.readBoolean();     // read if error
        if (isError) {
          call.setException(new RemoteException( WritableUtils.readString(in),
              WritableUtils.readString(in)));
        } else {
          Writable value = ReflectionUtils.newInstance(valueClass, conf);
          value.readFields(in);                 // read value
          call.setValue(value);
        }
      } catch (IOException e) {
        markClosed(e);
      }
View Full Code Here

      V value = null;
      if (clazz.equals(byte [].class)) {
        byte [] bytes = Bytes.readByteArray(in);
        value = (V)bytes;
      } else {
        Writable w = (Writable)ReflectionUtils.
          newInstance(clazz, getConf());
        w.readFields(in);
        value = (V)w;
      }
      this.instance.put(key, value);
    }
  }
View Full Code Here

    if (!dataReader.getValueClass().equals(valueClass)) {
      throw new Exception(dr + "Wrong value class in " + dir + ", expected" + valueClass.getName() +
                          ", got " + dataReader.getValueClass().getName());
    }
    long cnt = 0L;
    Writable key = ReflectionUtils.newInstance(keyClass, conf);
    Writable value = ReflectionUtils.newInstance(valueClass, conf);
    SequenceFile.Writer indexWriter = null;
    if (!dryrun) indexWriter = SequenceFile.createWriter(fs, conf, index, keyClass, LongWritable.class);
    try {
      long pos = 0L;
      LongWritable position = new LongWritable();
View Full Code Here

          reader.getKeyClass().asSubclass(WritableComparable.class),
          reader.getValueClass());

    WritableComparable key =
      ReflectionUtils.newInstance(reader.getKeyClass().asSubclass(WritableComparable.class), conf);
    Writable value =
      ReflectionUtils.newInstance(reader.getValueClass().asSubclass(Writable.class), conf);

    while (reader.next(key, value))               // copy all entries
      writer.append(key, value);
View Full Code Here

          throw new RuntimeException("Can't find class " + className);
        }
      } else {
        instanceClass = CODE_TO_CLASS.get(b);
      }
      Writable writable = WritableFactories.newInstance(instanceClass, conf);
      writable.readFields(in);
      instance = writable;
      if (instanceClass == NullInstance.class) {  // null
        declaredClass = ((NullInstance)instance).declaredClass;
        instance = null;
      }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.io.Writable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.