Package com.volantis.mcs.repository.lock

Examples of com.volantis.mcs.repository.lock.Lock


            while (resultSet.next()) {
                String resourceIdentifier = resultSet.getString(1);
                String principalName = resultSet.getString(2);
                Timestamp acquisitionTime = resultSet.getTimestamp(3);
                Principal principal = new JDBCPrincipal(principalName);
                Lock lock = updateLock(resourceIdentifier, principal,
                        acquisitionTime.getTime());
                locks.add(lock);
            }
        } catch (SQLException e) {
            throw new LockException(e);
View Full Code Here


            String principalName = args[1];
            Principal principal = new JDBCPrincipal(principalName);
            String resource = args[2];

            Lock lock = manager.getLock(resource);
            lock.acquire(principal);
        } else if (command.equals("unlock")) {

            if (args.length != 3) {
                usage("lock <principal> <resource>");
            }

            String principalName = args[1];
            Principal principal = new JDBCPrincipal(principalName);
            String resource = args[2];
           
            Lock lock = manager.getLock(resource);
            lock.release(principal);
        } else if (command.equals("list")) {

            Collection locks = manager.getLocks();
            if (locks.size() == 0) {
                System.out.println("No locks found");
            } else {
                for (Iterator i = locks.iterator(); i.hasNext();) {
                    Lock lock = (Lock) i.next();
                    Date date = new Date(lock.getAcquisitionTime());
                    DateFormat format = DateFormat.getDateTimeInstance();
                    String formattedDate = format.format(date);
                    System.out.println("Resource " +
                            lock.getResourceIdentifier() +
                            " is owned by " + lock.getOwner().getName() +
                            " and was acquired on " + formattedDate);
                }
            }
        }
    }
View Full Code Here

        //   Test Expectations
        // =====================================================================

        Collection collection = lockManager.getLocks();
        assertEquals(2, collection.size());
        Lock lock;
        Iterator iterator = collection.iterator();
        lock = (Lock) iterator.next();
        checkLock(lock, "Lock 1", "resource1", "fred", 1000);
        lock = (Lock) iterator.next();
        checkLock(lock, "Lock 2", "resource2", "barney", 2000);
View Full Code Here

        // =====================================================================
        //   Test Expectations
        // =====================================================================

        Lock lock1 = lockManager.getLock("fred");
        assertNotNull(lock1);
        Lock lock2 = lockManager.getLock("fred");
        assertNotNull(lock2);
        assertSame(lock1, lock2);
    }
View Full Code Here

                .returns(lockInfo);

        // =====================================================================
        //   Test Expectations
        // =====================================================================
        Lock lock = new JDBCLock(lockManagerMock, RESOURCE_ID, null, -1);
        boolean locked = lock.acquire(fred);
        assertTrue("Locked", locked);

        assertEquals("Principal unexpected", fred, lock.getOwner());
        assertEquals("Acquisition time incorrect", 12345L,
                lock.getAcquisitionTime());
    }
View Full Code Here

                .returns(lockInfo);

        // =====================================================================
        //   Test Expectations
        // =====================================================================
        Lock lock = new JDBCLock(lockManagerMock, RESOURCE_ID, null, -1);
        boolean locked = lock.acquire(fred);
        assertFalse("Unlocked", locked);

        assertEquals("Principal unexpected", wilma, lock.getOwner());
        assertEquals("Acquisition time incorrect", 54321L,
                lock.getAcquisitionTime());
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.repository.lock.Lock

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.