Monday, November 8, 2010

Thunderbird - Synchronizing Google contacts

I have been having trouble with synchronizing my contacts from Google to my Thunderbird Application. I was trying to use the import functionality given in the Thunderbird which to my surprise didn't work.

Then i found out one add on for it Zindus. All you have to do is click on this link download the add on file, then go to tools->Add on and click install and provide the path to the downloaded file. Now you have to provide your internet account settings and hit sync :) . This is definitely going in my top 10 application list on Ubuntu. BTW this has nothing to do with which version of linux or any other platform you are using.

Sunday, November 7, 2010

Wars Of the Social Networking

I have recently read an article about Google and Facebook getting into a social network war. Looks like things are going to be interesting in the social networking arena Google Vs Facebook. All i know from this is one person would be a clear winner, User. Both the giants are known to be very precise on what users want, i am just excited about new things Google would do to really get into this and how Facebook would counter...

Dark Clouds On JAVA

Latest news about Java has been somewhat down(Least i could say). In this article Weeks News all the updates i see are definitely concerning for Java developers like me.
To be honest with you guys i have started looking for other options but i just cant seem to get over Java so easily. I had a chance to give OpenJDK a swing but i must say there is still a long way to go on this. Perhaps  we need companies to focus on community building and move towards open source languages with a mix of proprietary tools and features, lets face it that the only thing that will feed us.
This is my 2 scents on the topic......

May be some of you would like to go through the article by eclipse Marketing Director Oracle Get a Clue.

All i can say this point is ALL IS WELL...... (I hope ;) )

Friday, October 22, 2010

Java Scheduling with Quartz and Spring - Triggers

hi all, so lets do a dive into the Triggers !

As you know that a Job in a Quartz is an entity which does the work and is kept separate from when this job should be run. For executing the job at a particular time they have the concepts of a Trigger. We associate a job with a trigger, although we can associate multiple triggers with a job, i.e. we can have trigger which says "Fire this job at 9AM daily" then we can also have a trigger2 which says "Fire this job at 10AM", So the job will be fired at 9AM and 10 AM both. Why would you want this, there are times were you scheduling can become a little complex the best solution for that would be to divide the schedule in multiple points and run(There is a certain amount of complex schedule that a Trigger can accept, more on that later).
Enough theory lets code !

First as always we need the Spring configuration which can define the time when i want my job to run.


<bean id="updateFooMap" class="org.springframework.scheduling.quartz.CronTriggerBean">
     <property name="jobDetail" ref="createMapJob" />
     <property name="jobName" value="updateMap"></property>
     <property name="startDelay" value="10000" />
     <property name="cronExpression" value="0/10 * 9-17 ? * MON-FRI"></property>
</bean>

You guessed it right, we need to define a Bean! (then again ain't all object Bean ? :) ). We create this bean of type CronTriggerBean which is a wrapper class in Spring for CronTrigger class in Quartz. Give it a reference to the Job on which it should run (remember that trigger should know which job it should fire, but job should not know which trigger is working on it). We also give this trigger a name "updateJob". I also give it a start delay of 10sec after which this job would start looking whether it should fire or not. Now i have added a CronExpression which will define when this job should be run, this is no different then cron expression in Linux. I have selected the configuration to run this job after every 10 sec from 9 hrs to 1700 hrs though Monday to Friday.
Once we are ready with the Trigger Bean we need to register all the trigger beans with the Scheduling Factory in Quartz which will fire the jobs using these triggers.


<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
     <property name="triggers">
         <list>
             <ref bean="updateMap" />
         </list>
     </property>
</bean>


Once this is done now we are ready with our job being run. run the application(Web or stand alone Spring application) and you should see the effects :) .

Sunday, October 17, 2010

Java Scheduling with Quartz and Spring

So, moving on from my last post lets do some more generic stuff with Quartz scheduler. First of all let us define a Use case; We need couple of processes which can edit or change a common java collection e.g. Map. To make this work we need a bean defined in the spring, now this bean is a representation of a Map which we need to work on.

Public class MyMap<k,v> {
   private Map<K,V> myMap = new HashMap<K,V>();

           public V get(K key){
              return myMap.get(key);
          }

      public void put(K key, V value){
          myMap.put(key,value);
      }

}

In my case i need a bit more complex map, but you got the point i need a workspace object on which my jobs can work and if it is declared as bean then i can pass the reference of this object to the job.

Note: As i will be working on a common workspace object i need to make sure when i do any changes on this object inside a job they will not be persistent(By default Quartz job are stateless).

What i need is a job which can initialize this map. So, I will create MyJob class where i will pass on the reference to this bean in the spring configuration file like this:


