• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Waitable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.hadoop.util.Waitable的典型用法代码示例。如果您正苦于以下问题:Java Waitable类的具体用法?Java Waitable怎么用?Java Waitable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Waitable类属于org.apache.hadoop.util包,在下文中一共展示了Waitable类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: purge

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
/**
 * Purge a replica from the cache.
 *
 * This doesn't necessarily close the replica, since there may be
 * outstanding references to it.  However, it does mean the cache won't
 * hand it out to anyone after this.
 *
 * You must hold the cache lock while calling this function.
 *
 * @param replica   The replica being removed.
 */
private void purge(ShortCircuitReplica replica) {
  boolean removedFromInfoMap = false;
  String evictionMapName = null;
  Preconditions.checkArgument(!replica.purged);
  replica.purged = true;
  Waitable<ShortCircuitReplicaInfo> val = replicaInfoMap.get(replica.key);
  if (val != null) {
    ShortCircuitReplicaInfo info = val.getVal();
    if ((info != null) && (info.getReplica() == replica)) {
      replicaInfoMap.remove(replica.key);
      removedFromInfoMap = true;
    }
  }
  Long evictableTimeNs = replica.getEvictableTimeNs();
  if (evictableTimeNs != null) {
    evictionMapName = removeEvictable(replica);
  }
  if (LOG.isTraceEnabled()) {
    StringBuilder builder = new StringBuilder();
    builder.append(this).append(": ").append(": purged ").
        append(replica).append(" from the cache.");
    if (removedFromInfoMap) {
      builder.append("  Removed from the replicaInfoMap.");
    }
    if (evictionMapName != null) {
      builder.append("  Removed from ").append(evictionMapName);
    }
    LOG.trace(builder.toString());
  }
  unref(replica);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:43,代码来源:ShortCircuitCache.java


示例2: fetchOrCreate

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
/**
 * Fetch or create a replica.
 *
 * You must hold the cache lock while calling this function.
 *
 * @param key          Key to use for lookup.
 * @param creator      Replica creator callback.  Will be called without
 *                     the cache lock being held.
 *
 * @return             Null if no replica could be found or created.
 *                     The replica, otherwise.
 */
public ShortCircuitReplicaInfo fetchOrCreate(ExtendedBlockId key,
    ShortCircuitReplicaCreator creator) {
  Waitable<ShortCircuitReplicaInfo> newWaitable = null;
  lock.lock();
  try {
    ShortCircuitReplicaInfo info = null;
    do {
      if (closed) {
        if (LOG.isTraceEnabled()) {
          LOG.trace(this + ": can't fetchOrCreate " + key +
              " because the cache is closed.");
        }
        return null;
      }
      Waitable<ShortCircuitReplicaInfo> waitable = replicaInfoMap.get(key);
      if (waitable != null) {
        try {
          info = fetch(key, waitable);
        } catch (RetriableException e) {
          if (LOG.isDebugEnabled()) {
            LOG.debug(this + ": retrying " + e.getMessage());
          }
          continue;
        }
      }
    } while (false);
    if (info != null) return info;
    // We need to load the replica ourselves.
    newWaitable = new Waitable<ShortCircuitReplicaInfo>(lock.newCondition());
    replicaInfoMap.put(key, newWaitable);
  } finally {
    lock.unlock();
  }
  return create(key, creator, newWaitable);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:48,代码来源:ShortCircuitCache.java


示例3: fetchOrCreate

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
/**
 * Fetch or create a replica.
 *
 * You must hold the cache lock while calling this function.
 *
 * @param key          Key to use for lookup.
 * @param creator      Replica creator callback.  Will be called without
 *                     the cache lock being held.
 *
 * @return             Null if no replica could be found or created.
 *                     The replica, otherwise.
 */
public ShortCircuitReplicaInfo fetchOrCreate(ExtendedBlockId key,
    ShortCircuitReplicaCreator creator) {
  Waitable<ShortCircuitReplicaInfo> newWaitable = null;
  lock.lock();
  try {
    ShortCircuitReplicaInfo info = null;
    do {
      if (closed) {
        LOG.trace("{}: can't fethchOrCreate {} because the cache is closed.",
            this, key);
        return null;
      }
      Waitable<ShortCircuitReplicaInfo> waitable = replicaInfoMap.get(key);
      if (waitable != null) {
        try {
          info = fetch(key, waitable);
        } catch (RetriableException e) {
          LOG.debug("{}: retrying {}", this, e.getMessage());
        }
      }
    } while (false);
    if (info != null) return info;
    // We need to load the replica ourselves.
    newWaitable = new Waitable<>(lock.newCondition());
    replicaInfoMap.put(key, newWaitable);
  } finally {
    lock.unlock();
  }
  return create(key, creator, newWaitable);
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:43,代码来源:ShortCircuitCache.java


示例4: create

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
private ShortCircuitReplicaInfo create(ExtendedBlockId key,
    ShortCircuitReplicaCreator creator,
    Waitable<ShortCircuitReplicaInfo> newWaitable) {
  // Handle loading a new replica.
  ShortCircuitReplicaInfo info = null;
  try {
    LOG.trace("{}: loading {}", this, key);
    info = creator.createShortCircuitReplicaInfo();
  } catch (RuntimeException e) {
    LOG.warn(this + ": failed to load " + key, e);
  }
  if (info == null) info = new ShortCircuitReplicaInfo();
  lock.lock();
  try {
    if (info.getReplica() != null) {
      // On success, make sure the cache cleaner thread is running.
      LOG.trace("{}: successfully loaded {}", this, info.getReplica());
      startCacheCleanerThreadIfNeeded();
      // Note: new ShortCircuitReplicas start with a refCount of 2,
      // indicating that both this cache and whoever requested the
      // creation of the replica hold a reference.  So we don't need
      // to increment the reference count here.
    } else {
      // On failure, remove the waitable from the replicaInfoMap.
      Waitable<ShortCircuitReplicaInfo> waitableInMap = replicaInfoMap.get(key);
      if (waitableInMap == newWaitable) replicaInfoMap.remove(key);
      if (info.getInvalidTokenException() != null) {
        LOG.info(this + ": could not load " + key + " due to InvalidToken " +
            "exception.", info.getInvalidTokenException());
      } else {
        LOG.warn(this + ": failed to load " + key);
      }
    }
    newWaitable.provide(info);
  } finally {
    lock.unlock();
  }
  return info;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:40,代码来源:ShortCircuitCache.java


示例5: accept

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
@VisibleForTesting // ONLY for testing
public void accept(CacheVisitor visitor) {
  lock.lock();
  try {
    Map<ExtendedBlockId, ShortCircuitReplica> replicas = new HashMap<>();
    Map<ExtendedBlockId, InvalidToken> failedLoads = new HashMap<>();
    for (Entry<ExtendedBlockId, Waitable<ShortCircuitReplicaInfo>> entry :
        replicaInfoMap.entrySet()) {
      Waitable<ShortCircuitReplicaInfo> waitable = entry.getValue();
      if (waitable.hasVal()) {
        if (waitable.getVal().getReplica() != null) {
          replicas.put(entry.getKey(), waitable.getVal().getReplica());
        } else {
          // The exception may be null here, indicating a failed load that
          // isn't the result of an invalid block token.
          failedLoads.put(entry.getKey(),
              waitable.getVal().getInvalidTokenException());
        }
      }
    }
    LOG.debug("visiting {} with outstandingMmapCount={}, replicas={}, "
            + "failedLoads={}, evictable={}, evictableMmapped={}",
        visitor.getClass().getName(), outstandingMmapCount, replicas,
        failedLoads, evictable, evictableMmapped);
    visitor.visit(outstandingMmapCount, replicas, failedLoads,
        evictable, evictableMmapped);
  } finally {
    lock.unlock();
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:31,代码来源:ShortCircuitCache.java


示例6: fetch

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
/**
 * Fetch an existing ReplicaInfo object.
 *
 * @param key       The key that we're using.
 * @param waitable  The waitable object to wait on.
 * @return          The existing ReplicaInfo object, or null if there is
 *                  none.
 *
 * @throws RetriableException   If the caller needs to retry.
 */
private ShortCircuitReplicaInfo fetch(ExtendedBlockId key,
    Waitable<ShortCircuitReplicaInfo> waitable) throws RetriableException {
  // Another thread is already in the process of loading this
  // ShortCircuitReplica.  So we simply wait for it to complete.
  ShortCircuitReplicaInfo info;
  try {
    if (LOG.isTraceEnabled()) {
      LOG.trace(this + ": found waitable for " + key);
    }
    info = waitable.await();
  } catch (InterruptedException e) {
    LOG.info(this + ": interrupted while waiting for " + key);
    Thread.currentThread().interrupt();
    throw new RetriableException("interrupted");
  }
  if (info.getInvalidTokenException() != null) {
    LOG.info(this + ": could not get " + key + " due to InvalidToken " +
          "exception.", info.getInvalidTokenException());
    return info;
  }
  ShortCircuitReplica replica = info.getReplica();
  if (replica == null) {
    LOG.warn(this + ": failed to get " + key);
    return info;
  }
  if (replica.purged) {
    // Ignore replicas that have already been purged from the cache.
    throw new RetriableException("Ignoring purged replica " +
        replica + ".  Retrying.");
  }
  // Check if the replica is stale before using it.
  // If it is, purge it and retry.
  if (replica.isStale()) {
    LOG.info(this + ": got stale replica " + replica + ".  Removing " +
        "this replica from the replicaInfoMap and retrying.");
    // Remove the cache's reference to the replica.  This may or may not
    // trigger a close.
    purge(replica);
    throw new RetriableException("ignoring stale replica " + replica);
  }
  ref(replica);
  return info;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:54,代码来源:ShortCircuitCache.java


示例7: create

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
private ShortCircuitReplicaInfo create(ExtendedBlockId key,
    ShortCircuitReplicaCreator creator,
    Waitable<ShortCircuitReplicaInfo> newWaitable) {
  // Handle loading a new replica.
  ShortCircuitReplicaInfo info = null;
  try {
    if (LOG.isTraceEnabled()) {
      LOG.trace(this + ": loading " + key);
    }
    info = creator.createShortCircuitReplicaInfo();
  } catch (RuntimeException e) {
    LOG.warn(this + ": failed to load " + key, e);
  }
  if (info == null) info = new ShortCircuitReplicaInfo();
  lock.lock();
  try {
    if (info.getReplica() != null) {
      // On success, make sure the cache cleaner thread is running.
      if (LOG.isTraceEnabled()) {
        LOG.trace(this + ": successfully loaded " + info.getReplica());
      }
      startCacheCleanerThreadIfNeeded();
      // Note: new ShortCircuitReplicas start with a refCount of 2,
      // indicating that both this cache and whoever requested the 
      // creation of the replica hold a reference.  So we don't need
      // to increment the reference count here.
    } else {
      // On failure, remove the waitable from the replicaInfoMap.
      Waitable<ShortCircuitReplicaInfo> waitableInMap = replicaInfoMap.get(key);
      if (waitableInMap == newWaitable) replicaInfoMap.remove(key);
      if (info.getInvalidTokenException() != null) {
        LOG.info(this + ": could not load " + key + " due to InvalidToken " +
            "exception.", info.getInvalidTokenException());
      } else {
        LOG.warn(this + ": failed to load " + key);
      }
    }
    newWaitable.provide(info);
  } finally {
    lock.unlock();
  }
  return info;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:44,代码来源:ShortCircuitCache.java


示例8: fetch

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
/**
 * Fetch an existing ReplicaInfo object.
 *
 * @param key       The key that we're using.
 * @param waitable  The waitable object to wait on.
 * @return          The existing ReplicaInfo object, or null if there is
 *                  none.
 *
 * @throws RetriableException   If the caller needs to retry.
 */
private ShortCircuitReplicaInfo fetch(ExtendedBlockId key,
    Waitable<ShortCircuitReplicaInfo> waitable) throws RetriableException {
  // Another thread is already in the process of loading this
  // ShortCircuitReplica.  So we simply wait for it to complete.
  ShortCircuitReplicaInfo info;
  try {
    LOG.trace("{}: found waitable for {}", this, key);
    info = waitable.await();
  } catch (InterruptedException e) {
    LOG.info(this + ": interrupted while waiting for " + key);
    Thread.currentThread().interrupt();
    throw new RetriableException("interrupted");
  }
  if (info.getInvalidTokenException() != null) {
    LOG.info(this + ": could not get " + key + " due to InvalidToken " +
        "exception.", info.getInvalidTokenException());
    return info;
  }
  ShortCircuitReplica replica = info.getReplica();
  if (replica == null) {
    LOG.warn(this + ": failed to get " + key);
    return info;
  }
  if (replica.purged) {
    // Ignore replicas that have already been purged from the cache.
    throw new RetriableException("Ignoring purged replica " +
        replica + ".  Retrying.");
  }
  // Check if the replica is stale before using it.
  // If it is, purge it and retry.
  if (replica.isStale()) {
    LOG.info(this + ": got stale replica " + replica + ".  Removing " +
        "this replica from the replicaInfoMap and retrying.");
    // Remove the cache's reference to the replica.  This may or may not
    // trigger a close.
    purge(replica);
    throw new RetriableException("ignoring stale replica " + replica);
  }
  ref(replica);
  return info;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:52,代码来源:ShortCircuitCache.java


示例9: fetch

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
/**
 * Fetch an existing ReplicaInfo object.
 *
 * @param key       The key that we're using.
 * @param waitable  The waitable object to wait on.
 * @return          The existing ReplicaInfo object, or null if there is
 *                  none.
 *
 * @throws RetriableException   If the caller needs to retry.
 */
private ShortCircuitReplicaInfo fetch(ExtendedBlockId key,
    Waitable<ShortCircuitReplicaInfo> waitable) throws RetriableException {
  // Another thread is already in the process of loading this
  // ShortCircuitReplica.  So we simply wait for it to complete.
  ShortCircuitReplicaInfo info;
  try {
    if (LOG.isTraceEnabled()) {
      LOG.trace(this + ": found waitable for " + key);
    }
    info = waitable.await();
  } catch (InterruptedException e) {
    LOG.info(this + ": interrupted while waiting for " + key);
    Thread.currentThread().interrupt();
    throw new RetriableException("interrupted");
  }
  if (info.getInvalidTokenException() != null) {
    LOG.warn(this + ": could not get " + key + " due to InvalidToken " +
          "exception.", info.getInvalidTokenException());
    return info;
  }
  ShortCircuitReplica replica = info.getReplica();
  if (replica == null) {
    LOG.warn(this + ": failed to get " + key);
    return info;
  }
  if (replica.purged) {
    // Ignore replicas that have already been purged from the cache.
    throw new RetriableException("Ignoring purged replica " +
        replica + ".  Retrying.");
  }
  // Check if the replica is stale before using it.
  // If it is, purge it and retry.
  if (replica.isStale()) {
    LOG.info(this + ": got stale replica " + replica + ".  Removing " +
        "this replica from the replicaInfoMap and retrying.");
    // Remove the cache's reference to the replica.  This may or may not
    // trigger a close.
    purge(replica);
    throw new RetriableException("ignoring stale replica " + replica);
  }
  ref(replica);
  return info;
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:54,代码来源:ShortCircuitCache.java


示例10: create

import org.apache.hadoop.util.Waitable; //导入依赖的package包/类
private ShortCircuitReplicaInfo create(ExtendedBlockId key,
    ShortCircuitReplicaCreator creator,
    Waitable<ShortCircuitReplicaInfo> newWaitable) {
  // Handle loading a new replica.
  ShortCircuitReplicaInfo info = null;
  try {
    if (LOG.isTraceEnabled()) {
      LOG.trace(this + ": loading " + key);
    }
    info = creator.createShortCircuitReplicaInfo();
  } catch (RuntimeException e) {
    LOG.warn(this + ": failed to load " + key, e);
  }
  if (info == null) info = new ShortCircuitReplicaInfo();
  lock.lock();
  try {
    if (info.getReplica() != null) {
      // On success, make sure the cache cleaner thread is running.
      if (LOG.isTraceEnabled()) {
        LOG.trace(this + ": successfully loaded " + info.getReplica());
      }
      startCacheCleanerThreadIfNeeded();
      // Note: new ShortCircuitReplicas start with a refCount of 2,
      // indicating that both this cache and whoever requested the 
      // creation of the replica hold a reference.  So we don't need
      // to increment the reference count here.
    } else {
      // On failure, remove the waitable from the replicaInfoMap.
      Waitable<ShortCircuitReplicaInfo> waitableInMap = replicaInfoMap.get(key);
      if (waitableInMap == newWaitable) replicaInfoMap.remove(key);
      if (info.getInvalidTokenException() != null) {
        LOG.warn(this + ": could not load " + key + " due to InvalidToken " +
            "exception.", info.getInvalidTokenException());
      } else {
        LOG.warn(this + ": failed to load " + key);
      }
    }
    newWaitable.provide(info);
  } finally {
    lock.unlock();
  }
  return info;
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:44,代码来源:ShortCircuitCache.java



注:本文中的org.apache.hadoop.util.Waitable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VfsTestUtil类代码示例发布时间:2022-05-23
下一篇:
Java ConstUI类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap