Dec 07

One of the most classic patterns in software is the producer-consumer pattern. There is a module producing data, and a module reading it for further processing. Moreover, in order to achieve better performance, usually there are many consumer modules running on many different threads while the producer (or several producers) run on its own thread. This allows to distribute processing work between threads, and in the multi-core, multi-processor environment of today, between physical processors as well. Concurrent frameworks (such as java.util.concurrent) provide out-of-the-box solutions for these kind of problems.

Same pattern, multiple machines

This pattern also works well when wanting to distribute tasks between different physical machines as well. The producer machine somehow creates information, and offloads the task of processing that information to other machines. Since we want to distribute the work between different machines without coupling issues, the data is written to a physical disk and using some sort of a distribution system (e.g. JMS queues), a notification containing the full path to the data is sent. An available consumer receiving the notification can then read the data from the physical disk and process it. The following diagram illustrates this simple idea:

Continue reading »

  • Share/Bookmark
Feb 26

Functors are defined as a function encapsulated in an object. In most cases, the function’s parameters can be set and the result retrieved using the common accessor pattern, such as setParameter1(Object value) or getResult(). The fact that these functions are encapsulated by real objects is also the reason for its greatest benefit: the use of many design patterns including structural ones such as the Decorator pattern and behavioral ones such as the Visitor pattern.

Functors in software design

While the classic object oriented design encourages inheritance and method overloading to achieve code reuse and code specialization, the functors’ design promote another approach, of composition. Functors are created to accomplish simple tasks and are later connected together, by connecting one functor’s result to another’s parameter, to satisfy a greater goal of the application.

Continue reading »

  • Share/Bookmark
Dec 22

Isn’t it about time we got to know the different stream classes a bit better? We use them in almost every project, but what do they mean? How should can we use them more efficiently? And what is the difference between a Reader and an InputStream anyway? I hope I’ll manage to give the answers I’ve come across from using, implementing and reviewing other implementations of these extremely useful classes. Continue reading »

  • Share/Bookmark

Chaotic Java is Digg proof thanks to caching by WP Super Cache