Package org.apache.ojb.otm.lock

Examples of org.apache.ojb.otm.lock.ObjectLock


     * @see org.apache.ojb.otm.lock.map.LockMap#getLock(Identity)
     *
     */
    public ObjectLock getLock(Identity oid)
    {
        ObjectLock lock;

        synchronized (_locks)
        {
            lock = (ObjectLock) _locks.get(oid);
            if (lock == null)
            {
                lock = new ObjectLock(oid);
                _locks.put(oid, lock);
            }
        }
        return lock;
    }
View Full Code Here


        synchronized (_locks)
        {
            for (Iterator it = _locks.entrySet().iterator(); it.hasNext(); )
            {
                Map.Entry entry = (Map.Entry) it.next();
                ObjectLock lock = (ObjectLock) entry.getValue();
                if (lock.isFree())
                {
                    it.remove();
                }
            }
        }
View Full Code Here

    */
    public void waitForLock(ObjectLock lock, Transaction tx)
        throws LockingException
    {
        Transaction writerTx;
        ObjectLock writerWaitsForLock;

        // test for deadlock
        writerTx = lock.getWriter();
        while (writerTx != null)
        {
            writerWaitsForLock = (ObjectLock) _waitsFor.get(writerTx);
            if (writerWaitsForLock == null)
            {
                break;
            }
            writerTx = writerWaitsForLock.getWriter();
            if (writerTx == null)
            {
                break;
            }
            if (writerTx == tx)
            {
                StringBuffer sb = new StringBuffer();

                // deadlock detected.
                // Now we traverse the cycle once more to provide more info
                writerTx = lock.getWriter();
                sb.append(lock.getTargetIdentity());
                while (writerTx != tx)
                {
                    writerWaitsForLock = (ObjectLock) _waitsFor.get(writerTx);
                    sb.append(" -> ");
                    sb.append(writerWaitsForLock.getTargetIdentity());
                    writerTx = writerWaitsForLock.getWriter();
                }
                throw new DeadlockException(sb.toString());
            }
        }

View Full Code Here

            _tx2 = _kit.getTransaction(_conn2);
            _tx2.begin();

            Article obj =  Article.createInstance();
            obj.setArticleId(333);
            _lock = new ObjectLock(_conn1.getIdentity(obj));
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
View Full Code Here

     * @see org.apache.ojb.otm.lock.map.LockMap#getLock(Identity)
     *
     */
    public ObjectLock getLock(Identity oid)
    {
        ObjectLock lock;

        synchronized (_locks)
        {
            lock = (ObjectLock) _locks.get(oid);
            if (lock == null)
            {
                lock = new ObjectLock(oid);
                _locks.put(oid, lock);
            }
        }
        return lock;
    }
View Full Code Here

        synchronized (_locks)
        {
            for (Iterator it = _locks.entrySet().iterator(); it.hasNext(); )
            {
                Map.Entry entry = (Map.Entry) it.next();
                ObjectLock lock = (ObjectLock) entry.getValue();
                if (lock.isFree())
                {
                    it.remove();
                }
            }
        }
View Full Code Here

            _conn2 = _kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            _tx2 = _kit.getTransaction(_conn2);
            _tx2.begin();

            Article obj =  Article.createInstance();
            _lock = new ObjectLock(_conn1.getIdentity(obj));
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
View Full Code Here

    */
    public void waitForLock(ObjectLock lock, Transaction tx)
        throws LockingException
    {
        Transaction writerTx;
        ObjectLock writerWaitsForLock;

        // test for deadlock
        writerTx = lock.getWriter();
        while (writerTx != null)
        {
            writerWaitsForLock = (ObjectLock) _waitsFor.get(writerTx);
            if (writerWaitsForLock == null)
            {
                break;
            }
            writerTx = writerWaitsForLock.getWriter();
            if (writerTx == null)
            {
                break;
            }
            if (writerTx == tx)
            {
                StringBuffer sb = new StringBuffer();

                // deadlock detected.
                // Now we traverse the cycle once more to provide more info
                writerTx = lock.getWriter();
                sb.append(lock.getTargetIdentity());
                while (writerTx != tx)
                {
                    writerWaitsForLock = (ObjectLock) _waitsFor.get(writerTx);
                    sb.append(" -> ");
                    sb.append(writerWaitsForLock.getTargetIdentity());
                    writerTx = writerWaitsForLock.getWriter();
                }
                throw new DeadlockException(sb.toString());
            }
        }

View Full Code Here

TOP

Related Classes of org.apache.ojb.otm.lock.ObjectLock

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.