當前位置: 首頁>>代碼示例>>Java>>正文


Java Stat.getCtime方法代碼示例

本文整理匯總了Java中org.apache.zookeeper.data.Stat.getCtime方法的典型用法代碼示例。如果您正苦於以下問題:Java Stat.getCtime方法的具體用法?Java Stat.getCtime怎麽用?Java Stat.getCtime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.zookeeper.data.Stat的用法示例。


在下文中一共展示了Stat.getCtime方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ScheduleDataManager4ZK

import org.apache.zookeeper.data.Stat; //導入方法依賴的package包/類
public ScheduleDataManager4ZK(ZKManager aZkManager) throws Exception {
   	this.zkManager = aZkManager;
   	gson = new GsonBuilder().registerTypeAdapter(Timestamp.class,new TimestampTypeAdapter()).setDateFormat("yyyy-MM-dd HH:mm:ss").create();

	this.PATH_BaseTaskType = this.zkManager.getRootPath() +"/baseTaskType";
	
	if (this.getZooKeeper().exists(this.PATH_BaseTaskType, false) == null) {
		ZKTools.createPath(getZooKeeper(),this.PATH_BaseTaskType, CreateMode.PERSISTENT, this.zkManager.getAcl());
	}
	loclaBaseTime = System.currentTimeMillis();
       String tempPath = this.zkManager.getZooKeeper().create(this.zkManager.getRootPath() + "/systime",null, this.zkManager.getAcl(), CreateMode.EPHEMERAL_SEQUENTIAL);
       Stat tempStat = this.zkManager.getZooKeeper().exists(tempPath, false);
       zkBaseTime = tempStat.getCtime();
       ZKTools.deleteTree(getZooKeeper(), tempPath);
       if(Math.abs(this.zkBaseTime - this.loclaBaseTime) > 5000){
       	log.error("請注意,Zookeeper服務器時間與本地時間相差 : " + Math.abs(this.zkBaseTime - this.loclaBaseTime) +" ms");
       }	
}
 
開發者ID:hungki,項目名稱:tbschedule-wed,代碼行數:19,代碼來源:ScheduleDataManager4ZK.java

示例2: SchedulerServerForZookeeper

import org.apache.zookeeper.data.Stat; //導入方法依賴的package包/類
public SchedulerServerForZookeeper(ZKManager zkManager, String pathServer, String pathTask) {
    this.zkManager = zkManager;
    this.pathTask = pathTask;
    this.pathServer = pathServer;
    try {
        long timeApart = 5000;
        // zookeeper時間與服務端時間差距判斷
        String tempPath = this.zkManager.getZooKeeper().create(this.zkManager.getRootPath() + "/systime", null, this.zkManager.getAcl(), CreateMode.EPHEMERAL_SEQUENTIAL);
        Stat tempStat = this.zkManager.getZooKeeper().exists(tempPath, false);
        zkBaseTime = tempStat.getCtime();
        ZKTools.deleteTree(this.zkManager.getZooKeeper(), tempPath);
        loclaBaseTime = System.currentTimeMillis();
        if (Math.abs(this.zkBaseTime - this.loclaBaseTime) > timeApart) {
            LOG.error("請注意,Zookeeper服務器時間與本地時間相差 : " + Math.abs(this.zkBaseTime - this.loclaBaseTime) + " ms");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:liuht777,項目名稱:uncode-scheduler,代碼行數:20,代碼來源:SchedulerServerForZookeeper.java

示例3: getCreateTime

import org.apache.zookeeper.data.Stat; //導入方法依賴的package包/類
public long getCreateTime(String path) throws KeeperException, InterruptedException {
    Stat stat = _zk.exists(path, false);
    if (stat != null) {
        return stat.getCtime();
    }
    return -1;
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:8,代碼來源:ZkConnection.java

示例4: setZNode

import org.apache.zookeeper.data.Stat; //導入方法依賴的package包/類
@PUT
@Produces( { MediaType.APPLICATION_JSON, "application/javascript",
        MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response setZNode(
        @PathParam("path") String path,
        @QueryParam("callback") String callback,
        @DefaultValue("-1") @QueryParam("version") String versionParam,
        @DefaultValue("base64") @QueryParam("dataformat") String dataformat,
        @DefaultValue("false") @QueryParam("null") String setNull,
        @Context UriInfo ui, byte[] data) throws InterruptedException,
        KeeperException {
    ensurePathNotNull(path);

    int version;
    try {
        version = Integer.parseInt(versionParam);
    } catch (NumberFormatException e) {
        throw new WebApplicationException(Response.status(
                Response.Status.BAD_REQUEST).entity(
                new ZError(ui.getRequestUri().toString(), path
                        + " bad version " + versionParam)).build());
    }

    if (setNull.equals("true")) {
        data = null;
    }

    Stat stat = zk.setData(path, data, version);

    ZStat zstat = new ZStat(path, ui.getAbsolutePath().toString(), null,
            null, stat.getCzxid(), stat.getMzxid(), stat.getCtime(), stat
                    .getMtime(), stat.getVersion(), stat.getCversion(),
            stat.getAversion(), stat.getEphemeralOwner(), stat
                    .getDataLength(), stat.getNumChildren(), stat
                    .getPzxid());

    return Response.status(Response.Status.OK).entity(
            new JSONWithPadding(zstat, callback)).build();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:41,代碼來源:ZNodeResource.java

示例5: reapExpiredLocks

import org.apache.zookeeper.data.Stat; //導入方法依賴的package包/類
/**
 * Will delete all lock znodes of this type (either read or write) which are "expired"
 * according to timeout. Assumption is that the clock skew between zookeeper and this servers
 * is negligible.
 * Referred in zk recipe as "Revocable Shared Locks with Freaking Laser Beams".
 * (http://zookeeper.apache.org/doc/trunk/recipes.html).
 */
public void reapExpiredLocks(long timeout) throws IOException {
  List<String> children;
  try {
    children = ZKUtil.listChildrenNoWatch(zkWatcher, parentLockNode);
  } catch (KeeperException e) {
    LOG.error("Unexpected ZooKeeper error when listing children", e);
    throw new IOException("Unexpected ZooKeeper exception", e);
  }
  if (children == null) return;

  KeeperException deferred = null;
  Stat stat = new Stat();
  long expireDate = System.currentTimeMillis() - timeout; //we are using cTime in zookeeper
  for (String child : children) {
    if (isChildOfSameType(child)) {
      String znode = ZKUtil.joinZNode(parentLockNode, child);
      try {
        ZKUtil.getDataNoWatch(zkWatcher, znode, stat);
        if (stat.getCtime() < expireDate) {
          LOG.info("Reaping lock for znode:" + znode);
          ZKUtil.deleteNodeFailSilent(zkWatcher, znode);
        }
      } catch (KeeperException ex) {
        LOG.warn("Error reaping the znode for write lock :" + znode);
        deferred = ex;
      }
    }
  }
  if (deferred != null) {
    throw new IOException("ZK exception while reaping locks:", deferred);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:40,代碼來源:ZKInterProcessLockBase.java


注:本文中的org.apache.zookeeper.data.Stat.getCtime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。