Last few years there has been plenty of buzz around OSGi. There are many high profile projects using it http://en.wikipedia.org/wiki/OSGi as can be seen here. It was even rubberstamped into JSR-291.
As a basis for developing platforms, OSGi has garnered a lot of success. But what does does that mean to me? I don't work on platform development, perhaps >95% of IT community does not. My bills are paid by developing applications. Server side is what interests most people in Java, although, OSGi got its start on devices and desktop arguably Eclipse has answered it.
Yet, with all this much buzz, I felt I should check things out a bit. I did have a motivation to do so, because I was trying to look at ways by which I could componentize Portlets so that I do not get bitten by things I mentioned in my previous post.
After kicking some tires, I am still left with the feeling that all is not well in the OSGi land today. I will readily admit to my noobie status, still, following are some of the concerns I still have.
1. The benefits of OSGi are not obvious.
Modularity and componentizing has been such a big problem, for so long, there have been too many solutions which in many ways overlap or compete: EJB, POJO, Maven, (Web)services, DI, etc. the list is so long, you are already using many diluting the pay back. Much has been written about the benefits of OSGi, yet, nothing brought it home to me succinctly.
2. OSGi has a learning curve.
It needs an initial investment of time and effort. Words like Module, Component, Service, Bundle (well, maybe not bundle), etc. are already is wide use with conflicting / overlapping meaning and OSGi yet again over loads these words causing more confusion to the average developer. OSGi Alliance needs to invest a bit on developing well documented examples, patterns, best practices, something like what Sun did through J2EE Blueprints.
3. Tooling and IDE support is not ready for prime time.
I think in just rubber stamping an existing spec through JSR-291, we lost a huge opportunity to improve. Adding OSGi based Annotations could have helped a lot, by making this platform less Run-time focused and could have added Compile time/Deployment time support. I don't know all the politics of this, but Sun's No vote was very illuminating. The run-time focus of OSGi right now, is too dependant on being able to use a console. Not something I would be willing to deal with on a day-to-day. How about a platform independent Ant Tasks. I know of the ant wrapper on BND, I am talking about something more. Perhaps something that can augment/replace the runtime console. Does that need Distributed OSGi? That would be one way to do it. Alternatively, the spec already has a HTTP Service, which arguably can be used to incorporate this added functionality. Eating ones own dog food is good.
Squandering of JSR-291 opportunity has left relationship between OSGi bundles and WAR/EAR packaging and management fuzzy. Yes, I know, a bundle is just another jar, which can be dumped into a war like all the other jars one dumps into a war, but then you don't start or stop a jar at runtime.
4. Tomcat/OSGi integration today is non-existent.
This to me a huge gap. After all Tomcat is the most dominant webapp server today. There was some discussion among Tomcat developers regarding this for Tomcat 7, but nothing exists today. Unless there are easy ways of creating Bundles, packaging, deploying, debugging, it will fail to catch market share among application developers.
5. Distributed OSGi a necessity.
There is an RFC (the link goes to the entire set of specs of which RFC 119 is a part of), some talk about it, some development too, but it is not here yet with the exception of the reference implementation Apache CXF. I think when I can use a few Annotations and/or simple configuration, and get a nice Web Services based service, which can be started and stopped easily OSGi will always be one of those curiosities.
6. Framework Support a necessity.
OSGi does not define higher level services, but one needs Transaction Management, Dependancy Injection, QoS, Availability / failover / clustering, ability to locate and use services across applications, system, network, OS boundaries on and on. You can debate the choice of words here "Framework support", but I was kind of alluding to the type of added value Spring framework brings to a POJO. Till such functionality becomes available in a seamless manner, a developer will always be wondering how does OSGi fit into my application.
After a huge burst of interest when Eclipse 3 moved to OSGi 3 years back, somehow I get the feeling OSGi momentum is stalling. However, some powerful market forces are at work here. With Oracle acquiring Sun (Glassfish [when will v3 loose its Prelude moniker signalling production readiness? that's a whole different story]), BEA (Weblogic), what impact does that have? Will it further boost OSGi? It can, if Oracle Application Server also adopts it in a big way delivering a large pool of interoperable bundles across the 3 platforms. This can lead to an explosion of the repository of bundles, enabling one to grab ready-to-use-bundles and use it. That of course will finally bring home the benefits succinctly while answering the main question this blog poses.
My crystal ball sure is cloudy, how's yours?
Monday, July 27, 2009
Liferay messes up OpenSessionInView
It all started with the work I was doing on Liferay 5.2.3 a few months back. There is something wrong with Liferay/Hibernate/Spring Transaction integration. It just does not work. For one thing, Transaction demarcation either declaratively or through AOP relies on ThreadLocal or Thread based state. OpenSessionInView filter as implemented by Spring relies on or assumes that the thread that was dispatched for the request is the same one through out the request and response phases of the operation. By tying the SessionFactory and other state to the thread the filter is able to keep the session in view. I have not had the time to research this out more completely. It appears that Liferay uses different threads or atleast switches threads thus messing up the OSIV filter.
If you are trying to use Lazy Loading in Hibernate you are dependant on OSIV. With OSIV confused, you can say good bye to Lazy Loading, Transaction Demarcation and all the good stuff inside a Portlet.
The only way I could get Lazy Loading to work was by extracting some pieces of code from Spring's OpenSessionInViewInterceptor, sticking it into my code and thus setting up transaction boundaries. Between these boundary points, I could get Lazy Loading to work.
From the perspective of compliance with the Portlet Specification JSR-168, what Liferay has done maybe right. The spec clearly splits up each request into Action and Render phases. The Portal is supposed to enable multiple portlets to respond to each of these phases in parallel. Chances are Liferay is internally using a pool of threads and dispatching requests in parallel. The side effect is that frameworks written for traditional web applications where it is assumed that the same thread is involved through out the request gets messed up.
Why Liferay did not make any effort to fix this issue is beyond me. It sure gave me a lot of heart burn.
In my case I had the code separated into a service class, and that helped, because I was able to extend org.springframework.orm.hibernate3.HibernateAccessor. I setup the start point of the transaction boundary by this code. Created a method startTransaction to do so.
If you are trying to use Lazy Loading in Hibernate you are dependant on OSIV. With OSIV confused, you can say good bye to Lazy Loading, Transaction Demarcation and all the good stuff inside a Portlet.
The only way I could get Lazy Loading to work was by extracting some pieces of code from Spring's OpenSessionInViewInterceptor, sticking it into my code and thus setting up transaction boundaries. Between these boundary points, I could get Lazy Loading to work.
From the perspective of compliance with the Portlet Specification JSR-168, what Liferay has done maybe right. The spec clearly splits up each request into Action and Render phases. The Portal is supposed to enable multiple portlets to respond to each of these phases in parallel. Chances are Liferay is internally using a pool of threads and dispatching requests in parallel. The side effect is that frameworks written for traditional web applications where it is assumed that the same thread is involved through out the request gets messed up.
Why Liferay did not make any effort to fix this issue is beyond me. It sure gave me a lot of heart burn.
In my case I had the code separated into a service class, and that helped, because I was able to extend org.springframework.orm.hibernate3.HibernateAccessor. I setup the start point of the transaction boundary by this code. Created a method startTransaction to do so.
currentSession = SessionFactoryUtils.getSession(
getSessionFactory(), true
);
setFlushModeName("FLUSH_NEVER");
applyFlushMode(currentSession, true);
TransactionSynchronizationManager.bindResource(
getSessionFactory(), new SessionHolder(currentSession)
);
Corresponding end point was setup through another method
endTransaction.
SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.unbindResource(
getSessionFactory()
);
SessionFactoryUtils.closeSession(sessionHolder.getSession());
Subscribe to:
Posts (Atom)