Examples of IEntityLock


Examples of org.jasig.portal.concurrency.IEntityLock

throws GroupsException
{
    Class groupType = org.jasig.portal.EntityTypes.GROUP_ENTITY_TYPE;
    try
    {
        IEntityLock lock =  ( secs == 0 )
            ? EntityLockService.instance().newWriteLock(groupType, key, owner)
            : EntityLockService.instance().newWriteLock(groupType, key, owner, secs);

        ILockableEntityGroup group = groupFactory.findLockable(key);
        if ( group == null )
           { lock.release(); }
        else
            { group.setLock(lock); }

        return group;
    }
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

throws GroupsException
{
    Iterator itr;
    IEntityGroup containingGroup = null;
    ILockableEntityGroup lockableGroup = null;
    IEntityLock lock = null;
    List lockableGroups = new ArrayList();
    try
    {
        String lockOwner = group.getLock().getLockOwner();
        for ( itr=group.getContainingGroups(); itr.hasNext(); )
        {
            containingGroup = (IEntityGroup) itr.next();
            lockableGroup=
                GroupService.findLockableGroup(containingGroup.getKey(), lockOwner);
                if ( lockableGroup != null )
                     { lockableGroups.add(lockableGroup); }
        }
        for ( itr = lockableGroups.iterator(); itr.hasNext(); )
        {
            lockableGroup = (ILockableEntityGroup) itr.next();
            lockableGroup.removeMember(group);
            lockableGroup.updateMembers();
        }
    }
    catch (GroupsException ge)
        { throw new GroupsException("Could not remove deleted group " + group.getKey() +
                " from parent", ge); }
    finally
    {
        for ( itr = lockableGroups.iterator(); itr.hasNext(); )
        {
            lock = ((ILockableEntityGroup) itr.next()).getLock();
            try
            {
                if ( lock.isValid() )
                    { lock.release(); }
            }
            catch (LockingException le)
            {
                log.error(
                    "ReferenceIndividualGroupService.removeDeletedGroupFromContainingGroups(): " +
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

    throwExceptionIfNotInternallyManaged();

    Class groupType = org.jasig.portal.EntityTypes.GROUP_ENTITY_TYPE;
    try {
        IEntityLock lock =
            (secs == 0)
                ? EntityLockService.instance().newWriteLock(groupType, key, owner)
                : EntityLockService.instance().newWriteLock(groupType, key, owner, secs);

        ILockableEntityGroup group = groupFactory.findLockable(key);
        if (group == null) {
            lock.release();
        } else {
            group.setLock(lock);
            group.setLocalGroupService(this);
        }
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

    if ( obj == this )
        return true;
    if ( ! ( obj instanceof EntityLockImpl))
        return false;

    IEntityLock candidate = (IEntityLock) obj;
    return this.getEntityType().equals(candidate.getEntityType()) &&
           this.getEntityKey().equals(candidate.getEntityKey()) &&
           this.getLockOwner().equals(candidate.getLockOwner()) &&
           this.getLockType() == candidate.getLockType() &&
           this.getExpirationTime().equals(candidate.getExpirationTime());
}
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

public IEntityLock newLock(Class entityType, String entityKey, int lockType, String owner, int durationSecs)
throws LockingException
{
    int expirationSecs = durationSecs;
    Date expires = getNewExpiration(expirationSecs);
    IEntityLock newLock = new EntityLockImpl(entityType, entityKey, lockType, expires, owner, this);

    // retrieve potentially conflicting locks:
    IEntityLock[] locks = retrieveLocks(entityType, entityKey, null);

    if ( lockType == WRITE_LOCK )
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

    Map cache = null;
    Collection caches = null;
    Iterator cacheIterator = null;
    Iterator cacheKeyIterator = null;
    Iterator keyIterator = null;
    IEntityLock lock = null;

    if ( entityType == null )
    {
        caches = getLockCache().values();
    }
    else
    {
        caches = new ArrayList(1);
        caches.add(getLockCache(entityType));
    }

    cacheIterator = caches.iterator();
    while ( cacheIterator.hasNext() )
    {
        cache = (Map) cacheIterator.next();
        cacheKeyIterator = cache.keySet().iterator();
        List keys = new ArrayList();

        // Synchronize on the cache only while collecting its keys.  There is some
        // exposure here.
        synchronized (cache) {
        while ( cacheKeyIterator.hasNext() )
            { keys.add(cacheKeyIterator.next()); }
        }

        keyIterator = keys.iterator();
        while ( keyIterator.hasNext() )
        {
            lock = getLockFromCache(keyIterator.next(), cache);
            if ( ( lock != null ) &&
                 ( (entityKey == null|| (entityKey.equals(lock.getEntityKey())) ) &&
                 ( (lockType == null)   || (lockType.intValue() == lock.getLockType()) ) &&
                 ( (lockOwner == null|| (lockOwner.equals(lock.getLockOwner())) ) &&
                 ( (expiration == null) || (expiration.equals(lock.getExpirationTime())) )
               )
                  { locks.add(lock); }
        }
    }
    return ((IEntityLock[])locks.toArray(new IEntityLock[locks.size()]));
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

* @param lock
* @return IEntityLock
*/
public IEntityLock find(IEntityLock lock) throws LockingException
{
    IEntityLock foundLock = null;
    Map m = getLockCache(lock.getEntityType());
    foundLock = getLockFromCache(getCacheKey(lock), m);

    if ( foundLock != null )
    {
        if ( lock.getLockType() != foundLock.getLockType() ||
           ! lock.getExpirationTime().equals(foundLock.getExpirationTime()) )
                { foundLock = null; }
    }

    return foundLock;
}
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

/**
*/
public void testExistsInStore() throws Exception
{
        String msg = null;
        IEntityLock lock = testLocks[4];
        msg = "Checking if " + lock + " exists in database.";
        print(msg);
        boolean exists = getService().existsInStore(lock);
        assertTrue(msg, exists);

View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

*/
public void testService() throws Exception
{

    String msg = null;
    IEntityLock readLock1, readLock2, writeLock = null;

    String key = System.currentTimeMillis() + "";

    print("Creating first read lock.");
    readLock1 = EntityLockService.instance().newReadLock(IPERSON_CLASS, key, testIds[0]);

    print("Creating second read lock (for same entity).");
    readLock2 = EntityLockService.instance().newReadLock(IPERSON_CLASS, key, testIds[0]);

    msg = "Attempting to create a write lock for the entity: should fail.";
    print(msg);
    try
        { writeLock = EntityLockService.instance().newWriteLock(IPERSON_CLASS, key, testIds[2]); }
    catch (LockingException le)
        { System.out.println("Caught Exception: " + le.getMessage()); }

    assertNull(msg, writeLock);

    msg = "Releasing read locks: lock should be invalid.";
    print(msg);
    readLock1.release();
    assertTrue( msg, ! readLock1.isValid() );
    readLock2.release();
    assertTrue( msg, ! readLock2.isValid() );

    msg = "Attempting to create a write lock for the entity: should succeed.";
    print(msg);
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

    int readSecs = 30;
    int writeSecs = 45;

    // Create a READ lock on Group testKeys[3], owned by testIds[0]:
    print("Creating new READ lock");
    IEntityLock lock = service.newLock(GROUP_CLASS, testKeys[3], IEntityLockService.READ_LOCK, testIds[0], readSecs);
    msg = "Testing if new lock is valid";
    valid = service.isValid(lock);
    print(msg);
    assertTrue(msg, valid);

    // Convert the READ lock to a WRITE lock:
    print("Converting READ lock to WRITE");
    service.convert(lock, IEntityLockService.WRITE_LOCK, writeSecs);
    msg = "Testing if converted lock is still valid";
    valid = service.isValid(lock);
    print(msg);
    assertTrue(msg, valid);

    // Convert the WRITE lock back to a READ lock:
    print("Converting WRITE lock to READ");
    service.convert(lock, IEntityLockService.READ_LOCK, readSecs);
    msg = "Testing if converted lock is still valid";
    valid = service.isValid(lock);
    print(msg);
    assertTrue(msg, valid);

    // Now try to create a WRITE lock on the same entity for a different owner.
    IEntityLock duplicateLock = null;
    msg = "Attempting to create a duplicate lock; should be null";
    print(msg);

    try { duplicateLock = service.newLock(GROUP_CLASS, testKeys[3], IEntityLockService.WRITE_LOCK, testIds[1]); }
    catch (LockingException le) {print("Caught exception: " + le.getMessage()); }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.