Thursday, October 9, 2008

At last...

I was waiting for this. Projects uploaded to maven central must have all its references satisfied by maven central itself. This is sometimes a double-edged sword...

Tuesday, October 7, 2008

Thread-safe simple lifecycle (part 2)

After last post, there are some issues that remain open:
  • Do clients need to know about transient states? After all, in our multithreaded environment we only want to know if the service provided by the active object is ready to be used or not, regardless of which thread's start command did the trick.
  • What happens if we stop the object while there are in-flight requests that depend on the ON state (such as a resource disposed after a stop command)? Can we provide deterministic behaviors for these cases? Can we provide them minimizing synchronized regions and contention?
Stay tuned.

Sunday, October 5, 2008

Thread-safe simple lifecycle.

The subject today is not rocket science,  but it's been common enough through the years to deserve a post :). The problem is as follows: we have and object with a very simple lifecycle (on and off) and we need (or want) the status-changing methods (start and stop) to be thread-safe.

Of course, we can just make start and stop synchronized but, can we do better? Ok, let's polish our list of desired features:
  • We want a generic solution. We only want to write the transition code (starting up and shutting down) without worrying about thread-safety, getting it for free from the solution.
  • We want to minimize synchronization, and ideally avoid it.
  • If we can't avoid synchronization, we forbid calling alien methods from synchronized regions (to avoid unforeseen problems in the future).
So, I've checked-in a possible solution. It avoids synchronization by adding some transient states and using AtomicReference (the java.util.concurrent.atomic package contains equivalent classes for different types). More specifically, the solution is based on the compareAndSet method, which besides the properties described in the documentation, has the added benefit of being idempotent, a property that really simplifies reasoning in concurrent and distributed systems, at very different levels of abstraction.

Update: Changed svn links to tagged version.

Tuesday, September 30, 2008

API-based queries

I'm a big fan of API-based queries. Even though I really appreciate query languages (e.g. SQL), the impedance mismatch of using them inside your favorite programming language is too high, even more when you're dealing with dynamically generated queries. So much string manipulation is really error-prone.

So I really like approaches such as Lucene's or Hibernate Criteria API. However, API-based approaches are normally low-priority (above all when dealing with SQL), so standards like JPA doesn't even have such an API and in Hibernate it is far more limiting than HQL, and issues like this are real showstoppers.

Update: typo

Sunday, September 7, 2008

Types and Programming Languages

Putting my money where my mouth is, in my last order to amazon (dollar is still cheap) I got Pierce's Types and Programming Languages, after having it in my wish list for a long time.

I expect it to be a long read, as it is pretty long and dense. In any case, even though it is quite academical, I'm sure it'll be eye-opening. Stay tuned.

Refactoring lucis...

These days I've been spending a little time refactoring lucis. In these early stages of development, the public API is being continuosly changing, as I look for better ways to provide the intended service.

Through this process, I've faced what I think is one of the most difficult problems in computer science: naming things.

In this case, there are some classes that deserve names already used by Lucene (Query, Searcher, etc.), and many source files (from users of lucis) may reference both Lucene's and Lucis' classes. Even though this is not a problem, I don't like fully-qualified names, so I've had some thesaurus time :) 

Thursday, August 28, 2008

Neil Gafter is leaving Google...

Via twitter. It will be interesting to know about his new gig...

Update: New employer revealed...