01: /*
02: ******************************************************************************
03: * Copyright (C) 2005, International Business Machines Corporation and *
04: * others. All Rights Reserved. *
05: ******************************************************************************
06: */
07: package com.ibm.icu.dev.test.util;
08:
09: /**
10: * Provides a flexible mechanism for controlling access, without requiring that a class be immutable.
11: * Once locked, an object can never be unlocked, so it is thread-safe from that point onward.
12: * The implementation of both methods must be synchronized.
13: * Once the object has been locked, it must guarantee that no changes can be made to it.
14: * Any attempt to alter it must raise an UnsupportedOperationException exception.
15: * This means that when the object returns internal objects,
16: * or if anyone has references to those internal objects, that those internal objects must either be immutable,
17: * or must also raise exceptions if any attempt to modify them is made. Of course, the object can return clones
18: * of internal objects, since those are safe. * @author davis
19: */
20: public interface Lockable extends Cloneable {
21: /**
22: * Determines whether the object has been locked or not.
23: */
24: public boolean isLocked();
25:
26: /**
27: * Locks the object.
28: * @return the object itself.
29: */
30: public Object lock();
31:
32: /**
33: * Provides for the clone operation. Any clone is initially unlocked.
34: */
35: public Object clone();
36: }
|