Example usage for org.apache.hadoop.io WritableUtils readEnum

List of usage examples for org.apache.hadoop.io WritableUtils readEnum

Introduction

In this page you can find the example usage for org.apache.hadoop.io WritableUtils readEnum.

Prototype

public static <T extends Enum<T>> T readEnum(DataInput in, Class<T> enumType) throws IOException 

Source Link

Document

Read an Enum value from DataInput, Enums are read and written using String values.

Usage

From source file:co.cask.cdap.data2.transaction.queue.hbase.DequeueScanAttributes.java

License:Apache License

public static ConsumerConfig readConsumerConfig(DataInput dataInput) throws IOException {
    long groupId = dataInput.readLong();
    int groupSize = dataInput.readInt();
    int instanceId = dataInput.readInt();
    DequeueStrategy strategy = WritableUtils.readEnum(dataInput, DequeueStrategy.class);
    String hashKey = WritableUtils.readString(dataInput);

    return new ConsumerConfig(groupId, instanceId, groupSize, strategy, hashKey);
}

From source file:com.chinamobile.bcbsp.action.Directive.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    this.faultSSStep = in.readInt();
    this.timestamp = in.readLong();
    int t = in.readInt();
    if (Directive.Type.Request.value() == t) {
        this.type = Directive.Type.Request;
        int length = WritableUtils.readVInt(in);
        if (length > 0) {
            this.actionList = new ArrayList<WorkerManagerAction>();
            for (int i = 0; i < length; ++i) {
                WorkerManagerAction.ActionType actionType = WritableUtils.readEnum(in,
                        WorkerManagerAction.ActionType.class);
                WorkerManagerAction action = WorkerManagerAction.createAction(actionType);
                action.readFields(in);/*ww w  .j  a  v a 2 s. co  m*/
                this.actionList.add(action);
            }
        } else {
            this.actionList = null;
        }

        this.workerManagersName = WritableUtils.readCompressedStringArray(in);
    } else if (Directive.Type.Response.value() == t) {
        this.type = Directive.Type.Response;
        this.status = new WorkerManagerStatus();
        this.status.readFields(in);
    } else {
        throw new IllegalStateException("Wrong directive type:" + t);
    }

    /* Zhicheng Liu added */
    this.migrateSSStep = in.readInt();

}

From source file:com.chinamobile.bcbsp.bspcontroller.ClusterStatus.java

License:Apache License

/**
 * rewrite the read method to read information from hdfs.
 * @param in//from www  .  j a v a  2 s .c  om
 *        DataInput object to read from hdfs.
 */
@Override
public void readFields(DataInput in) throws IOException {
    this.activeWorkerManagersCount = in.readInt();
    boolean detailed = in.readBoolean();
    if (detailed) {
        this.activeWorkerManagersName = WritableUtils.readCompressedStringArray(in);
    }
    this.maxClusterStaffs = in.readInt();
    this.runningClusterStaffs = in.readInt();
    this.state = WritableUtils.readEnum(in, BSPController.State.class);
}

From source file:com.chinamobile.bcbsp.fault.storage.Fault.java

License:Apache License

/**
 * read fault information.//www .j  av a2 s  .  com
 * @param in
 *        fault information to be read.
 */
@Override
public void readFields(DataInput in) throws IOException {
    this.type = WritableUtils.readEnum(in, Type.class);
    this.level = WritableUtils.readEnum(in, Level.class);
    this.timeOfFailure = Text.readString(in);
    this.workerNodeName = Text.readString(in);
    this.jobName = Text.readString(in);
    this.staffName = Text.readString(in);
    this.exceptionMessage = Text.readString(in);
    this.superStep_Stage = in.readInt();
}

From source file:com.chinamobile.bcbsp.util.JobStatus.java

License:Apache License

/**
 * deserialize/*from   w  ww  .  jav  a2 s  .  c om*/
 *
 * @param in Reads some bytes from an input.
 */
