Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.LockNotGrantedException


                    // Don't wait if timeout is zero
                    if ( timeout == 0 ) {
                        if (log.isDebugEnabled()) {
                            log.debug ( "Timeout on " + this.toString() + " by " + tx );
                        }
                        throw new LockNotGrantedException( "persist.writeTimeout" + _oid + "/" + _id + " by " + tx );
                    }
                    if (log.isDebugEnabled()) {
                        log.debug ( "Waiting on " + this.toString() + " by " + tx );
                    }
                    // Detect possibility of dead-lock. Must remain in wait-on-lock
                    // position until lock is granted or exception thrown.

                    tx.setWaitOnLock( this );
                    detectDeadlock( tx, 10 );
                   
                    // Must wait for lock and then attempt to reacquire
                    _writeWaiting = new LinkedTx( tx, _writeWaiting );
                   
                    // Wait until notified or timeout elapses. Must detect
                    // when notified but object deleted (i.e. locks released)
                    // All waiting transactions are notified at once, but once
                    // notified a race condition starts to acquire new lock
                    long clock = System.currentTimeMillis();
                    try {
                        long waittime = endtime - System.currentTimeMillis();
                        wait( waittime<0? 0: waittime );
                    } catch ( InterruptedException except ) {
                        // If the thread is interrupted, come out with the proper message
                        throw new LockNotGrantedException( "persist.writeLockTimeout" );
                    }

                    if ( _deleted )
                        // object should not be deleted, as we got lock on it
                        throw new IllegalStateException("internal error: object deleted" + _oid + "/" + _id + " by " + tx);
View Full Code Here


                LinkedTx read;

                // Is the blocked transaction blocked by the transaction locking
                // this object? This is a deadlock.
                if ( waitOn._writeLock == waitingTx ) {
                    throw new LockNotGrantedException( Messages.message("persist.deadlock") );
                }
                read = waitOn._readLock;
                while ( read != null ) {
                    if ( read.tx == waitingTx )
                        throw new LockNotGrantedException( Messages.message ("persist.deadlock" ));
                    read = read.next;
                }
                waitOn.detectDeadlock( waitingTx, numOfRec - 1 );
            }
        } else {
            LinkedTx lock;

            lock = _readLock;
            while ( lock != null ) {
                // T1 trying to acquire lock on O1, which is locked by T2
                // T2 trying to acauire lock on O1, T1 is waiting on O1

                // lock is the blocking transaction. We are only interested in
                // a blocked transacrtion.
                waitOn = lock.tx.getWaitOnLock();
                if ( waitOn != null && lock.tx != waitingTx ) {
                    LinkedTx read;

                    if ( waitOn._writeLock == waitingTx ) {
                        throw new LockNotGrantedException( Messages.message ("persist.deadlock") );
                    }
                    read = waitOn._readLock;
                    while ( read != null ) {
                        if ( read.tx == waitingTx )
                            throw new LockNotGrantedException( Messages.message ("persist.deadlock") );
                        read = read.next;
                    }
                    waitOn.detectDeadlock( waitingTx, numOfRec - 1 );
                }
                lock = lock.next;
View Full Code Here

                    // other thread is loading or creating object and haven't finished
                    try {
                        _waitCount++;
                        wait();                       
                    } catch ( InterruptedException e ) {
                        throw new LockNotGrantedException("Thread interrupted acquiring lock!");
                    } finally {
                        _waitCount--;
                    }
                } else if ( _writeLock == tx ) {
                    //throw new IllegalStateException("Transaction: "+tx+" has already hold the write lock on "+_oid+
                    //        " Acquire shouldn't be called twice");
                    return;
                } else if ( _readLock == null && _writeLock == null && write ) {
                    // no transaction hold any lock,
                    _confirmWaiting = tx;
                    _confirmWaitingAction = ACTION_WRITE;
                    return;
                } else if ( _readLock == null && _writeLock == null && !write ) {
                    // no transaction hold any lock,
                    if ( _object == null ) {
                        _confirmWaiting = tx;
                        _confirmWaitingAction = ACTION_READ;
                        return;
                    } else {
                        _readLock = new LinkedTx( tx, null );
                        return;
                    }
                } else if ( _readLock != null && !write ) {
                    // already a transaction holding read lock, can acquire read lock
                    LinkedTx linked = _readLock;
                    while ( linked != null ) {
                        if ( linked.tx == tx )
                            throw new IllegalStateException("Transaction: "+tx+" has already hold the write lock on "+_oid+
                            " Acquire shouldn't be called twice");
                            //return;
                        linked = linked.next;
                    }
                  
                    // if not already in readLock
                    _readLock = new LinkedTx( tx, _readLock );
                    return;
                } else {
                    // other transaction holding writeLock, waits for write
                    // or, other transaction holding readLock, waiting for read
                    if ( timeout == 0 ) {
                        if ( TRACE )
                            System.out.println( "Timeout on " + this.toString() + " by " + tx );
                        throw new LockNotGrantedException( (write ? "persist.writeLockTimeout" :
                                                               "persist.readLockTimeout") + _oid + "/" + _id + " by " + tx );
                    }
                    if ( TRACE )
                        System.out.println( "Waiting on " + this.toString() + " by " + tx );
                    // Detect possibility of dead-lock. Must remain in wait-on-lock
                    // position until lock is granted or exception thrown.
                    tx.setWaitOnLock( this );
                    detectDeadlock( tx, 10 );
                   
                    // Must wait for lock and then attempt to reacquire
                    if ( write )
                        _writeWaiting = new LinkedTx( tx, _writeWaiting );
                    else
                        _readWaiting = new LinkedTx( tx, _readWaiting );
                   
                    // Wait until notified or timeout elapses. Must detect
                    // when notified but object deleted (i.e. locks released)
                    // All waiting transactions are notified at once, but once
                    // notified a race condition starts to acquire new lock
                    try {
                        long waittime = endtime - System.currentTimeMillis();
                        wait( waittime<0? 0: waittime );
                    } catch ( InterruptedException except ) {
                        // If the thread is interrupted, come out with the proper message
                        throw new LockNotGrantedException( write ? "persist.writeLockTimeout" :
                                                               "persist.readLockTimeout" + _oid + "/" + _id + " by " + tx );
                    }

                    if ( _deleted )
                        // If object has been deleted while waiting for lock, report deletion.
View Full Code Here

                    wait();
                    while ( _deleted ) {
                        wait();
                    }
                } catch ( InterruptedException e ) {
                    throw new LockNotGrantedException("Thread interrupted acquiring lock!");
                } finally {
                    _waitCount--;
                }
            } else if ( _readLock != null || _writeLock != null ) {
                throw new LockNotGrantedException("Lock already exist!");
            } else {
                _confirmWaiting = tx;
                _confirmWaitingAction = ACTION_CREATE;
                return;
            }
