All Meetings, All the Time
Mar. 25th, 2014 10:11 pmBack to the Loop again today for another round of meetings.
I did manage to spend a few more minutes on the locking scheme for the server-side of my Java code. At this point, I'm looking at having all of the lockable objects on the server define three inner classes: the first being an immutable class that holds all of the data for the mutable outer class, the second being a private class that provides a locator / index for the objects so that you can find them with a key, the third being a public class that allows you to obtain either a read lock or a write lock and that will give you access to either the immutable inner class or the mutable outer class, depending on the type of lock that you've obtained.
So in skeleton form, it would look like this:
Ok, that's an awful mess of assumptions left out and I may have blown some of the syntax, as I haven't actually tried to compile this yet, but it looks like the right idea.
I think.
I did manage to spend a few more minutes on the locking scheme for the server-side of my Java code. At this point, I'm looking at having all of the lockable objects on the server define three inner classes: the first being an immutable class that holds all of the data for the mutable outer class, the second being a private class that provides a locator / index for the objects so that you can find them with a key, the third being a public class that allows you to obtain either a read lock or a write lock and that will give you access to either the immutable inner class or the mutable outer class, depending on the type of lock that you've obtained.
So in skeleton form, it would look like this:
public class MyClass implements LockableObject { public class Const { boolean member; Const( boolean member ) { this.member = member; } boolean getMember() { return this.member; } } private class MyIndex implements Index< Key, MyClass > { MyClass find( Key key ) { ... implementation details and other useful operations elided return object; } } public class Lock { Key key; // key to use with the index to locate the class instance LockType readOrWrite; // enum defined elsewhere (READ/WRITE) MyClass object; // the object, once we've located and locked it, else null public Lock( Key key, LockType readOrWrite ) { this.key = key; this.readOrWrite = readOrWrite; } public boolean lock() { ... probably uses tryLock() etc on ReentrantReadWriteLock return success; } public MyClass get() { if ( isLockedForWrite()) { return object; } return null; } public MyClass.Const getConst() { if ( isLockedForWrite() || isLockedForRead()) { return object.Const; // is this vaguely the right syntax? } return null; } } }
Ok, that's an awful mess of assumptions left out and I may have blown some of the syntax, as I haven't actually tried to compile this yet, but it looks like the right idea.
I think.