Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Thursday, 31 January 2013

Tech: A Rough Guide to Atmosphere with Spring, Tomcat & Jersey: Avoiding the Pitfalls

Welcome to the second  installment of the NerdAbility tech guide series. This post looks at the Atmosphere framework! Enjoy....

Edit: I Previously forgot to include the  project sources and people have rightly asked in the comments about it. I couldn't find the example I wrote this blog post from, but I found a similar example on my github. You can find it here

More and more it's becoming a common requirement to support some sort of bi-directional (asynchronous) channel in modern web applications. Atmosphere is a great library which does much of the heavy lifting if you're running on a Java, servlet based stack. It offers support for WebSockets, Server Side Events (SSE), Long-Polling, HTTP Streaming (Forever frame) and JSONP. There are, however, some pitfalls and, if you've not got a lot of experience in the area, it can be frustrating trying to work out whats going wrong.

Having run through the process once I thought it'd be nice to cover my implementation in some detail. Maybe you'll see something which can help you with your own configuration or implementation problems.

Overview of the stack

This is what I had in place before integrating atmosphere.
  • Application server: Tomcat 7.0.32 (Must be greater than 7.0.30 for atmosphere to work correctly).
  • Container: Spring 3.2 RC1 ( though anything post 3 is fine )
  • Build Enginer/ Dependency Manager: Maven3
  • Front-End: Javascript / JQuery

    Include the Dependencies

    You'll want to add the following entries to your POM :

    Properties:

    Dependencies:

    Just a quick note about the cors-filter dependancy, you'll only need it if you want Cross-Origin-Resource-Sharing support. I thought about covering it in this article, but maybe i'll write it up as a follow up

    The web.xml

    If you're not using servlet 3 already, time to upgrade. Change your web-app config to look like this:

    The next step is to include the standard spring dispatcher etc to your configuration. You will probably you'll already have this anyway.


    The Atmosphere Controller 

    Using The Atmosphere Servlet

    I fully accept that everyone has their own pet way of setting up servlets, this is just one possible mutation. You want to add the following to your web.xml:

    Pitfall 1: The broadcasterLifeCyclePolicy tells atmosphere to destroy any connections that been closed by the client, enabling it will prevent OOM (Out of Memory) issues in your application.
    Pitfall 2: The recoverFromDestroyedBroadcaster prevents an exception being thrown when you try to reuse a broadcaster that you have recently destroyed ( useful if you want your client to subscribe using its own personal channel ).
    So now you're able to use spring MVC alongside your atmosphere code without them stepping on each others' toes. Lets move on.

    The Controller Class

    Mine was simple enough. It basically passes off the broadcasters that it creates to another service which whatever listeners you have configured ( Mine was RabbitMQ ) will call when they have an appropriate message.

    
    @Configurable: Using @Configurable is a great way to use aop classweaving to inject spring dependencies into non-managed spring classes. There is extensive documentation on how to set this up in spring 

    Pitfall 3: Make sure you set the suspend period, or you're going to be dealing with a java.net.SocketException: Too many open files in pretty much no time.

    The Service Class

    Also very simple. Using a map to store the in use channel ids -> broadcasters, the service is simply responsible for looping through the registered broadcasters and broadcasting a generic message.

    The Async Class

    Probably you'll have some asynchronous process which is waiting for messages, there are many possible implementations that this may take so i'll just show one of the popular ones RabbitMQ.
    You'll need to make sure you add the following dependency to your pom:

    RabbitMQ has a pretty clean java integration which is nice and quick to set up. The first component is a context configuration file where you bind your queues, connection factory, admin, exchanges and listeners.


    Notice the reference to broadcastQueueConsumer we used there ? Lets write that now.

    I've omitted the declaration of the Simple Message Converter in the context file but please dont forget about it. Once you're done you've got a pretty clean implementation of the serverside and should be ready to move onto the frontend.

    JQuery frontend implementation

    Really its quite simple to build a small subscription handler. I've added an example of mine below :
    Pitfall 4: Make sure you set enableXDR to true if you want to support cross domain requests.

    Pitfall 5: To send custom request params it seems like you need to pass via url (maybe jfrancard has fixed now but not sure)

    Thanks for reading, and feel free to ask any questions via a comment below or our twitter @nerd_ability

    Thursday, 3 January 2013

    Technologies You Can't and Won't Miss in 2013

    With the new year welcomed in around the world, here at Nerdability we wanted to highlight some of the tools and frameworks we have followed / used in 2012, which we think will continue to grow and have a strong 2013.

    Meteorjs Logo

    The Meteorjs framework / application platform made a big splash in the technology ocean this year when the group behind it received a ton of funding ($11.2m) to focus on developing the open source project. Meteor is great for building responsive web applications and components that run in a modern distributed environment. Meteor is based around the concept of smart packages, offering bundles of functionality that can be added to your application. These smart packages  help keep things nice and lightweight and also offer functionality that you would spend way to long making yourself. However Meteorjs is in what they are calling early preview, so things will be changing and if you want to run the latest version your application will require updates and changes to keep up with new Meteor releases. Also we would say Meteor is an advanced framework, and you will need to have a grasp of the underlying technologies (Node.js / HTML 5) to really get the most out of it. We think 2013 will see Meteor make a deep impact, so why not give it a try by following their quick start guide and looking through some examples here?

    jClarity Logo

    jClarity have just launched their first JVM performance tuning tool focused on garbage collection log analysis called Censum. Censum tries to solve your GC and memory nightmares, which we all know can be a very long winded process! From what we have seen so far jClarity seem to be on top of the needs of developers wanting easy to interpret information about what is happening under the hood of the JVM. What we really like about Censum is the fact it can be used in any organisation and comes in at a very reasonable price point. Also jClarity is run by three Java heavy hitters, Ben Evans, Kirk Pepperdine and Martijn Verburg, so we are sure that there will be much more to look forward to over 2013.

    Twitter Bootstrap Logo


    The NerdAbility team have really enjoyed using the Twitter Bootstrap framework over the past year while working on NerdAbility and other projects. The Twitter Bootstrap framework has really grown in popularity in 2012, and there are now so many kick ass add-ons that supplement the already vast Bootstrap features. A great list is provided by @bootstraphero here. If you haven't tried the framework yet then check out some examples

    BitBucket Logo
    In December (2012) we moved over our Git hosting to BitBucket from CloudBees. We made this decision due to the fact there is now a very similar interface to GitHub, with issue tracking, code reviews and a smart desktop client (SourceTree). Even though many are saying BitBucket has simply cloned GitHubs features, BitBucket is free for the first five users with unlimited repos and has a reasonable price plan starting at $10 for 10 users. For a small team this is a great freebie! While we have a small team and a small number of repositories we are quite happy with using BitBucket. It seems that when choosing between GitHub and BitBucket it will be down to brand or price plan preference. GitHub charges by the number of private repo's, BitBucket by the number of users. We expect BitBucket's popularity to grow among small teams looking to keep costs down while still getting some great features.

    Grails Logo Play Logo

    While neither of these frameworks are new in 2012, the last year has seen some big releases for both Grails and Play frameworks. They have both passed the 2.0 milestones and continue to go from strength to strength.

    We are excited by what Typesafe are doing with the Play framework and the move towards Scala. We have seen some great examples of how you can use the framework and Scala to write precise and elegant code that is just not possible with Java. Also Typesafe have had a sizeable amount ($14m) of investment this year, and the Spring legend Rod Johnson has joined as a director. We like the approach Typesafe are taking with the 'Typesafe Stack' which should help keep the various technologies focused.

    The team at SpringSource have also been very busy with Grails. Behind the scenes Grails 2.2 is running Groovy 2.0 and is still built on Spring. Additionally the plugin repository is ever growing and we are now seeing many well established add-ons. This makes Grails an attractive framework, and we expect it to continue to grow in usage in enterprises and startups.

    NerdAbility.com Logo

    Here at NerdAbility we will be working hard in 2013 to keep improving the site. We are working on many new integrations for your profile, so in 2013 you will be able to show off even more of the cool tech things you do on-line. Help NerdAbility grow by sharing your profile URL on forums, Twitter, LinkedIn and especially when you are applying for jobs. There is no better way to stand out than showing that you are an awesome developer in and outside of work!

    Come check us out today and signup for a free profile. You can then connect to sites like StackOverflow, GitHub, BitBucket, Google Code, Geeklist and have all the awesome stuff you do shown on your NerdAbility profile.

    Sunday, 30 September 2012

    Google Code, User Search & Gravatar! NerdAbility Updates - September 2012

    At NerdAbility HQ we have had a busy month, launching some cool new upgrades to your profile! This includes Google Code project integration, StackOverflow Flair and Gravatar profiles pictures! Additionally you can now search other users based on their username or skill, giving you the results along side the users NerdScore.

    We have also added new privacy options to allow you to hide your page to the public while you are getting things ready. Oh, and if you don't want to be included in our user search feature, you can easily opt-out on the privacy settings page.

    Other small changes include more ways to share your profile with enhanced social sharing buttons. This makes it easier to share your's or others profiles and show off!

    We are going to keep pushing out more features, so keep an eye on your profile and the blog for the latest news. Now a quick guide to some of the new features.......

    Setting Up a Gravatar Profile Photo - Stand out!


    First of all login to your profile at http://nerdability.com - then once you are directed to your page look to the right hand side, if your picture, then hey, you already have a Gravatar! If you don't see a picture, or want to change it then you can follow the link underneath and go sign up (it's really quick and easy too).
    Setting Up a Gravatar Profile Photo
    NerdAbility - Setting Up a Gravatar Profile Photo
    Gravatar Signup or Login
    Signup to Gravatar or Login

    Adding Google Code Projects to your Profile - Show off!


    If you have a Google Code profile you can now have your projects shown on your NerdAbility profile! It's just as easy as adding any other integration, simply login to your profile at http://nerdability.com and look at the right-hand side of your profile for 'Get Connected', then click the 'Connect Google Code' and enter your Google Code profile URL (something like http://code.google.com/u/....). 

    Connect Your Profile to Google Code
    NerdAbility - Connect Google Code

    Searching & Searching - Find Other Awesome Techies!


    You can now search our users to find who has certain skills, and then pick who you want to check out based on their NerdScore! This makes it easy to say find users with Java skills and then check out the person with the highest NerdScore! To access the search go to the Users page and get searching...

    NerdAbility User Search
    NerdAbility User Search

    Changing Your Privacy Settings - It's Under Your Control!


    We now offer privacy options for your profile, as we know you may not want your profile to be searchable or you may want to go into hiding for awhile. You can mange this quickly and easily from your profile page, simply login and click on your name in the top right of the page. Then click 'Privacy & Settings' from the drop down.

    NerdAbility Privacy & Settings
    NerdAbility Privacy & Settings 
    Next you can choose the privacy settings for your profile (and if you want to sign up to our site email updates). Hopefully it will look like this...

    Privacy & Settings Page
    Privacy Privacy Privacy!
    And that's all for this month! Make sure to spread the word and check us out on Twitter @Nerd_Ability

    Thursday, 30 August 2012

    NerdScore!? NerdAbility Updates - August 2012

    NerdScore is Live!


    So far this month we have launched the "NerdScore" on NerdAbility.com! This gives your profile a score based on the connections and details you have added to NerdAbility. To work out your score we use the super secret "NerdOrithm"!

    You can now show off your high score via http://nerdability.com/user/yourprofile, and increase it by connecting and using sites like GitHubBitbucketStackOverflowGo check it out :)

    Profile NerdScore!

    Enhanced StackOverflow Integration


    We have tapped up the StackOverflow API to add further integration to your NerdAbility profile, now showing a summary of your SO "Badges" and your answer "Accept Rate". Check it out on your profile now, and if you havn't integrated with StackOverflow give it a try :).

    NerdAbility StackOverflow with Badges
    Now with Badges & Accept Rate

    What's Coming Up?


    Over the next few weeks we will be pushing out some more new features to the NerdAbility site. These are focused around improving the user experience and giving you more control of the privacy and contact preferences for your profile.

    We are also working hard on allowing you to integrate even more of the cool stuff you do on-line in to your  NerdAbility dynamic resume / CV. This includes the tech meetups and events you go to, the coding / software engineering books you have been reading and the presentations you have published on-line. So keep your eyes peel for update emails and blog updates to be the first to hear when these features go live.

    Also ... Hot Skills & How To's


    We want to show you some of the technologies that we have been using (and we think are quite cool). So expect to see some how-to blogs, which will get you up and running. These will include the extending the Spring Social framework and integrating with Java / Spring app MailChimp (the email campaign app). All of these examples will come with sample projects on GitHub!

    Once you have had a play and could tell someone else how to do it why not add it as a skill on your NerdAbility profile? Its easy - see how below:

    1. Sign Up or Sign In 

    NerdAbility Login Example
    NerdAbility Login
    2. Add the Skill to your profile - click "Want To Add A Skill", then add the details and click "Add Skill". Done :) 

    Add NerdAbility Skill
    Add a Skill to NerdAbility
    3. Or even better why not share the code you are working on on GitHub or BitbucketYou can then link your account to your NerdAbility profile and we will automatically add the skill to your page, sweet right? Just click the connect GitHub or Bitbucket on the right hand side of your profile.

    Connect GitHub to your NerdAbility profile
    Connect your GitHub or BitBucket to NerdAbility
    That's all for the August updates from the NerdAbility team!

    Please get in touch with us on Twitter - @Nerd_Ability or comment below with any idea, feedback or questions.

    Friday, 17 August 2012

    6 Steps to Getting an Awesome Tech Job

    So everyone wants an awesome coding job using the ’latest technologies’ at a amazing company right? And the competition for these jobs is tough! People from big corporations want in on the exciting world of start-ups, and well-seasoned start-up coders want to work on the next big thing. Previously you needed a great hand crafted CV and 100 years of experience building monolithic Java EE / C++ apps to get noticed. Now companies want to see you are up to speed with new school technologies like Node.js, Groovy & Grails, Ruby, Scala, Clojure and that you also actively contribute via Blogs, GitHub, BitBucket, StackOverflow etc.

    How do you get one of these awesome jobs you ask? Follow NerdAbility’s fool proof 6 point plan!.....

      Blogger LogoTumblr. Logo
    1.  Create a tech blog! – Have you been trying to learn a new technology but found the documentation is a bit shady? Did you spend hours on forums and post multiple StackOverflow questions to finally get to a solution? Then write a blog about it! Document the problem, the steps you took to solve it and give some sample code or even put the project on online. Next make sure to share it back with the people and forums that helped along the way. This is a great way to get your solution out there and people checking out your blog (maybe even the CTO of your next employer). Sites like Blogger and Tumblr make it super easy to get started, so go make one today!