@Override
public synchronized void readFields(DataInput in) throws IOException {
    this.jobid = new BSPJobID();
    jobid.readFields(in);
    this.setupProgress = in.readLong();
    this.progress = in.readLong();
    this.cleanupProgress = in.readLong();
    this.runState = in.readInt();
    this.state = WritableUtils.readEnum(in, State.class);
    this.startTime = in.readLong();
    this.finishTime = in.readLong();
    this.user = Text.readString(in);
    //    this.schedulingInfo = Text.readString(in);
    this.superstepCount = in.readLong();
    this.recovery = in.readBoolean();
}

From source file:com.chinamobile.bcbsp.util.StaffStatus.java

License:Apache License

/**
 * deserialize//from   w w  w.  java  2s .c  o  m
 *
 * @param in Reads some bytes from an input.
 */
@Override
public void readFields(DataInput in) throws IOException {
    this.jobId.readFields(in);
    this.staffId.readFields(in);
    this.progress = in.readInt();
    this.runState = WritableUtils.readEnum(in, State.class);
    this.stateString = Text.readString(in);
    this.phase = WritableUtils.readEnum(in, Phase.class);
    this.startTime = in.readLong();
    this.finishTime = in.readLong();
    this.superstepCount = in.readLong();
    this.faultFlag = in.readInt();
    if (this.faultFlag == 1) {
        this.fault.readFields(in);
    }
    this.recovery = in.readBoolean();
    this.currentSSTime = in.readLong();
    this.workerManager = Text.readString(in);
}

From source file:com.cloudera.sa.giraph.examples.ktrusses.PhaseWritable.java

License:Apache License

public void readFields(DataInput in) throws IOException {
    boolean isNull = in.readBoolean();
    if (!isNull) {
        phase = WritableUtils.readEnum(in, Phase.class);
    }/*from w w w  .  j  a  v  a2s .  c  om*/
}

From source file:com.facebook.hiveio.common.Writables.java

License:Apache License

/**
 * Read an enum array/*from   ww  w .ja  v  a  2 s .  com*/
 *
 * @param in DataInput
 * @param klass enum class
 * @param <E> type of enum
 * @return array of enums
 * @throws IOException
 */
public static <E extends Enum<E>> E[] readEnumArray(DataInput in, Class<E> klass) throws IOException {
    int length = in.readInt();
    if (length > 0) {
        String readClassName = WritableUtils.readString(in);
        Class<?> readClass = Classes.classForName(readClassName);
        Preconditions.checkArgument(klass.equals(readClass), "Expected Enum class %s, read %s", klass.getName(),
                readClassName);
    }
    E[] enums = (E[]) Array.newInstance(klass, length);
    for (int i = 0; i < length; ++i) {
        enums[i] = WritableUtils.readEnum(in, klass);
    }
    return enums;
}

From source file:com.marklogic.mapreduce.StreamLocator.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    path = new Path(Text.readString(in));
    codec = WritableUtils.readEnum(in, CompressionCodec.class);
}

From source file:com.moz.fiji.hive.io.EntityIdWritable.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    byte[] bytes = WritableUtils.readCompressedByteArray(in);
    mHBaseRowKey = bytes;//from  w  w  w. j  ava 2 s. c  o  m

    // Read the components
    int numComponents = WritableUtils.readVInt(in);
    List<Object> components = Lists.newArrayList();
    for (int c = 0; c < numComponents; c++) {
        Component componentType = WritableUtils.readEnum(in, Component.class);
        switch (componentType) {
        case STRING:
            String stringComponent = WritableUtils.readString(in);
            components.add(stringComponent);
            break;
        case INTEGER:
            Integer intComponent = WritableUtils.readVInt(in);
            components.add(intComponent);
            break;
        case LONG:
            Long longComponent = WritableUtils.readVLong(in);
            components.add(longComponent);
            break;
        case RAW_HBASE_KEY:
            byte[] byteArrayComponent = WritableUtils.readCompressedByteArray(in);
            components.add(byteArrayComponent);
            break;
        case NULL:
            break;
        default:
            throw new EntityIdException("Unexpected type for Component " + componentType);
        }
    }
    mComponents = components;

    String shellString = WritableUtils.readString(in);
    mShellString = shellString;
}