Proxy Based POJOs (No AOP) in POJO Cache
jason.greene Oct 4, 2007 8:46 PMIn a conversation we had offline, Vincent Marquez has advocated a proxy based approach in addition to the current AOP approach for POJO Cache. Best of all, he has offered to work on the implementation. The primary use case for this is scenarios where it is impractical or undesirable to instrument classes. With Java 5 loadtime weaving this is less of an issue, but there are still cases where you might not want it, such as:
- Your app uses conflicting bytecode modification
- You need to cluster a class you dont know about until AFTER its been loaded, and you dont want to instrument everything
- Your app uses a serialization framework that is sensitive to the class structure
The current proposal would replace conforming non-advised objects with a proxy that would intercept all method calls. One of the restrictions would be that the object must follow the JavaBean style, which allows us to determine the correct operation and attribute we are operating on. This gives us fine-grained replication, does not require the class to implement serializable, and gives us correct object identity semantics. Essentially this is the same behavior of interception used by hibernate.
In summary it would provide close to the same advantages of AOP (over serialization), but with some trade-offs for not requiring instrumentation.
They are:- Application code has to reget an object after attaching, so that it can use the proxy instead (this is already the case today with collections)
- Objects must be java bean style only (getBlah/setBlah), since we can only catch method invocations. However, this is the prevalent style for domain models.
- Not possible to intercept array access. Application code will have to *touch* the field reference to trigger a compare and update.
I think this exchange is worth the added benefits, so provided certain implementation details can be worked out, I am all for this. One such issue is the precedence rules for determining the correct storage handler for an object. We would essentially have 3, Advised, Proxy, and Serialized.
Thoughts?