Blogs : Latest entries
When I was in the USA I bought an Apple TV and brought it back home to Belgium.
Last night, it broke down entirely after just a couple of months of operation. When I hook it up to the power socket, nothing happens. The front light doesn't light up, and I can hear no noises of the hard drive spinning up either. Seems to me that either a fuse broke, or something else just fried.
I spent some time with the Apple support line, both in the USA and in Belgium and they both say that I can only have it services in USA. I'll thus have to wait 'till my next trip to San Francisco in October to have the Apple TV repaired.
This sucks, I thought that all Apple products had worldwide warranties, apparently some of them don't.
RIFE has a unique approach towards validation which is centralized around bean instances and not bean classes.
Instead of having an external validation service, each bean instance publishes meta data about its constraints. Every part of the system (validation, form generation, database structure creation, ...) will inspect the meta data and peruse it. Validation is an exception in that after inspecting the meta data, the results of the validation are contributed back for each specific bean instance as
Instead of implementing a container that keeps track of all the mappings between bean instances, their meta data and the validation errors, I decided that each bean instance will actually hold this data into fields. However, since people generally dont want to pollute their bean classes with framework-specific constructs, I created the meta-data merging facility. This automatically looks for a class with the
All this is very intuitive when you use it in practice and develop a database-backed website. RIFE's database layer doesn't use an entity container either but rather creates and populates new bean instances each time an entity is fetched from the database. This has the benefit of each thread having a dedicated version of the entity which can be manipulated without risking data races. Only when all the operations are finished, the entity is stored back into the database through an explicit save call.
The code could be like this when editing an existing
However, when using Terracotta (or something else, like a cache), you typically don't want every entity to go back to the database. Instead, you want to keep them in memory and only store certain parts into the database. So instead of having a database manager, you have some kind of in-memory service that is able to find and store entities.
Intuitively and naively you would replace the code above with the following broken code:
The problem relies in the fact that each and every thread will be working with the same instance of the
So, instead of retrieving the user from the service to modify it with possibly invalid data, you want to create a new instance of the entity that will be in local scope until the validation has succeeded. Only then you want to store it back into the service. This guarantees that your data is always correct and also allows perfectly concurrent access on users with the same identifier.
The correct code would thus be:
This had me scratching my head when I was bitten by the broken code above. However, if you think about it, it's perfectly logical. Working with in-memory containers is fundamentally different from working with relational database, where your data is stored independently from the actual objects that you're using. You have to remember that an in-memory container is a store too, and you don't want invalid or intermediate results to end up in there. However, this is what you risk to happen when you directly manipulate the fields of the instances that are already in the in-memory container ... but it's oh so tempting to do!