Package info.aduna.concurrent.locks

Examples of info.aduna.concurrent.locks.Lock


  private String getProcessName() {
    return ManagementFactory.getRuntimeMXBean().getName();
  }

  private Lock createLock() {
    return new Lock() {

      private boolean active = true;

      public boolean isActive() {
        return active;
View Full Code Here


    if (!lockDir.mkdir()) {
      return null;
    }

    Lock lock = null;

    try {
      File infoFile = new File(lockDir, INFO_FILE_NAME);
      File lockedFile = new File(lockDir, LOCK_FILE_NAME);

      RandomAccessFile raf = new RandomAccessFile(lockedFile, "rw");
      try {
        FileLock fileLock = raf.getChannel().lock();
        lock = createLock(raf, fileLock);
        sign(infoFile);
      }
      catch (IOException e) {
        if (lock != null) {
          // Also closes raf
          lock.release();
        }
        else {
          raf.close();
        }
        throw e;
View Full Code Here

   *         if the directory is already locked.
   */
  public Lock lockOrFail()
    throws SailLockedException
  {
    Lock lock = tryLock();

    if (lock != null) {
      return lock;
    }

View Full Code Here

      return null;
    }
  }

  private Lock createLock(final RandomAccessFile raf, final FileLock fileLock) {
    return new Lock() {

      private boolean active = true;

      private Thread hook = new Thread(new Runnable() {
View Full Code Here

   */
  public void clear()
    throws IOException
  {
    try {
      Lock writeLock = lockManager.getWriteLock();
      try {
        dataStore.clear();

        valueCache.clear();
        valueIDCache.clear();
        namespaceCache.clear();
        namespaceIDCache.clear();

        initBNodeParams();

        setNewRevision();
      }
      finally {
        writeLock.release();
      }
    }
    catch (InterruptedException e) {
      IOException ioe = new IOException("Failed to acquire write lock");
      ioe.initCause(e);
View Full Code Here

  @Override
  protected void shutDownInternal()
    throws SailException
  {
    if (isInitialized()) {
      Lock stLock = getStatementsReadLock();

      try {
        cancelSyncTimer();
        sync();

        valueFactory = null;
        statements = null;
        dataFile = null;
        initialized = false;
      }
      finally {
        stLock.release();
      }
    }
  }
View Full Code Here

        syncTimerTask = new TimerTask() {

          @Override
          public void run() {
            try {
              Lock stLock = getStatementsReadLock();
              try {
                sync();
              }
              finally {
                stLock.release();
              }
            }
            catch (SailException e) {
              logger.warn("Unable to sync on timer", e);
            }
View Full Code Here

    if (statements == null) {
      // Store has been shut down
      return;
    }

    Lock stLock = statementListLockManager.getWriteLock();
    try {
      for (int i = statements.size() - 1; i >= 0; i--) {
        MemStatement st = statements.get(i);

        if (st.getTillSnapshot() <= currentSnapshot) {
          // stale statement
          st.removeFromComponentLists();
          statements.remove(i);
        }
        else {
          // Reset snapshot
          st.setSinceSnapshot(1);
        }
      }

      currentSnapshot = 1;
    }
    finally {
      stLock.release();
    }
  }
View Full Code Here

  public final void close()
    throws SailException
  {
    // obtain an exclusive lock so that any further operations on this
    // connection (including those from any concurrent threads) are blocked.
    Lock conLock = getExclusiveConnectionLock();

    try {
      if (isOpen) {
        try {
          while (true) {
            SailBaseIteration ci = null;

            synchronized (activeIterations) {
              if (activeIterations.isEmpty()) {
                break;
              }
              else {
                ci = activeIterations.remove(0);
              }
            }

            try {
              ci.forceClose();
            }
            catch (SailException e) {
              throw e;
            }
            catch (Exception e) {
              throw new SailException(e);
            }
          }

          assert activeIterations.isEmpty();

          if (txnActive) {
            logger.warn("Rolling back transaction due to connection close", new Throwable());
            try {
              // Use internal method to avoid deadlock: the public
              // rollback method will try to obtain a connection lock
              rollbackInternal();
            }
            finally {
              txnActive = false;
            }
          }

          closeInternal();
        }
        finally {
          isOpen = false;
          sailBase.connectionClosed(this);
        }
      }
    }
    finally {
      // Release the exclusive lock. Any threads waiting to obtain a
      // non-exclusive read lock will get one and then fail with an
      // IllegalStateException, because the connection is no longer open.
      conLock.release();
    }
  }
View Full Code Here

  public final CloseableIteration<? extends BindingSet, QueryEvaluationException> evaluate(
      TupleExpr tupleExpr, Dataset dataset, BindingSet bindings, boolean includeInferred)
    throws SailException
  {
    Lock conLock = getSharedConnectionLock();
    try {
      verifyIsOpen();
      return registerIteration(evaluateInternal(tupleExpr, dataset, bindings, includeInferred));
    }
    finally {
      conLock.release();
    }
  }
View Full Code Here

TOP

Related Classes of info.aduna.concurrent.locks.Lock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.