james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harmeet Bedi" <hb...@yahoo.com>
Subject locking - unlocking.
Date Thu, 15 Mar 2001 10:20:51 GMT
there seems to be some code in the james.mailrepository package that has
this pattern

<modifier> <returntype> someMethod(<parameters>) {
      lock(..);
      some code
      unlock(...);
}

Would it be better to have some way to enforce unlocking via try-finally
mechanism...

<modifier> <returntype> someMethod(<parameters>) {
      try {
          lock(..);
          some code
      } fianlly {
           unlock(...);
      }
}

the 2 places I found were
method <remove> in james/mailrepository/AvalonMailRepository.java
improvement could be from:
----------------------------
    public void remove(String key) {
        lock(key);
        sr.remove(key);
        or.remove(key);
        unlock(key);
    }

to:
---------------------------------
    public void remove(String key) {
        try {
            lock(key);
            sr.remove(key);
            or.remove(key);
        } finally {
            unlock(key);
        }
    }


method <remove> in james/mailrepository/TownSpoolRepository.java
improvement could be from:
---------------------------------------
    public void remove(String key) {
        //System.err.println("removing " + key);
        lock(key);
        try {
            TableDataSet messages = new TableDataSet(...);
            messages.setWhere(...);
            Record message = messages.getRecord(0);
            message.markToBeDeleted();
            message.save();
        } catch (Exception me) {
            throw new RuntimeException("Exception while removing mail: " +
me.getMessage());
        }
        unlock(key);
    }

to:
---------------------------------------
    public void remove(String key) {
        //System.err.println("removing " + key);
        try {
            lock(key);
            TableDataSet messages = new TableDataSet(...);
            messages.setWhere(...);
            Record message = messages.getRecord(0);
            message.markToBeDeleted();
            message.save();
        } catch (Exception me) {
            throw new RuntimeException("Exception while removing mail: " +
me.getMessage());
        } finally {
            unlock(key);
        }
    }


If this makes sense could someone please commit.

On this topic, would it make sense to use something like AspectJ, or some
uses-derivation based pattern, or JDK1.3 proxies to enforce locking policies
across functions ?

thanks,
Harmeet


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org


Mime
View raw message