Java Code Examples for org.apache.hadoop.util.ReflectionUtils#getClass()

The following examples show how to use org.apache.hadoop.util.ReflectionUtils#getClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodecPool.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static <T> boolean payback(Map<Class<T>, Set<T>> pool, T codec) {
  if (codec != null) {
    Class<T> codecClass = ReflectionUtils.getClass(codec);
    Set<T> codecSet;
    synchronized (pool) {
      codecSet = pool.get(codecClass);
      if (codecSet == null) {
        codecSet = new HashSet<T>();
        pool.put(codecClass, codecSet);
      }
    }

    synchronized (codecSet) {
      return codecSet.add(codec);
    }
  }
  return false;
}
 
Example 2
Source File: CodecPool.java    From big-c with Apache License 2.0 6 votes vote down vote up
private static <T> boolean payback(Map<Class<T>, Set<T>> pool, T codec) {
  if (codec != null) {
    Class<T> codecClass = ReflectionUtils.getClass(codec);
    Set<T> codecSet;
    synchronized (pool) {
      codecSet = pool.get(codecClass);
      if (codecSet == null) {
        codecSet = new HashSet<T>();
        pool.put(codecClass, codecSet);
      }
    }

    synchronized (codecSet) {
      return codecSet.add(codec);
    }
  }
  return false;
}
 
Example 3
Source File: CodecPool.java    From RDFS with Apache License 2.0 6 votes vote down vote up
private static <T> void payback(ConcurrentHashMap<Class<T>, List<T>> pool, 
                                T codec) {
  if (codec != null) {
    Class<T> codecClass = ReflectionUtils.getClass(codec);
    List<T> codecList = pool.get(codecClass);
    if (codecList == null) {
      codecList = new ArrayList<T>();
      List<T> old = pool.putIfAbsent(codecClass, codecList);
      if (old != null) {
        codecList = old; 
      }
    }
    synchronized (codecList) {
      codecList.add(codec);
    }
  }
}
 
Example 4
Source File: CodecPool.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static <T> void updateLeaseCount(
    LoadingCache<Class<T>, AtomicInteger> usageCounts, T codec, int delta) {
  if (codec != null) {
    Class<T> codecClass = ReflectionUtils.getClass(codec);
    usageCounts.getUnchecked(codecClass).addAndGet(delta);
  }
}
 
Example 5
Source File: CodecPool.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static <T> void updateLeaseCount(
    LoadingCache<Class<T>, AtomicInteger> usageCounts, T codec, int delta) {
  if (codec != null) {
    Class<T> codecClass = ReflectionUtils.getClass(codec);
    usageCounts.getUnchecked(codecClass).addAndGet(delta);
  }
}
 
Example 6
Source File: CodecPool.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
private static <T> void payback(Map<Class<T>, List<T>> pool, T codec) {
  if (codec != null) {
    Class<T> codecClass = ReflectionUtils.getClass(codec);
    synchronized (pool) {
      if (!pool.containsKey(codecClass)) {
        pool.put(codecClass, new ArrayList<T>());
      }

      List<T> codecList = pool.get(codecClass);
      synchronized (codecList) {
        codecList.add(codec);
      }
    }
  }
}