Bill Roper (billroper) wrote,
Bill Roper

All Meetings, All the Time

Back 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:
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.
Tags: java, musings, work

  • Comcast At Work

    So we went to watch some TV that we'd recorded on our Comcast X1 DVR and discovered that -- overnight! -- we had gone from less than 50% full to over…

  • Tired

    I hit the wall late this afternoon. Sleep will follow soon now, but I needed to finish going through the APBA cards for next season. In other news,…

  • It Floats!

    I was discussing some of the intricacies of floating point mathematics with Gretchen over lunch today, which eventually led to her saying, "'Field of…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded