本文整理匯總了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");
}
}
示例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();
}
}
示例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;
}
示例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();
}
示例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);
}
}