Example usage for org.apache.zookeeper Op getType

List of usage examples for org.apache.zookeeper Op getType

Introduction

In this page you can find the example usage for org.apache.zookeeper Op getType.

Prototype

public int getType() 

Source Link

Document

Gets the integer type code for an Op.

Usage

From source file:com.ery.estorm.zk.RecoverableZooKeeper.java

License:Apache License

/**
 * Convert Iterable of {@link ZKOp} we got into the ZooKeeper.Op instances
 * to actually pass to multi (need to do this in order to appendMetaData).
 *///  w w w.  j a  v  a 2 s  .co m
private Iterable<Op> prepareZKMulti(Iterable<Op> ops) throws UnsupportedOperationException {
    if (ops == null)
        return null;

    List<Op> preparedOps = new LinkedList<Op>();
    for (Op op : ops) {
        if (op.getType() == ZooDefs.OpCode.create) {
            CreateRequest create = (CreateRequest) op.toRequestRecord();
            preparedOps.add(Op.create(create.getPath(), appendMetaData(create.getData()), create.getAcl(),
                    create.getFlags()));
        } else if (op.getType() == ZooDefs.OpCode.delete) {
            // no need to appendMetaData for delete
            preparedOps.add(op);
        } else if (op.getType() == ZooDefs.OpCode.setData) {
            SetDataRequest setData = (SetDataRequest) op.toRequestRecord();
            preparedOps.add(
                    Op.setData(setData.getPath(), appendMetaData(setData.getData()), setData.getVersion()));
        } else {
            throw new UnsupportedOperationException("Unexpected ZKOp type: " + op.getClass().getName());
        }
    }
    return preparedOps;
}

From source file:com.navercorp.nbasearc.confmaster.server.ZooKeeperHolder.java

License:Apache License

public List<OpResult> multi(Iterable<Op> ops) throws MgmtZooKeeperException {
    try {//from   w  w  w. j a  va  2 s  . c  o m
        for (Op op : ops) {
            if (op.getType() == create || op.getType() == delete || op.getType() == setData) {
                ThreadLocalVariableHolder.checkPermission(op.getPath(), WRITE);
            } else if (op.getType() == getData || op.getType() == exists || op.getType() == getChildren) {
                ThreadLocalVariableHolder.checkPermission(op.getPath(), READ);
            }
        }
        return zk.multi(ops);
    } catch (KeeperException e) {
        Logger.error("Multi operation fail. {}, {}", e.getPath(), ops, e);
        throw new MgmtZooKeeperException(e);
    } catch (InterruptedException e) {
        Logger.error("Multi operation fail. {}", ops, e);
        throw new MgmtZooKeeperException(e);
    }
}

From source file:org.midonet.midolman.state.ZkOpList.java

License:Apache License

private static String getOpDesc(Op op) {
    return ZooDefs.opNames[op.getType()] + " " + op.getPath();
}

From source file:org.midonet.midolman.state.ZkOpList.java

License:Apache License

/**
 * Add an Op object./*from  ww  w . j  a v a2s.  co m*/
 *
 * For delete Op, all the previously added updated and delete Ops are
 * replaced by this one.  If there was a create Op prior to it, delete Op is
 * not added, and the create Op is removed.
 *
 * For create Op, if another create Op already exists, this replaces it.
 *
 * @param op Op object to add
 */
public void add(Op op) {
    Preconditions.checkNotNull(op);
    Preconditions.checkArgument(validOpType(op.getType()));

    int type = op.getType();
    if (type == ZooDefs.OpCode.delete) {

        // Remove any updates previously added
        remove(this.updateOps, op.getPath());

        // Remove any create added but if there was a create, there is no
        // need to add the delete Op
        if (this.createOps.containsKey(op.getPath())) {
            this.createOps.remove(op.getPath());
            return;
        }

        // Replace any delete previously added
        this.deleteOps.put(op.getPath(), op);

    } else if (type == ZooDefs.OpCode.create) {

        // Replace the previously added create
        this.createOps.put(op.getPath(), op);

    } else if (type == ZooDefs.OpCode.setData) {

        // For updates, just add to the list
        this.updateOps.add(op);
    }
}

From source file:org.midonet.midolman.state.ZkUtil.java

License:Apache License

/**
 * Checks whether Op object is deletion/*from   www. j a v a 2s. c om*/
 *
 * @param op Op object to check
 * @return True if it's error
 */
public static boolean isDelete(Op op) {
    return op != null && op.getType() == ZooDefs.OpCode.delete;
}