Package info.aduna.concurrent.locks

Examples of info.aduna.concurrent.locks.Lock


    throws StoreException
  {
    if (isInitialized()) {
      logger.debug("Shutting down NativeStore...");

      Lock txnLock = getTransactionLock();
      try {
        Lock writeLock = getWriteLock();
        try {
          tripleStore.close();
          valueStore.close();
          namespaceStore.close();

          initialized = false;

          logger.debug("NativeStore shut down");
        }
        catch (IOException e) {
          throw new StoreException(e);
        }
        finally {
          writeLock.release();
        }
      }
      finally {
        txnLock.release();
        dirLock.release();
View Full Code Here


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

      try {
        cancelSyncTimer();
        sync();

        statements.clear();
        bf.clear();
        uf.clear();
        lf.clear();
        dataFile = null;
        syncFile = null;
        initialized = false;
      }
      finally {
        stLock.release();
        if (dirLock != null) {
          dirLock.release();
        }
      }
    }
View Full Code Here

          @Override
          public void run() {
            try {
              // Acquire read lock to guarantee that the statement list
              // doesn't change while writing
              Lock stLock = getStatementsReadLock();
              try {
                sync();
              }
              finally {
                stLock.release();
              }
            }
            catch (StoreException e) {
              logger.warn("Unable to sync on timer", e);
            }
View Full Code Here

    HashSet<MemValue> processedSubjects = new HashSet<MemValue>();
    HashSet<MemValue> processedPredicates = new HashSet<MemValue>();
    HashSet<MemValue> processedObjects = new HashSet<MemValue>();
    HashSet<MemValue> processedContexts = new HashSet<MemValue>();

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

        if (st.getTillSnapshot() <= currentSnapshot) {
          MemResource subj = st.getSubject();
          if (processedSubjects.add(subj)) {
            subj.cleanSnapshotsFromSubjectStatements(currentSnapshot);
          }

          MemURI pred = st.getPredicate();
          if (processedPredicates.add(pred)) {
            pred.cleanSnapshotsFromPredicateStatements(currentSnapshot);
          }

          MemValue obj = st.getObject();
          if (processedObjects.add(obj)) {
            obj.cleanSnapshotsFromObjectStatements(currentSnapshot);
          }

          MemResource context = st.getContext();
          if (context != null && processedContexts.add(context)) {
            context.cleanSnapshotsFromContextStatements(currentSnapshot);
          }

          // stale statement
          statements.remove(i);
        }
        else {
          // Reset snapshot
          st.setSinceSnapshot(1);
        }
      }

      currentSnapshot = 1;
    }
    finally {
      stLock.release();
    }

    // long endTime = System.currentTimeMillis();
    // System.out.println("cleanSnapshots() took " + (endTime - startTime) +
    // " ms");
View Full Code Here

    }
    manager.flush();
    conn.commit();
    conn.setAutoCommit(true);
    releaseLock();
    Lock writeLock = vf.tryIdWriteLock();
    try {
      vf.flush();
      statements.committed(writeLock != null);
    }
    finally {
      if (writeLock != null) {
        writeLock.release();
      }
    }
  }
View Full Code Here

    logger.trace("Incoming query model:\n{}", query);

    // Clone the tuple expression to allow for more aggressive optimizations
    query = query.clone();

    Lock readLock = nativeStore.getReadLock();

    try {
      replaceValues(query);

      NativeTripleSource tripleSource = new NativeTripleSource(nativeStore, includeInferred,
          !isAutoCommit());
      EvaluationStrategyImpl strategy = new EvaluationStrategyImpl(tripleSource, query);

      QueryOptimizerList optimizerList = new QueryOptimizerList();
      optimizerList.add(new BindingAssigner());
      optimizerList.add(new ConstantOptimizer(strategy));
      optimizerList.add(new CompareOptimizer());
      optimizerList.add(new ConjunctiveConstraintSplitter());
      optimizerList.add(new DisjunctiveConstraintOptimizer());
      optimizerList.add(new SameTermFilterOptimizer());
      optimizerList.add(new QueryModelPruner());
      optimizerList.add(new QueryJoinOptimizer(new NativeEvaluationStatistics(nativeStore)));
      optimizerList.add(new FilterOptimizer());

      optimizerList.optimize(query, bindings);
      logger.trace("Optimized query model:\n{}", query);

      Cursor<BindingSet> iter;
      iter = strategy.evaluate(query, EmptyBindingSet.getInstance());
      iter = new LockingCursor<BindingSet>(readLock, iter);
      return iter;
    }
    catch (EvaluationException e) {
      readLock.release();
      throw e;
    }
    catch (RuntimeException e) {
      readLock.release();
      throw e;
    }
  }
View Full Code Here

  public Cursor<? extends Resource> getContextIDs()
    throws StoreException
  {
    // Which resources are used as context identifiers is not stored
    // separately. Iterate over all statements and extract their context.
    Lock readLock = nativeStore.getReadLock();
    try {
      Cursor<? extends Resource> contextIter;
      contextIter = nativeStore.getContextIDs(!isAutoCommit());
      // releasing the read lock when the iterator is closed
      contextIter = new LockingCursor<Resource>(readLock, contextIter);

      return contextIter;
    }
    catch (IOException e) {
      readLock.release();
      throw new StoreException(e);
    }
    catch (RuntimeException e) {
      readLock.release();
      throw e;
    }
  }
View Full Code Here

  public Cursor<? extends Statement> getStatements(Resource subj, URI pred, Value obj,
      boolean includeInferred, Resource... contexts)
    throws StoreException
  {
    Lock readLock = nativeStore.getReadLock();
    try {
      Cursor<? extends Statement> iter;
      iter = nativeStore.createStatementCursor(subj, pred, obj, includeInferred, !isAutoCommit(), contexts);
      iter = new LockingCursor<Statement>(readLock, iter);

      return iter;
    }
    catch (IOException e) {
      readLock.release();
      throw new StoreException("Unable to get statements", e);
    }
    catch (RuntimeException e) {
      readLock.release();
      throw e;
    }
  }
View Full Code Here

      return false;
    }
  }

  public Lock tryLock() {
    Lock lock = null;
    try {
      Connection con = getConnection();
      try {
        Statement st = con.createStatement();
        try {
          st.execute(CREATE_LOCKED);
          lock = createLock();
          st.execute(INSERT + getProcessName() + "')");
          return lock;
        }
        finally {
          st.close();
        }
      }
      finally {
        con.close();
      }
    }
    catch (SQLException exc) {
      logger.warn(exc.toString(), exc);
      if (lock != null) {
        lock.release();
      }
      return null;
    }
  }
View Full Code Here

  }

  public Lock lockOrFail()
    throws SailLockedException
  {
    Lock lock = tryLock();
    if (lock != null) {
      return lock;
    }

    String requestedBy = getProcessName();
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.