Posts

Applying the Strategy Pattern in Java

Image
Working with strategy on Arrays.sort & java.util.Comparator All these examples and more can be found on github In Java, you cannot pass function references through a method. With this being true, how do we then apply a strategy to a method? What is suggested, is that we define an interface with the function we want to pass. This way we can on the fly, define and pass an algorithm to a method for process. In this demo, we will be working strictly with the strategy interface:   java.util.Comparator . This is a java strategy interface, readily available in the Java API as of 1.5. It supplies a compare algorithm, where its implementation is primarily for sorting large collections of objects.

Atmosphere Websockets & Comet with Spring MVC

Image
Since writing this guide, Spring has come out with their own Comet and Websocket implementations. I suggest you first read through their guides before deciding on atmosphere as your Comet & Websocket solution. 1.  Messaging with Stomp over Websockets 2.  Spring Messaging On to the guide... Feel free to clone the source of this project on github. springMVC-atmosphere-comet-websockets The Websocket protocol is defined by W3C  here . The protocol is considered an HTTP upgrade protocol. Essentially what happens is, a websocket request is made by a client browser, via the HTTP protocol. Once, the request is in, the server should respond with a success. Then the browser and server establish a TCP link to handle communication from there on out. This protocol enables bi-directional communication between a client and server. Here is a link to browser and servers that support Websockets and/or Comet:  comet/websocket support link