コード例 #1
0
  /**
   * Refresh locks held by the authorization <code>authID</code>.
   *
   * <p>(remember that the lock may have expired)
   *
   * @param authID Authorization identifing Lock to refresh
   * @param transaction Transaction with authorization for lockID
   * @return <code>true</code> if lock was found and refreshed
   * @throws IOException If transaction not authorized to refresh authID
   * @throws IllegalArgumentException If authID or transaction not provided
   */
  public synchronized boolean refresh(String authID, Transaction transaction) throws IOException {
    if (authID == null) {
      throw new IllegalArgumentException("lockID required");
    }

    if ((transaction == null) || (transaction == Transaction.AUTO_COMMIT)) {
      throw new IllegalArgumentException(
          "Tansaction required (with authorization for " + authID + ")");
    }

    Lock lock;
    boolean refresh = false;

    for (Iterator i = allLocks().iterator(); i.hasNext(); ) {
      lock = (Lock) i.next();

      if (lock.isExpired()) {
        i.remove();
      } else if (lock.isMatch(authID)) {
        if (lock.isAuthorized(transaction)) {
          lock.refresh();
          refresh = true;
        } else {
          throw new IOException("Not authorized to refresh " + lock);
        }
      }
    }

    return refresh;
  }
コード例 #2
0
  /**
   * Lock for typeName & featureID if it exists.
   *
   * <p>This method will not return expired locks.
   *
   * @param typeName
   * @param featureID
   * @return Lock if exists, or null
   */
  protected Lock getLock(String typeName, String featureID) {
    Map locks = locks(typeName);
    // LOGGER.info("checking for lock " + typeName + ", " + featureID
    //    + " in locks " + locks);

    synchronized (locks) {
      if (locks.containsKey(featureID)) {
        Lock lock = (Lock) locks.get(featureID);

        if (lock.isExpired()) {
          locks.remove(featureID);
          // LOGGER.info("returning null");

          return null;
        } else {
          // LOGGER.info("returing " + lock);

          return lock;
        }
      } else {
        // LOGGER.info("locks did not contain key, returning null");

        // not found
        return null;
      }
    }
  }
コード例 #3
0
  /**
   * Release locks held by the authorization <code>authID</code>.
   *
   * <p>(remember that the lock may have expired)
   *
   * @param authID Authorization identifing Lock to release
   * @param transaction Transaction with authorization for lockID
   * @return <code>true</code> if lock was found and released
   * @throws IOException If transaction not authorized to release authID
   * @throws IllegalArgumentException If authID or transaction not provided
   */
  public boolean release(String authID, Transaction transaction) throws IOException {
    // LOGGER.info("release called on lock: " + authID + ", trans: "
    //  + transaction);

    if (authID == null) {
      throw new IllegalArgumentException("lockID required");
    }

    if ((transaction == null) || (transaction == Transaction.AUTO_COMMIT)) {
      throw new IllegalArgumentException(
          "Tansaction required (with authorization for " + authID + ")");
    }

    Lock lock;
    boolean release = false;

    // This could be done more efficiently, and perhaps cleaner,
    // but these maps within a map are just nasty.  The previous way of
    // calling iterator.remove() didn't actually remove anything, as it
    // was only iterating through the values of a map, which I believe
    // java just copies, so it's immutable.  Or perhaps we just moved
    // through too many iterator layers...
    for (Iterator i = lockTables.values().iterator(); i.hasNext(); ) {
      Map fidMap = (Map) i.next();
      Set unLockedFids = new HashSet();

      for (Iterator j = fidMap.keySet().iterator(); j.hasNext(); ) {
        String fid = (String) j.next();
        lock = (Lock) fidMap.get(fid);
        // LOGGER.info("checking lock " + lock + ", is match "
        //    + lock.isMatch(authID));

        if (lock.isExpired()) {
          unLockedFids.add(fid);

          // fidMap.remove(fid); concurrent modification error.
        } else if (lock.isMatch(authID)) {
          // LOGGER.info("matches, is authorized: "
          //    + lock.isAuthorized(transaction));

          if (lock.isAuthorized(transaction)) {
            unLockedFids.add(fid);

            // fidMap.remove(fid);
            release = true;
          } else {
            throw new IOException("Not authorized to release " + lock);
          }
        }
      }

      for (Iterator k = unLockedFids.iterator(); k.hasNext(); ) {
        fidMap.remove(k.next());
      }
    }

    return release;
  }
コード例 #4
0
  /**
   * Implment lockExists.
   *
   * <p>Remeber lock may have expired.
   *
   * @param authID
   * @return true if lock exists for authID
   * @see org.geotools.data.LockingManager#lockExists(java.lang.String)
   */
  public boolean exists(String authID) {
    // LOGGER.info("checking existence of lock: " + authID + " in "
    //    + allLocks());

    if (authID == null) {
      return false;
    }

    Lock lock;

    for (Iterator i = allLocks().iterator(); i.hasNext(); ) {
      lock = (Lock) i.next();

      if (lock.isExpired()) {
        i.remove();
      } else if (lock.isMatch(authID)) {
        return true;
      }
    }

    return false;
  }