Friday, January 28, 2011

Configure embedded Jetty in OSGi enviroment

As mentioned earlier, recently was working on using embedded Jetty server in an OSGi environment. Though the information is available on web, but quite scattered. Especially how to configure or debug jetty. So, below is the collated information:
Once you have the up and running servlet as per the steps at:
http://bryanhunt.wordpress.com/2010/05/14/osgi-as-a-web-application-server/
You can do away with auto start of bundles in the launch configuration, use the following code in the activator of your bundle
Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry");
if (bundle.getState() == Bundle.RESOLVED) {
 bundle.start(Bundle.START_TRANSIENT);
} 

To make sure your bundle auto starts, implement the startup extension. In your plugin.xml put this:  

    <extension point="org.eclipse.ui.startup">  </extension>

Configure Jetty:  
Now, many times you will not have the option to change the config.ini to provide the port, or you want to configure the Jetty from within your application, there you will need to use the JettyConfigurator class. Use the following code in the activator of your bundle
Dictionary settings = new Hashtable();
settings.put("http.enabled", Boolean.TRUE);
settings.put("http.port", 8080);
settings.put("http.host", "0.0.0.0");
settings.put("https.enabled", Boolean.FALSE);
try {
     JettyConfigurator.startServer("my.jetty", settings);
} catch (Exception e) {
   e.printStackTrace();
} 
You can configure many other settings using the JettyConfigurator as mentioned above. 

Friday, January 14, 2011

Thank you for the computers, Microsoft

Ok, many people will raise their eye brows and many would have already started writing a hate mail … but yes if there is one company I will give credit for the popularity of computers then it would be M$.

Just to clarify I am not one of this die hard Visual Basic fans, I am totally into open source, and have my own reason to hate M$ (notice the dollar sign)

But if it would not have been M$, the computers would have been still a luxury item for the geeks; people who will give confusing commands to open a vi editor and type Hello world, save the file with Esc : wq  and then dance around in the room for what they have accomplished.

Microsoft was one company which made the things easy, made the computers accessible to the common man and continues to do so.

When I was in college learning computers, Unix was part of semester curriculum, we were told that Unix was such a stable system that no change was required in it for almost 16 years. (ok, sound like another urban legend). But even in practical terms why not make things better, why I should type Esc+a, just to start typing, and Esc+x to delete, when that delete key is right there in front of me. I know many geeks and vi editor lovers are already up in arms against me,  but dude, no one is taking away your geeky things, but please evolve …

Thank god, MS understood and made better useable systems (I do understand the it was Apple which brought in the good looking GUI interface and tried to break the monopoly of IBM, but a PC with almost negligible applications available priced at 2500$ in 1984 was bit too much for common man, and then chain of wrong decisions simply ruined the company… )

Love it … hate it… but M$ is one company because of which you are able to do most of things that you currently do on your computer… (of-course apart from your geeky stuff)

Monday, January 10, 2011

OSGi/Equinox: Remote Debug embedded Jetty Server

Today got stuck in one of those famous Java issues – Things not working and there are no errors and no exceptions. Grrrrrrrrrrrrr, whyyyyyyyyyyyy…………

Resorted to one of my oldest friend - remote debugging.
But this time the situation was different. The servlet was running as an Extension to Eclipse Application published on embedded Jetty server.
Looked around how to start the embedded server in debug mode and specify the debug port. But most of the articles talked about some Maven configuration. I know, open source community is big fan of Maven but I haven’t worked much on that. And I just want to start the server in debug mode, why all pom.xml and other stuff. (can’t really understand why the documentation of even the most popular open source products is so bad, will talk about this some other day)

Anyways after lot of wild goose chase realized that as its embedded, I need to just remote debug the JVM. So did what you do to remote debug any java application:

In Eclipse IDE, added the following in the VM Arguments in my Eclipse Application launch configuration dialog:
-Xdebug -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n
Where 4000 is the debug port we need to connect.


Started the application from Eclipse itself and then start remote debug like any other application server:

Microsoft: Late Again

Read the news.  Today read an article on how Apple has very silently inched towards being an enterprise company. A company very popularly known as the toy maker is no longer just a toy maker. First there was news on how iPads were being introduced in the schools in USA, and now the big one: JP Morgan Chase, company with one of the most complex procedures in terms of security, embraces the iPad. 
Though most people are talking about how it’s clear and present danger for RIM Blackberry, but I feel, in long term, it’s a clear competition to Microsoft.
First Microsoft was slow in catching up the Internet boom (which it publicly accepted few years back) and Google, quite aptly, won the battle in big way. MSN Search,  Live Search and now Bing, Microsoft is still lagging even after so many make overs.
But now the mobility boom, why Microsoft is still trying to sell desktops when whole world is moving towards internet and mobile gadgets. Though there was a recent launch of Windows 7 mobile, but if you see the other happenings around the world, it looks like a drop in the Indian Ocean.
A company with such a nice hold in IT Market is again late in catching up on Mobility enterprise solutions. The day will not be far when M$ cash cow ‘Windows’ will be just another redundant product.  M$ needs to check what their product managers are busy in and more importantly are they still paying millions of dollars them …  :)

Edit:  Like everyone else I Love the moments, when I get the chance to say "I told you so". A recent news gave me that moment.

Sunday, January 9, 2011

Mumbai Vs Software architecture ...

Yesterday I was watching discovery channel (ya, sometimes I do that also), while checking on one of my favorite series “Big” , found that the episode was actually talking about one of the Indian cities “Mumbai”. The name itself brings so many pictures. For the people in other part of the world, this city is business capital of India. The reason for the episode and for this blog is “this relatively small city is one of the most populated cities in the World (in-fact second most populous city in the world)”.

The episode talked about two of the major infrastructure projects currently in progress: Bandra–Worli Sea Link (Part of Western Freeway) and Eastern Freeway. Not going in too many details as you can check the Wikipedia links I have given above, one of the projects is a road link over the sea and another one is mostly elevated road link. Reason for this, as correctly mentioned in the episode, there is no space left in Mumbai so only option is to either build the road in the sea or in the air.


Though I am not against the new infrastructure projects but in the City like Mumbai and country like India where these costly projects are no easy tasks, isn’t this a Gold carpet to cover the previous mistakes. Mumbai is already packed to the brim; instead of making things seemingly better for more people to pour in, shouldn’t we rather think of better planning. One option is to make sure that apart from the important businesses which should stay in Mumbai (Mumbai is one of the busiest port in the world) other companies should be asked to move out slowly or at-least a complete stop of any new businesses until the infrastructure is capable of supporting the existing bulk.


Coming back to the title of the blog, I have seen a similar situation in many software projects. The amount of code that pours in rises exponentially in years and no one even looking into what’s already existing and if the current architecture can support the new functionality.
To mentioned some of the rather funny and worry some cases , in one project we completed the i18n of 100s of files; later to find that it was all dead code no longer used in the product.  (all getting build, packaged and published to all customers). In another instance, we did lengthy investigation to implement a long awaited feature, created the design and at the time of implementation found that it was already available in the code. No one cared to document or use it.
 

Why so much effort wastage on solving the wrong problems. How much time it takes to create at-least the architecture document of a software product? How much time does it take to understand the current architecture, clean up things before putting in more stuff. Since many years I continue to get amazed. And just for information, its 8 months since we informed the client about that dead code, it’s still there (build, packaged and ….)