List of usage examples for org.apache.zookeeper ZooKeeper multi
public List<OpResult> multi(Iterable<Op> ops) throws InterruptedException, KeeperException
From source file:com.navercorp.nbasearc.confmaster.repository.dao.zookeeper.ZkWorkflowLogDao.java
License:Apache License
@Override public synchronized void log(long jobID, String severity, String name, String type, String clusterName, String msg, String jsonArg) { while (numLogs >= config.getServerJobWorkflowLogMax()) { deleteLog(getNumOfStartLog());//from w ww.j ava 2s .c om } byte[] data; String path = pathOfLog(getLast()); List<Op> ops = new ArrayList<Op>(); ZkWorkflowLog workflowLog = new ZkWorkflowLog(getLast(), new Date(), jobID, type, severity, name, msg, clusterName, jsonArg); try { data = mapper.writeValueAsBytes(workflowLog); Long maxLogNo = getNumOfStartLog() + getNumLogs(); ops.add(Op.create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)); ops.add(Op.setData(rootPathOfLog(), String.valueOf(maxLogNo).getBytes(config.getCharset()), -1)); ZooKeeper zk = zookeeper.getZooKeeper(); List<OpResult> results = zk.multi(ops); zookeeper.handleResultsOfMulti(results); } catch (Exception e) { Logger.error(workflowLog.toString(), e); } Logger.info(workflowLog.toStringWithoutInfo()); increaseNumLogs(); }
From source file:org.apache.bookkeeper.zookeeper.BkZooKeeperClient.java
License:Apache License
@Override public List<OpResult> multi(final Iterable<Op> ops) throws InterruptedException, KeeperException { return BkZooWorker.syncCallWithRetries(this, new ZooCallable<List<OpResult>>() { @Override//from w w w . j a v a 2s . com public String toString() { return "multi"; } @Override public List<OpResult> call() throws KeeperException, InterruptedException { ZooKeeper zkHandle = zk.get(); if (null == zkHandle) { return BkZooKeeperClient.super.multi(ops); } return zkHandle.multi(ops); } }, operationRetryPolicy, rateLimiter, multiStats); }
From source file:org.apache.bookkeeper.zookeeper.ZooKeeperClient.java
License:Apache License
@Override public List<OpResult> multi(final Iterable<Op> ops) throws InterruptedException, KeeperException { return ZooWorker.syncCallWithRetries(this, new ZooCallable<List<OpResult>>() { @Override/*www .ja v a2 s . com*/ public String toString() { return "multi"; } @Override public List<OpResult> call() throws KeeperException, InterruptedException { ZooKeeper zkHandle = zk.get(); if (null == zkHandle) { return ZooKeeperClient.super.multi(ops); } return zkHandle.multi(ops); } }, operationRetryPolicy, rateLimiter, multiStats); }
From source file:org.midonet.api.tools.InitZkDirectories.java
License:Apache License
/** * @param args//from w w w .j a v a 2 s. co m * @throws IOException * @throws KeeperException * @throws InterruptedException */ public static void main(String[] args) throws IOException, InterruptedException, KeeperException { ZooKeeper zk = new ZooKeeper(args[0], 300, null); List<Op> ops = new ArrayList<Op>(); ops.add(Op.create("/midonet", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)); ops.add(Op.create("/midonet/v1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)); zk.multi(ops); /* * // TODO: Do better arg checking if (args.length != 2) { throw new * IllegalArgumentException( "Usage: InitZkDirectorires <API url>"); } * String url = args[0]; String token = args[1]; * * Client client = Client.create(); WebResource webResource = * client.resource(url + "/admin/init"); ClientResponse response = * webResource.type(MediaType.APPLICATION_JSON) .header(tokenHeader, * token).post(ClientResponse.class, null); if (response.getStatus() != * 200) { System.out.println("Error occurred:" + * response.getEntity(String.class)); } else { * System.out.println("Succeeded"); } */ return; }