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);
}
}
}
}