CompletableFuture is still a relatively fresh concept, despite being introduced almost two years ago (!) in March 2014 with Java 8. But maybe it’s good that this class is not so well known since it can be easily abused, especially with regards to threads and thread pools that are involved along the way. This article aims to describe how threads ...
Read More »Home » Archives for Tomasz Nurkiewicz »
Spock VW: writing custom Spock framework extensions
Spock framework has multiple built-in extensions that support many core features like @Ignore and @Timeout annotations. But more importantly developers are encouraged to write their own extensions. For example SpringExtension nicely integrates Spock with Spring framework. Writing custom extensions is not very well documented. In this article we will write very simple extension. It is not a comprehensive guide but ...
Read More »Dependency injection: syntax sugar over function composition
Quoting Dependency Injection Demystified: “Dependency Injection” is a 25-dollar term for a 5-cent concept. *James Shore, 22 Mar, 2006 Dependency injection, as much as it is important when writing testable, composable and well-structured applications, means nothing more than having objects with constructors. In this article I want to show you how dependency injection is basically just a syntax sugar that ...
Read More »Displaying progress of Spring application startup in web browser
When you restart your enterprise application, what do your clients see when they open the web browser? They see nothing, server doesn’t respond yet so web browser displays ERR_CONNECTION_REFUSED Web proxy (if any) in front of your application notices that it’s down and display “friendly” error message The website takes forever to load – it accepted socket connection and HTTP ...
Read More »Server-sent events with RxJava and SseEmitter
Spring framework 4.2 GA is almost released, let’s look at some new features it provides. The one that got my attention is a simple new class SseEmitter – an abstraction over sever-sent events easily used in Spring MVC controllers. SSE is a technology that allows you to stream data from server to the browser within one HTTP connection in one ...
Read More »RESTful considered harmful
I don’t like RESTful principles and APIs. In recent years it is seen as universal protocol for inter-process communication, especially in distributed systems. However I see many deficiencies of REST and there are alternatives that work well for certain use cases. Obviously there is no one size fits all, I just want to emphasize that REST architecture is flawed in ...
Read More »Consuming java.util.concurrent.BlockingQueue as rx.Observable
Classical producer-consumer pattern is relatively simple in Java since we have java.util.concurrent.BlockingQueue. To avoid busy waiting and error-prone manual locking we simply take advantage of put() and take(). They both block if queue is full or empty respectively. All we need is a bunch of threads sharing reference to the same queue: some producing and others consuming. And of course ...
Read More »Writing a download server. Part VI: Describe what you send (Content-type, et.al.)
As far as HTTP is concerned, what client is downloading is just a bunch of bytes. However client would really like to know how to interpret these bytes. Is it an image? Or maybe a ZIP file? The last part of this series describes how to give a hint to the client what she downloads. Set Content-type response header Content ...
Read More »Writing a download server. Part V: Throttle download speed
In the age of botnets that you can rent for few hundred bucks and run your very own distributed-denial-of-service attack, having emergency switches that selectively turn off expensive functionality or degrade performance gratefully is a huge win. Your application is still operational while you mitigate the problem. Of course such safety measure are also valuable under peaks or business hours. ...
Read More »