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

  • Planning. Planning Would Be Good

    Gretchen and I have a concert slot on Saturday for the Festival of the Living Rooms. We are now trying to figure out what we should put in it. Well,…

  • Bits and Pieces

    I am rather surprised to find that the Cardinals are suddenly in sole possession of the second wild-card berth in the NL. I am keeping my fingers…

  • Yet Another Pulled Pork Sandwich

    Gretchen and I went to City Barbeque for lunch yesterday and I decided to try the pulled pork sandwich there for the first time. This particular…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded