org.openide.util.Mutex.isReadAccess()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(202)

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

Mutex.isReadAccess介绍

[英]Tests whether this thread has already entered the mutex in read access. If it returns true, calling readAccess will be executed immediatelly without any blocking. Calling postWriteAccess will delay the execution of its Runnable until a readAccess section is over and calling writeAccess is strongly prohibited and will result in a warning as a deadlock prone behaviour.

Warning: since a thread with write access automatically has effective read access as well (whether or not explicitly requested), if you want to check whether a thread can read some data, you should check for either kind of access, e.g.:

assert myMutex.isReadAccess() || myMutex.isWriteAccess();

[中]测试此线程是否已在读取访问中进入互斥锁。如果返回true,调用readAccess将立即执行,无任何阻塞。调用postWriteAccess将延迟其Runnable的执行,直到readAccess部分结束,并且强烈禁止调用writeAccess,这将导致作为易死锁行为的警告。
警告:由于具有写访问权限的线程也会自动具有有效的读访问权限(无论是否明确请求),如果要检查线程是否可以读取某些数据,应检查这两种访问,例如:

assert myMutex.isReadAccess() || myMutex.isWriteAccess();

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-util

return m.isReadAccess();

代码示例来源:origin: org.netbeans.api/org-openide-util

if (m.isWriteAccess() || m.isReadAccess()) {
  run.run();
} else {

代码示例来源:origin: org.netbeans.api/org-openide-nodes

public void execute(Runnable command) {
  boolean ea = false;
  assert ea = true;
  if (ea) {
    Mutex mutex = getPMMutex();
    if (mutex != null && (mutex.isReadAccess() || mutex.isWriteAccess())) {
      throw new IllegalStateException("Should not acquire Children.MUTEX while holding ProjectManager.mutex()");
    }
  }
  command.run();
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

notifyLater = Children.MUTEX.isReadAccess();
  if (LOG_ENABLED) {
    LOGGER.finer("notifyAll for " + this + " on " + Thread.currentThread() + "  notifyLater: " + notifyLater); // NOI18N
if (Children.MUTEX.isReadAccess() || Children.MUTEX.isWriteAccess() || (initThread == Thread.currentThread())) {
    LOGGER.log(Level.FINER, "cannot initialize better " + this + " on " + Thread.currentThread() + " read access: " + Children.MUTEX.isReadAccess() + " write access: " + Children.MUTEX.isWriteAccess() + " initThread: " + initThread);

代码示例来源:origin: org.netbeans.api/org-openide-nodes

Children.PR.exitReadAccess();
if (Children.MUTEX.isReadAccess()) {
  return tmpNodes;

代码示例来源:origin: org.netbeans.api/org-openide-nodes

if (Children.MUTEX.isReadAccess()) {
      Children.MUTEX.postWriteRequest(notify);
    } else {
if (Children.MUTEX.isReadAccess() || Children.MUTEX.isWriteAccess() || (state.initThread() == Thread.currentThread())) {
  if (LOG_ENABLED) {
    LOGGER.log(Level.FINER, "Cannot wait for finished initialization " + this + " on " + Thread.currentThread() + " read access: " + Children.MUTEX.isReadAccess() + " write access: " + Children.MUTEX.isWriteAccess() + " initThread: " + state.initThread());

代码示例来源:origin: org.netbeans.api/org-openide-nodes

@Override
public Node getNodeAt(int index) {
  if (!checkInit()) {
    return null;
  }
  Node node = null;
  while (true) {
    try {
      Children.PR.enterReadAccess();
      EntrySupportLazyState state = internal.get();
      List<Entry> e = notNull(state.getVisibleEntries());
      if (index >= e.size()) {
        return node;
      }
      Entry entry = e.get(index);
      EntryInfo info = state.getEntryToInfo().get(entry);
      node = info.getNode();
      if (!isDummyNode(node)) {
        return node;
      }
      hideEmpty(null, entry);
    } finally {
      Children.PR.exitReadAccess();
    }
    if (Children.MUTEX.isReadAccess()) {
      return node;
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-projectapi-nb

@Override
public boolean isReadAccess() {
  return owner.MUTEX.isReadAccess();
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

private final void collectNodes(Node n, Map<Node,?> collect) {
  assert Children.MUTEX.isReadAccess();
  while (n != null && n != rootContext) {
    collect.put(n, null);
    n = n.getParentNode();
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-model

/**
 * Checks whether the current thread has a read or a write access granted.
 * @return true if a read or a write access is granted
 */
public boolean isAccess () {
  return mutex.isReadAccess ()  ||  mutex.isWriteAccess ();
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

/**
 * @return true if it is safe to wait (our thread is
 *         not in Children.MUTEX.readAccess
 */
private static boolean checkChildrenMutex() {
  return !Children.MUTEX.isReadAccess() && !Children.MUTEX.isWriteAccess ();
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-rakeproject

/**
 * Check whether this project is currently modified including modifications
 * to <code>project.xml</code>.
 * Access from GeneratedFilesHelper.
 */
boolean isProjectXmlModified() {
  assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
  return modifiedMetadataPaths.contains(PROJECT_XML_PATH);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-navigation

public void setEmpty() {
  menuAvaliable.set(false);
  updateButtons();
  final Children children = root.getChildren();
  if (!Children.MUTEX.isReadAccess()){
    Children.MUTEX.writeAccess(new Runnable(){
      @Override
      public void run() {
        children.remove(children.getNodes());
      }
    });
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-navigation

public void setEmpty() {
  menuAvaliable.set(false);
  updateButtons();
  final Children children = root.getChildren();
  if (!Children.MUTEX.isReadAccess()){
    Children.MUTEX.writeAccess(new Runnable(){
      @Override
      public void run() {
        children.remove(children.getNodes());
        refreshTask.cancel();
      }
    });
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

public GuardedActions(int type, Object p1) {
  this.type = type;
  this.p1 = p1;
  if (Children.MUTEX.isReadAccess() || Children.MUTEX.isWriteAccess()) {
    ret = run();
  } else {
    ret = Children.MUTEX.readAccess(this);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

public GuardedActions(int type, Object p1) {
  this.type = type;
  this.p1 = p1;
  if (Children.MUTEX.isReadAccess() || Children.MUTEX.isWriteAccess()) {
    ret = run();
  } else {
    ret = Children.MUTEX.readAccess(this);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

@SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
public GuardedActions(int type, Object p1) {
  this.type = type;
  this.p1 = p1;
  if (Children.MUTEX.isReadAccess() || Children.MUTEX.isWriteAccess()) {
    ret = run();
  } else {
    ret = Children.MUTEX.readAccess(this);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-rakeproject

/**
 * Load <references> from project.xml.
 * @return can return null if there are no references stored yet
 */
private Element loadReferences() {
  assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
  Element references = aux.getConfigurationFragment(REFS_NAME, REFS_NS2, true);
  if (references == null) {
    references = aux.getConfigurationFragment(REFS_NAME, REFS_NS, true);
  }
  return references;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-maven-indexer

private void fireChangeIndex(final RepositoryInfo repo) {
  if (getRepoMutex(repo).isWriteAccess()) {
    RequestProcessor.getDefault().post(new Runnable() {
      @Override
      public void run() {
        fireChangeIndex(repo);
      }
    });
    return;
  }
  assert !getRepoMutex(repo).isWriteAccess() && !getRepoMutex(repo).isReadAccess();
  repo.fireChangeIndex();
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

private void repaintSelection() {
  if (Children.MUTEX.isReadAccess() || Children.MUTEX.isWriteAccess()) {
    int[] idx = getSelectedIndices();
    if (idx.length == 0) {
      return;
    }
    for (int i = 0; i < idx.length; i++) {
      Rectangle r = getCellBounds(idx[i], idx[i]);
      repaint(r.x, r.y, r.width, r.height);
    }
  } else {
    new GuardedActions(3, null);
  }
}

相关文章