org.jruby.Ruby.getHierarchyLock()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(97)

本文整理了Java中org.jruby.Ruby.getHierarchyLock方法的一些代码示例,展示了Ruby.getHierarchyLock的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getHierarchyLock方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getHierarchyLock

Ruby.getHierarchyLock介绍

[英]Get the global object used to synchronize class-hierarchy modifications like cache invalidation, subclass sets, and included hierarchy sets.
[中]获取用于同步类层次结构修改(如缓存失效、子类集和包含的层次结构集)的全局对象。

代码示例

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * Remove a subclass from the weak set of subclasses.
 *
 * @param subclass The subclass to remove
 */
public synchronized void removeSubclass(RubyClass subclass) {
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> oldSubclasses = subclasses;
    if (oldSubclasses == null) return;
    oldSubclasses.remove(subclass);
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * Remove a subclass from the weak set of subclasses.
 *
 * @param subclass The subclass to remove
 */
public synchronized void removeSubclass(RubyClass subclass) {
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> oldSubclasses = subclasses;
    if (oldSubclasses == null) return;
    oldSubclasses.remove(subclass);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * Replace an existing subclass with a new one.
 *
 * @param subclass The subclass to remove
 * @param newSubclass The subclass to replace it with
 */
public synchronized void replaceSubclass(RubyClass subclass, RubyClass newSubclass) {
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> oldSubclasses = subclasses;
    if (oldSubclasses == null) return;
    oldSubclasses.remove(subclass);
    oldSubclasses.add(newSubclass);
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * Replace an existing subclass with a new one.
 *
 * @param subclass The subclass to remove
 * @param newSubclass The subclass to replace it with
 */
public synchronized void replaceSubclass(RubyClass subclass, RubyClass newSubclass) {
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> oldSubclasses = subclasses;
    if (oldSubclasses == null) return;
    oldSubclasses.remove(subclass);
    oldSubclasses.add(newSubclass);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * Add a new subclass to the weak set of subclasses.
 *
 * This version always constructs a new set to avoid having to synchronize
 * against the set when iterating it for invalidation in
 * invalidateCacheDescendants.
 *
 * @param subclass The subclass to add
 */
public synchronized void addSubclass(RubyClass subclass) {
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> oldSubclasses = subclasses;
    if (oldSubclasses == null) subclasses = oldSubclasses = new WeakHashSet<RubyClass>(4);
    oldSubclasses.add(subclass);
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * Add a new subclass to the weak set of subclasses.
 *
 * This version always constructs a new set to avoid having to synchronize
 * against the set when iterating it for invalidation in
 * invalidateCacheDescendants.
 *
 * @param subclass The subclass to add
 */
public synchronized void addSubclass(RubyClass subclass) {
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> oldSubclasses = subclasses;
    if (oldSubclasses == null) subclasses = oldSubclasses = new WeakHashSet<RubyClass>(4);
    oldSubclasses.add(subclass);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public void addInvalidatorsAndFlush(List<Invalidator> invalidators) {
  // add this class's invalidators to the aggregate
  invalidators.add(methodInvalidator);
  
  // if we're not at boot time, don't bother fully clearing caches
  if (!runtime.isBooting()) cachedMethods.clear();
  // no subclasses, don't bother with lock and iteration
  if (subclasses == null || subclasses.isEmpty()) return;
  
  // cascade into subclasses
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> mySubclasses = subclasses;
    if (mySubclasses != null) for (RubyClass subclass : mySubclasses) {
      subclass.addInvalidatorsAndFlush(invalidators);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

@SuppressWarnings("unchecked")
public void addIncludingHierarchy(IncludedModule hierarchy) {
  synchronized (getRuntime().getHierarchyLock()) {
    Set<RubyClass> including = this.includingHierarchies;
    if (including == Collections.EMPTY_SET) {
      including = this.includingHierarchies = new WeakHashSet(4);
    }
    including.add(hierarchy);
  }
}

代码示例来源:origin: org.jruby/jruby-core

@SuppressWarnings("unchecked")
public void addIncludingHierarchy(IncludedModule hierarchy) {
  synchronized (getRuntime().getHierarchyLock()) {
    Set<RubyClass> including = this.includingHierarchies;
    if (including == Collections.EMPTY_SET) {
      including = this.includingHierarchies = new WeakHashSet(4);
    }
    including.add(hierarchy);
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public void addInvalidatorsAndFlush(List<Invalidator> invalidators) {
  // add this class's invalidators to the aggregate
  invalidators.add(methodInvalidator);
  
  // if we're not at boot time, don't bother fully clearing caches
  if (!runtime.isBooting()) cachedMethods.clear();
  // no subclasses, don't bother with lock and iteration
  if (subclasses == null || subclasses.isEmpty()) return;
  
  // cascade into subclasses
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> mySubclasses = subclasses;
    if (mySubclasses != null) for (RubyClass subclass : mySubclasses) {
      subclass.addInvalidatorsAndFlush(invalidators);
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public void addIncludingHierarchy(IncludedModuleWrapper hierarchy) {
  synchronized (getRuntime().getHierarchyLock()) {
    Set<RubyClass> oldIncludingHierarchies = includingHierarchies;
    if (oldIncludingHierarchies == Collections.EMPTY_SET) includingHierarchies = oldIncludingHierarchies = new WeakHashSet(4);
    oldIncludingHierarchies.add(hierarchy);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public void addIncludingHierarchy(IncludedModuleWrapper hierarchy) {
  synchronized (getRuntime().getHierarchyLock()) {
    Set<RubyClass> oldIncludingHierarchies = includingHierarchies;
    if (oldIncludingHierarchies == Collections.EMPTY_SET) includingHierarchies = oldIncludingHierarchies = new WeakHashSet(4);
    oldIncludingHierarchies.add(hierarchy);
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public void invalidateCacheDescendants() {
  if (DEBUG) LOG.debug("invalidating descendants: {}", baseName);
  if (includingHierarchies.isEmpty()) {
    // it's only us; just invalidate directly
    methodInvalidator.invalidate();
    return;
  }
  List<Invalidator> invalidators = new ArrayList();
  invalidators.add(methodInvalidator);
  
  synchronized (getRuntime().getHierarchyLock()) {
    for (RubyClass includingHierarchy : includingHierarchies) {
      includingHierarchy.addInvalidatorsAndFlush(invalidators);
    }
  }
  
  methodInvalidator.invalidateAll(invalidators);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public void invalidateCacheDescendants() {
  if (DEBUG) LOG.debug("invalidating descendants: {}", baseName);
  if (includingHierarchies.isEmpty()) {
    // it's only us; just invalidate directly
    methodInvalidator.invalidate();
    return;
  }
  List<Invalidator> invalidators = new ArrayList();
  invalidators.add(methodInvalidator);
  
  synchronized (getRuntime().getHierarchyLock()) {
    for (RubyClass includingHierarchy : includingHierarchies) {
      includingHierarchy.addInvalidatorsAndFlush(invalidators);
    }
  }
  
  methodInvalidator.invalidateAll(invalidators);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public void becomeSynchronized() {
  // make this class and all subclasses sync
  synchronized (getRuntime().getHierarchyLock()) {
    super.becomeSynchronized();
    Set<RubyClass> mySubclasses = subclasses;
    if (mySubclasses != null) for (RubyClass subclass : mySubclasses) {
      subclass.becomeSynchronized();
    }
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * Invalidate all subclasses of this class by walking the set of all
 * subclasses and asking them to invalidate themselves.
 *
 * Note that this version works against a reference to the current set of
 * subclasses, which could be replaced by the time this iteration is
 * complete. In theory, there may be a path by which invalidation would
 * miss a class added during the invalidation process, but the exposure is
 * minimal if it exists at all. The only way to prevent it would be to
 * synchronize both invalidation and subclass set modification against a
 * global lock, which we would like to avoid.
 */
@Override
public void invalidateCacheDescendants() {
  super.invalidateCacheDescendants();
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> mySubclasses = subclasses;
    if (mySubclasses != null) for (RubyClass subclass : mySubclasses) {
      subclass.invalidateCacheDescendants();
    }
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public void becomeSynchronized() {
  // make this class and all subclasses sync
  synchronized (getRuntime().getHierarchyLock()) {
    super.becomeSynchronized();
    Set<RubyClass> mySubclasses = subclasses;
    if (mySubclasses != null) for (RubyClass subclass : mySubclasses) {
      subclass.becomeSynchronized();
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * Invalidate all subclasses of this class by walking the set of all
 * subclasses and asking them to invalidate themselves.
 *
 * Note that this version works against a reference to the current set of
 * subclasses, which could be replaced by the time this iteration is
 * complete. In theory, there may be a path by which invalidation would
 * miss a class added during the invalidation process, but the exposure is
 * minimal if it exists at all. The only way to prevent it would be to
 * synchronize both invalidation and subclass set modification against a
 * global lock, which we would like to avoid.
 */
@Override
public void invalidateCacheDescendants() {
  super.invalidateCacheDescendants();
  synchronized (runtime.getHierarchyLock()) {
    Set<RubyClass> mySubclasses = subclasses;
    if (mySubclasses != null) for (RubyClass subclass : mySubclasses) {
      subclass.invalidateCacheDescendants();
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

public void invalidateCacheDescendants() {
  LOG.debug("{} invalidating descendants", baseName);
  getRuntime().getCaches().incrementMethodInvalidations();
  if (includingHierarchies.isEmpty()) {
    // it's only us; just invalidate directly
    methodInvalidator.invalidate();
    return;
  }
  List<Invalidator> invalidators = new ArrayList<Invalidator>();
  invalidators.add(methodInvalidator);
  synchronized (getRuntime().getHierarchyLock()) {
    for (RubyClass includingHierarchy : includingHierarchies) {
      includingHierarchy.addInvalidatorsAndFlush(invalidators);
    }
  }
  methodInvalidator.invalidateAll(invalidators);
}

代码示例来源:origin: org.jruby/jruby-core

public void invalidateCacheDescendants() {
  LOG.debug("{} invalidating descendants", baseName);
  getRuntime().getCaches().incrementMethodInvalidations();
  if (includingHierarchies.isEmpty()) {
    // it's only us; just invalidate directly
    methodInvalidator.invalidate();
    return;
  }
  List<Invalidator> invalidators = new ArrayList<Invalidator>();
  invalidators.add(methodInvalidator);
  synchronized (getRuntime().getHierarchyLock()) {
    for (RubyClass includingHierarchy : includingHierarchies) {
      includingHierarchy.addInvalidatorsAndFlush(invalidators);
    }
  }
  methodInvalidator.invalidateAll(invalidators);
}

相关文章

微信公众号

最新文章

更多

Ruby类方法