Examples of IEntityLock


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

Examples of org.jasig.portal.concurrency.IEntityLock

    boolean valid = false;
    IEntityLockService service = getService();

    msg = "Attempting to renew an old lock";
    print(msg);
    IEntityLock badLock = testLocks[2];
    msg = "Checking if lock was renewed.";
    print(msg);
    try { service.renew(badLock); } catch (Exception ex) {print("Caught Exception: " + ex.getMessage()); }
    assertTrue(msg, ! service.isValid(badLock));

    msg = "Attempting to renew a valid lock";
    print(msg);
    IEntityLock goodLock = testLocks[0];
    msg = "Checking if lock was renewed.";
    print(msg);
    try { service.renew(goodLock); } catch (Exception ex) {print("Caught Exception: " + ex.getMessage()); }
    assertTrue(msg, service.isValid(goodLock));
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

    String msg = null;
    boolean valid = false;

    print("Creating new lock");
    IEntityLockService service = getService();
    IEntityLock newLock = service.newLock(GROUP_CLASS, testKeys[3], IEntityLockService.WRITE_LOCK, testIds[0]);
    msg = "Testing if new lock is valid";
    valid = getService().existsInStore(newLock);
    print(msg);
    assertTrue(msg, valid);
View Full Code Here

Examples of org.jasig.portal.concurrency.IEntityLock

    java.util.Date newExpiration = new java.util.Date(now + fiveMinutes);
    int newType = IEntityLockService.WRITE_LOCK;

    // Copy testLocks[1] to lock1.
    IEntityLock lock1 = new EntityLockImpl
        (testLocks[1].getEntityType(), testLocks[1].getEntityKey(),
         testLocks[1].getLockType(), testLocks[1].getExpirationTime(), testLocks[1].getLockOwner());

    // Update testLocks[1].
    getLockStore().update(testLocks[1], newExpiration, new Integer(newType));
    ((EntityLockImpl)testLocks[1]).setExpirationTime(newExpiration);
    ((EntityLockImpl)testLocks[1]).setLockType(newType);

    msg = "Check if the old version (lock1) still exists in store.";
    print(msg);
    assertTrue(msg, ! getService().existsInStore(lock1) );

    msg = "Check if new version exists in store.";
    print(msg);
    IEntityLock lock2 = new EntityLockImpl
        (lock1.getEntityType(), lock1.getEntityKey(), newType, newExpiration, lock1.getLockOwner());
    assertTrue( msg, getService().existsInStore(lock2) );

    print("Update only expiration on (updated) lock.");
    newExpiration = new java.util.Date(now + tenMinutes);
    getLockStore().update(lock2, newExpiration, null);
    ((EntityLockImpl)lock2).setExpirationTime(newExpiration);

    msg = "Check if un-updated lock still exists in store.";
    print(msg);
    assertTrue( msg, ! getService().existsInStore(testLocks[1]) );

    msg = "Check if the doubly-updated lock exists in store.";
    print(msg);
    IEntityLock lock3 = new EntityLockImpl
        (lock2.getEntityType(), lock2.getEntityKey(), lock2.getLockType(), newExpiration, lock2.getLockOwner());
    assertTrue( msg, getService().existsInStore(lock3) );

    testLocks[0] = lock3;
}
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
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.