Package org.apache.slide.lock

Examples of org.apache.slide.lock.NodeLock


  }

  private NodeLock findMatchingNodeLock(boolean inherited)
      throws ObjectNotFoundException, LockTokenNotFoundException,
      ServiceAccessException {
    NodeLock nodeLock = null;
    Enumeration locks = lock.enumerateLocks(slideToken, resourcePath,
        inherited);
    while (nodeLock == null && locks.hasMoreElements()) {
      NodeLock nl = (NodeLock) locks.nextElement();
      if (nl.getLockId().equals(lockId)) {
        nodeLock = nl;
      }
    }
    return nodeLock;
  }
View Full Code Here


          .getNamespaceConfig();
                    toLockSubject = getToLockSubject();
                    if (lockDate == null)
                        lockDate = new Date((new Date()).getTime()
                                + ((long) lockDuration * 1000L));
          NodeLock lockToken = new NodeLock(toLockSubject.getUri(),((SubjectNode)security.getPrincipal(slideToken)).getUri(),
              namespaceConfig.getCreateObjectAction().getUri(), lockDate,
              inheritance, NodeLock.LOCAL, lockInfo_lockOwner);
                    token.setTransactionTimeout(lockDuration * 1000);
          Transaction transaction = token.getTransactionManager().suspend();
                    //String txId = lockToken.getLockId();
                    String fullTxId = "<" + S_LOCK_TOKEN + lockToken.getLockId() + ">";
                    ExternalTransactionContext.registerContext(fullTxId, transaction);
                    slideToken.setExternalTx();
                    resp.setHeader("Lock-Token", fullTxId);
                    showLockDiscoveryInfo(lockToken);
        } catch (Exception e) {
          int statusCode = getErrorCode(e);
          sendError(statusCode, e);
          throw new WebdavException(statusCode);
        }
      } else if (lockInfo_lockType.equals(E_WRITE)) {
        try {
                   
                if (!checkIfHeaders()) {
                    return;
                }
                     
          NamespaceConfig namespaceConfig = token
              .getNamespaceConfig();
                    toLockSubject = getToLockSubject();
          NodeLock lockToken = null;

          inheritance = (depth != 0);
          boolean exclusive = !(lockInfo_lockScope.equals(E_SHARED));

          if (lockDate == null)
            lockDate = new Date((new Date()).getTime()
                + ((long) lockDuration * 1000L));

          lockToken = new NodeLock(toLockSubject,
              (SubjectNode) security.getPrincipal(slideToken),
              namespaceConfig.getCreateObjectAction(), lockDate,
              inheritance, exclusive, lockInfo_lockOwner);
          lock.lock(slideToken, lockToken);

          // Set the lock-token header
          // [RFC 2518, 9.5] " The Lock-Token response header is used
          // with the LOCK method to indicate the lock token created
          // as
          // a result of a successful LOCK request to create a new
          // lock."
          resp.setHeader("Lock-Token", "<" + S_LOCK_TOKEN
              + lockToken.getLockId() + ">");

          resp.setStatus(WebdavStatus.SC_OK);

          // The lock token on which the DAV module will have the info

          showLockDiscoveryInfo(lockToken);
        } catch (ObjectIsAlreadyLockedException e) {
          if (inheritance
              && generateMultiStatusResponse(isCollection, e,
                  requestUri)) {
            // error is on the resource which we attempted to lock
            String errorMessage = generateErrorMessage(e);
            // Write it on the servlet writer
            resp.setContentType(TEXT_XML_UTF_8);
            resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
            try {
              resp.getWriter().write(errorMessage);
            } catch (IOException ex) {
              // Critical error ... Servlet container is dead or
              // something
              int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
              sendError(statusCode, e);
              throw new WebdavException(statusCode);
            }
          } else {
            // Returning 207 on non-collection requests is generally
            // considered bad. So let's not do it, since this way
            // makes clients generally behave better.
            resp.setStatus(WebdavStatus.SC_LOCKED);
          }
          //
          // make sure the transaction is aborted
          // throw any WebDAV exception to indicate the transaction
          // wants to be aborted
          //
          throw new WebdavException(WebdavStatus.SC_ACCEPTED, false);
        } catch (Exception e) {
          int statusCode = getErrorCode(e);
          sendError(statusCode, e);
          throw new WebdavException(statusCode);
        }
      }
      break;

    case LOCK_REFRESH:

      try {

        Enumeration lockTokens = lock.enumerateLocks(slideToken,
            lockInfo_lockSubject, false);

        NodeLock currentLockToken = null;
        Date newExpirationDate = new Date((new Date()).getTime()
            + ((long) lockDuration * 1000L));
        while (lockTokens.hasMoreElements()) {
          currentLockToken = (NodeLock) lockTokens.nextElement();
          lock.renew(slideToken, currentLockToken, newExpirationDate);
View Full Code Here

     */
    public SourceLock[] getSourceLocks() throws SourceException {
        try {
            List result = new ArrayList();

            NodeLock lock;
            Enumeration locks = m_lock.enumerateLocks(m_slideToken,m_uri, false);
            while (locks.hasMoreElements()) {
                lock = (NodeLock) locks.nextElement();
                result.add(new SourceLock(lock.getSubjectUri(),
                                          lock.getTypeUri(),
                                          lock.getExpirationDate(),
                                          lock.isInheritable(),
                                          lock.isExclusive()));
            }

            return (SourceLock[]) result.toArray(new SourceLock[result.size()]);
        } catch (SlideException se) {
            throw new SourceException("Could not retrieve locks", se);
View Full Code Here

       SlideToken slideToken = new SlideTokenImpl(new CredentialsToken(caller));
       Lock lock = nat.getLockHelper();
      
       try {
           nat.begin();
           lock.lock(slideToken,new NodeLock(uri,subject,type,expire,isExclusive,isInherit));
           nat.commit();
       }
       catch (Exception e) {
           try {
               nat.rollback();
View Full Code Here

            super.putLock(uri, lock);
        }
        else {
            try {
                ResourceId resourceId = obtainResourceId(uri);
                NodeLock lockClone = lock.cloneObject();
                lockClone.setObjectUri(resourceId.getUuri()); // switch to uuri
                resourceId.getStore().putLock(resourceId, lockClone);
            }
            catch (ObjectNotFoundException e) {
                throw new ServiceAccessException(this, e);
            }
View Full Code Here

            super.renewLock(uri, lock);
        }
        else {
            try {
                ResourceId resourceId = obtainResourceId(uri);
                NodeLock lockClone = lock.cloneObject();
                lockClone.setObjectUri(resourceId.getUuri()); // switch to uuri
                resourceId.getStore().renewLock(resourceId, lockClone);
            }
            catch (ObjectNotFoundException e) {
                throw new ServiceAccessException(this, e);
            }
View Full Code Here

            super.removeLock(uri, lock);
        }
        else {
            try {
                ResourceId resourceId = obtainResourceId(uri);
                NodeLock lockClone = lock.cloneObject();
                lockClone.setObjectUri(resourceId.getUuri()); // switch to uuri
                resourceId.getStore().removeLock(resourceId, lockClone);
            }
            catch (ObjectNotFoundException e) {
                throw new ServiceAccessException(this, e);
            }
View Full Code Here

            super.killLock(uri, lock);
        }
        else {
            try {
                ResourceId resourceId = obtainResourceId(uri);
                NodeLock lockClone = lock.cloneObject();
                lockClone.setObjectUri(resourceId.getUuri()); // switch to uuri
                resourceId.getStore().killLock(resourceId, lockClone);
            }
            catch (ObjectNotFoundException e) {
                throw new ServiceAccessException(this, e);
            }
View Full Code Here

            try {
                ResourceId resourceId = obtainResourceId(uri);
                Enumeration locks = resourceId.getStore().enumerateLocks(resourceId);
                Vector result = new Vector();
                while (locks.hasMoreElements()) {
                    NodeLock l = ((NodeLock)locks.nextElement()).cloneObject();
                    l.setObjectUri(uri.toString()); // switch to uri
                    result.add(l);
                }
                return result.elements();
            }
            catch (ObjectNotFoundException e) {
View Full Code Here

            Vector locksVector = null;
            if (value == null) {
                locksVector = new Vector();
                Enumeration lockList = lockStore.enumerateLocks(uri);
                while (lockList.hasMoreElements()) {
                    NodeLock tempLock = (NodeLock) lockList.nextElement();
                    tempLock.validate(uri.toString());
                    locksVector.addElement(tempLock);
                }
                locksCache.put(uri.toString(), locksVector);
            } else {
                locksVector = (Vector) value;
View Full Code Here

TOP

Related Classes of org.apache.slide.lock.NodeLock

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.