View Full Code Here

                        /*
                        if ( _deleted ) {
                            throw new ObjectDeletedWaitingForLockException("Object deleted!");
                        }*/
                    } catch ( InterruptedException e ) {
                        throw new LockNotGrantedException("Thread interrupted acquiring lock!");
                    } finally {
                        _waitCount--;
                    }
                } else if ( _writeLock == tx ) {
                    return;
                } else if ( _writeLock == null && _readLock == null ) {
                    // can get the lock now
                    _confirmWaiting = tx;
                    _confirmWaitingAction = ACTION_UPDATE;
                    return;
                } else {
                    if ( timeout == 0 ) {
                        if ( TRACE )
                            System.out.println( "Timeout on " + this.toString() + " by " + tx );
                        throw new LockNotGrantedException( "persist.writeLockTimeout" );
                    }
                    if ( TRACE )
                        System.out.println( "Waiting on " + this.toString() + " by " + tx );
                    // Detect possibility of dead-lock. Must remain in wait-on-lock
                    // position until lock is granted or exception thrown.
                    tx.setWaitOnLock( this );
                    detectDeadlock( tx, 10 );
                   
                    // Must wait for lock and then attempt to reacquire
                    _writeWaiting = new LinkedTx( tx, _writeWaiting );
                   
                    // Wait until notified or timeout elapses. Must detect
                    // when notified but object deleted (i.e. locks released)
                    // All waiting transactions are notified at once, but once
                    // notified a race condition starts to acquire new lock
                    long clock = System.currentTimeMillis();
                    try {
                        long waittime = endtime - System.currentTimeMillis();
                        wait( waittime<0? 0: waittime );
                    } catch ( InterruptedException except ) {
                        // If the thread is interrupted, come out with the proper message
                        throw new LockNotGrantedException( "persist.writeLockTimeout" + _oid + "/" + _id + " by " + tx );
                    }

                    if ( _deleted )
                        // If object has been deleted while waiting for lock, report deletion.
                        throw new ObjectDeletedWaitingForLockException("object deleted" + _oid + "/" + _id + " by " + tx);
View Full Code Here

                } else {
                    // Don't wait if timeout is zero
                    if ( timeout == 0 ) {
                        if ( TRACE )
                            System.out.println( "Timeout on " + this.toString() + " by " + tx );
                        throw new LockNotGrantedException( "persist.writeTimeout" + _oid + "/" + _id + " by " + tx );
                    }
                    if ( TRACE )
                        System.out.println( "Waiting on " + this.toString() + " by " + tx );
                    // Detect possibility of dead-lock. Must remain in wait-on-lock
                    // position until lock is granted or exception thrown.

                    tx.setWaitOnLock( this );
                    detectDeadlock( tx, 10 );
                   
                    // Must wait for lock and then attempt to reacquire
                    _writeWaiting = new LinkedTx( tx, _writeWaiting );
                   
                    // Wait until notified or timeout elapses. Must detect
                    // when notified but object deleted (i.e. locks released)
                    // All waiting transactions are notified at once, but once
                    // notified a race condition starts to acquire new lock
                    long clock = System.currentTimeMillis();
                    try {
                        long waittime = endtime - System.currentTimeMillis();
                        wait( waittime<0? 0: waittime );
                    } catch ( InterruptedException except ) {
                        // If the thread is interrupted, come out with the proper message
                        throw new LockNotGrantedException( "persist.writeLockTimeout" );
                    }

                    if ( _deleted )
                        // object should not be deleted, as we got lock on it
                        throw new IllegalStateException("internal error: object deleted" + _oid + "/" + _id + " by " + tx);
View Full Code Here

                LinkedTx read;

                // Is the blocked transaction blocked by the transaction locking
                // this object? This is a deadlock.
                if ( waitOn._writeLock == waitingTx ) {
                    throw new LockNotGrantedException( "persist.deadlock" );
                }
                read = waitOn._readLock;
                while ( read != null ) {
                    if ( read.tx == waitingTx )
                        throw new LockNotGrantedException( "persist.deadlock" );
                    read = read.next;
                }
                waitOn.detectDeadlock( waitingTx, numOfRec - 1 );
            }
        } else {
            LinkedTx lock;

            lock = _readLock;
            while ( lock != null ) {
                // T1 trying to acquire lock on O1, which is locked by T2
                // T2 trying to acauire lock on O1, T1 is waiting on O1

                // lock is the blocking transaction. We are only interested in
                // a blocked transacrtion.
                waitOn = lock.tx.getWaitOnLock();
                if ( waitOn != null && lock.tx != waitingTx ) {
                    LinkedTx read;

                    if ( waitOn._writeLock == waitingTx ) {
                        throw new LockNotGrantedException( "persist.deadlock" );
                    }
                    read = waitOn._readLock;
                    while ( read != null ) {
                        if ( read.tx == waitingTx )
                            throw new LockNotGrantedException( "persist.deadlock" );
                        read = read.next;
                    }
                    waitOn.detectDeadlock( waitingTx, numOfRec - 1 );
                }
                lock = lock.next;
View Full Code Here

                entry = (ObjectLock) locks.get( orgoid );
                newentry = (ObjectLock) locks.get( newoid );

                // validate locks
                if ( orgoid == newoid )
                    throw new LockNotGrantedException("Locks are the same");
                if ( entry == null )
                    throw new LockNotGrantedException("Lock doesn't exsit!");
                if ( !entry.isExclusivelyOwned( tx ) )
                    throw new LockNotGrantedException("Lock to be renamed is not own exclusively by transaction!");
                if ( entry.isEntered() )
                    throw new LockNotGrantedException("Lock to be renamed is being acquired by another transaction!");
                if ( newentry != null )
                    throw new LockNotGrantedException("Lock is already existed for the new oid.");

                entry = (ObjectLock) locks.remove( orgoid );
                entry.setOID( newoid );
                locks.put( newoid, entry );
View Full Code Here

                entry = (ObjectLock) locks.get( orgoid );
                newentry = (ObjectLock) locks.get( newoid );

                // validate locks
                if ( orgoid == newoid )
                    throw new LockNotGrantedException("Locks are the same");
                if ( entry == null )
                    throw new LockNotGrantedException("Lock doesn't exsit!");
                if ( !entry.isExclusivelyOwned( tx ) )
                    throw new LockNotGrantedException("Lock to be renamed is not own exclusively by transaction!");
                if ( entry.isEntered() )
                    throw new LockNotGrantedException("Lock to be renamed is being acquired by another transaction!");
                if ( newentry != null )
                    throw new LockNotGrantedException("Lock is already existed for the new oid.");

                entry = (ObjectLock) locks.remove( orgoid );
                entry.setOID( newoid );
                locks.put( newoid, entry );
View Full Code Here

TOP

Related Classes of org.exolab.castor.jdo.LockNotGrantedException

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.