<bean id="myMap" class="com.myproj.MyMap"></bean>

<bean id="createMapJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myproj.CreateMapJob" />
<property name="jobDataAsMap">
<map>
<entry key="myMap" value-ref="myMap"/>
</map>
</property>
</bean>


After this configuration we are ready to write our CreateMapJob class.

/**
* This class extends the QuartzJobBean class which defines that we will be treating this as a spring
* Quartz Job. It implements a marker interface which defines this Job as Stateful Job.
*/
public class CreateMapJob extends QuartsJobBean implements StatefulJob{

private MyMap myMap;

   public void setMyMap(MyMap myMap){
          this.myMap = myMap;
   }

    protected void executeInternal(JobExecutionContext jobexecutioncontext) throws JobExecutionException                                          
   {
          JobDataMap map = jobexecutioncontext.getJobDetail().getJobDataMap();
           MyMap myMap = (MyMap) map.get("myMap");
           myMap.put("1", "Im a stateful Job !!");
        
   }

}


After this you would have an entry in the bean myMap and this will be persistent, please note you need to declare this job as stateful to save you changes in the bean. The trade off that will remain is that this Job can't be executed in parallel, this will be sychronized. Moving on we need another job which can run parallel to the first job which will read the Data pushed into the map.


<bean id="readMapJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myproj.ReadMapJob" />
<property name="jobDataAsMap">
<map>
<entry key="myMap" value-ref="myMap"/>
</map>
</property>
</bean>


After defining the Job we need to write the class


public class ReadMapJob extends QuartsJobBean{

private MyMap myMap;

   public void setMyMap(MyMap myMap){
          this.myMap = myMap;
   }

    protected void executeInternal(JobExecutionContext jobexecutioncontext) throws JobExecutionException                                           
   {
          JobDataMap map = jobexecutioncontext.getJobDetail().getJobDataMap();
           MyMap myMap = (MyMap) map.get("myMap");
           System.out.println(myMap.get("1"));
          
   }

}

In this way you can have Quartz scheduler share data between them. ofcourse in case of any practical scheduler job you would need triggers which can be configured to fire a job on scheduled time. More on that later....

Tuesday, October 12, 2010

Java Scheduling with Quartz and Spring

I have recently been involved with scheduling background jobs in a Java Enterprise application. I had the Choice of using java Executer framework support, Timer class from Java and Quartz.
I Went with Quartz because of the simple fact that they have separated out triggers from the Job. In my case i wanted multiple scheduling time for the same job(I know sychronization can be bit of a pain).  If you go through the tutorial on the Website for Quartz's http://www.opensymphony.com/quartz you will realize it is rather easy to set up the package and make it work. All the threads that you needed to create (Executor Factories in case of JDK 5.0) are gone, which was really nice.

Here's what i did....
   created a job class using the spring wrapper for quartz's e.g.
Public class FooJob extends QuartzJobBean{

       public void executeInternal (JobExecutionContext context) {
                System.out.println("Did my Foo job.... what about you?");
       }
}

This is the as simple a class can get, with just a print statement, of course your job would me much more complex (which was my case ) but the basic idea remains.

What Springs philosophy says that you should only write code which is related to the job in hand and should not be bothered about the Triggers that you need and how they would be attached with the Job. Keeping that in mind, after writing this Job class you need to switch to the spring configurations.

First things first we need to declare this Job class as our bean class(Did you notice the name "Bean" in the class extended ;) )

< bean id="fooJob" class="org.springframework.scheduling.quartz.JobDetailBean">
      


That's it, now you can create a main class which creates a ApplicationContext and you are done!

Of course there are many more things you can do with this but on that in later posts...

Monday, August 16, 2010

Lawsuits and open source community

hi, i recently have been reading a lot about the fight between Oracle and Google and i thought i should also give my 2 cents on it.
As mentioned in this blog posted by James http://nighthacks.com/roller/jag/entry/quite_the_firestorm, i kind of agree with him when he says that we need patents as defensive weapons, but what i don't understand is how can we limit ourselves from not using these weapons for offence. Oracle is and always have been the organization which thinks on metric system. The way we all open source developers think is that software should be moving towards a free and open environment: but can we really reach there without having organizations like Oracle, Microsoft? who will pay the bills? Although Google has a unique and interesting way of getting the money from open source software while also driving the innovation, small companies which depend on these open source languages and standards need more support from the community. Events like these are definitely not helping.

Finally i would say filing these kind of lawsuits, oracle is hurting the language it payed for !

P.S. - Sorry for the brevity, i expect my IDE to auto-correct my syntax errors :-).