Package com.orientechnologies.common.concur.lock

Examples of com.orientechnologies.common.concur.lock.OLockException


    final String dbPooledName = iDatabase instanceof ODatabaseComplex ? ((ODatabaseComplex<?>) iDatabase).getUser().getName() + "@"
        + iDatabase.getName() : iDatabase.getName();

    final OResourcePool<String, DB> pool = pools.get(dbPooledName);
    if (pool == null)
      throw new OLockException("Can't release a database URL not acquired before. URL: " + iDatabase.getName());

    pool.returnResource(iDatabase);
  }
View Full Code Here


  public V getResource(K iKey, final long iMaxWaitMillis, String... iAdditionalArgs) throws OLockException {

    // First, get permission to take or create a resource
    try {
      if (!sem.tryAcquire(iMaxWaitMillis, TimeUnit.MILLISECONDS))
        throw new OLockException("Can't acquire lock on requested resource: " + iKey);
    } catch (InterruptedException e) {
      throw new OLockException("Can't acquire lock on requested resource: " + iKey, e);
    }

    // Then, actually take one if available...
    V res = resources.poll();
    if (res != null) {
      listener.reuseResource(iKey, res);
      return res;
    }

    // ...or create one if none available
    try {
      res = listener.createNewResource(iKey, iAdditionalArgs);
      return res;
    } catch (Exception e) {
      // Don't hog the permit if we failed to create a resource!
      sem.release();
      throw new OLockException("Error on creation of the new resource in the pool", e);
    }
  }
View Full Code Here

        }
      }
    }

    if (fileLock == null)
      throw new OLockException(
          "File '"
              + osFile.getPath()
              + "' is locked by another process, maybe the database is in use by another process. Use the remote mode with a OrientDB server to allow multiple access to the same database.");
  }
View Full Code Here

  @Override
  public OTransaction lockRecord(final OIdentifiable iRecord, final OStorage.LOCKING_STRATEGY iLockingStrategy) {
    final OStorage stg = database.getStorage();
    if (!(stg.getUnderlying() instanceof OStorageEmbedded))
      throw new OLockException("Cannot lock record across remote connections");

    final ORID rid = iRecord.getIdentity();
    // if (locks.containsKey(rid))
    // throw new IllegalStateException("Record " + rid + " is already locked");
View Full Code Here

  @Override
  public OTransaction unlockRecord(final OIdentifiable iRecord) {
    final OStorage stg = database.getStorage();
    if (!(stg.getUnderlying() instanceof OStorageEmbedded))
      throw new OLockException("Cannot lock record across remote connections");

    final ORID rid = iRecord.getIdentity();

    final OStorage.LOCKING_STRATEGY lock = locks.remove(rid);

    if (lock == null)
      throw new OLockException("Cannot unlock a never acquired lock");
    else if (lock == OStorage.LOCKING_STRATEGY.KEEP_EXCLUSIVE_LOCK)
      ((OStorageEmbedded) stg.getUnderlying()).releaseWriteLock(rid);
    else
      ((OStorageEmbedded) stg.getUnderlying()).releaseReadLock(rid);
View Full Code Here

    lock();
    try {

      final OReentrantResourcePool<String, DB> pool = pools.get(dbPooledName);
      if (pool == null)
        throw new OLockException("Cannot release a database URL not acquired before. URL: " + iDatabase.getName());

      if (pool.returnResource(iDatabase))
        this.notifyEvictor(dbPooledName, iDatabase);

    } finally {
View Full Code Here

    synchronized (iResource) {
      try {
        iResource.wait(iTimeout);
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new OLockException("Thread interrupted while waiting for resource '" + iResource + "'");
      }
    }

    Object[] value = queue.remove(iResource);
View Full Code Here

  public V getResource(K key, final long maxWaitMillis, Object... additionalArgs) throws OLockException {
    // First, get permission to take or create a resource
    try {
      if (!sem.tryAcquire(maxWaitMillis, TimeUnit.MILLISECONDS))
        throw new OLockException("No more resources available in pool. Requested resource: " + key);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new OInterruptedException(e);
    }

    V res;
    do {
      // POP A RESOURCE
      res = resources.poll();
      if (res != null) {
        // TRY TO REUSE IT
        if (listener.reuseResource(key, additionalArgs, res)) {
          // OK: REUSE IT
          break;
        } else
          res = null;

        // UNABLE TO REUSE IT: THE RESOURE WILL BE DISCARDED AND TRY WITH THE NEXT ONE, IF ANY
      }
    } while (!resources.isEmpty());

    // NO AVAILABLE RESOURCES: CREATE A NEW ONE
    try {
      if (res == null) {
        res = listener.createNewResource(key, additionalArgs);
        created++;
      }

      return res;
    } catch (RuntimeException e) {
      sem.release();
      // PROPAGATE IT
      throw e;
    } catch (Exception e) {
      sem.release();

      throw new OLockException("Error on creation of the new resource in the pool", e);
    }
  }
View Full Code Here

            } catch (InterruptedException e2) {
              Thread.currentThread().interrupt();
            }
          }

          throw new OLockException("Thread interrupted while waiting for resource of class '" + getClass() + "' with timeout="
              + timeout);
        }
        throwTimeoutException(lock.writeLock());
      } else {
        lock.writeLock().lock();
View Full Code Here

              }
            } catch (InterruptedException e2) {
              Thread.currentThread().interrupt();
            }
          }
          throw new OLockException("Thread interrupted while waiting for resource of class '" + getClass() + "' with timeout="
              + timeout);
        }

        throwTimeoutException(lock.readLock());
      } else
View Full Code Here

TOP

Related Classes of com.orientechnologies.common.concur.lock.OLockException

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.