Programming
Conditional Java Configurations in Spring Framework
Spring Framework offers very flexible means for binding application components. Externalizable properties, composite configuration, nested application contexts and profiles.
Sometimes, it is necessary to control whether particular beans or @Configuration
will be loaded or not. Spring Framework v.4.1.x does not provide that feature out of the box. But, hopefully, Spring allows conditional bean initialization (see @Profile
implementation and @Configurable
).
So, I created the annotation @Enabled
which allows me to control bean instantiation via properties.
@Enabled
indicates that a component is eligible for registration when evaluated expression is true. This annotation should be used in conjunction with Configuration and Bean annotations.
JAX-WS with Custom SSLSocketFactory
It’s very easy to configure custom SSLSocketFactory for JAX-WS web-service: just specify custom property referring to SSLSocketFactory
bean.
But there is a nuance…
Useful Code Templates for Jetbrains Idea
Jetbrains Idea is a perfect IDE (sorry, Eclipse fans). But, like every tool, sometimes it needs some customization to fit your needs. Today I want to show how to adjust it’s code-generation templates.
When you generates a new class or method using Idea, it creates one using predefined templates. You may modify that template in “Settings -> File and Code templates” section.
WebJars: Easy Packaging Client Libraries
When developing java web application it is often annoying to manage third-party javascript libraries. Especially, when it is necessary to upgrade some of them.
The project “WebJars” makes a life easier for such lazyefficient developers, like me :-)
There is a wide range of popular javascript libraries packaged int Jar archives and ready to be included as a dependencies into your project. It is described in the documentation how to configure resource mapping in a web framework of your choice.
JSON Validation with JSON Schema
JSON has became a de-facto standard for webservices, replacing XML web services. It has native support in web browser clients.
That makes JSON is the standard of choice for UI-oriented services. It has a good support on mobile devices. Also, it provides smaller data payload size compared to XML and it’s very sufficient for high-load systems as it saves a traffic. But what is for data validation? For XML web services there is a XML Schema. It comes ti mind, that similar standard for JSON should be called “JSON Schema”. And it really exists!
Chronicle
Chronicle by Peter Lawrey:
This library is an ultra low latency, high throughput, persisted, messaging and event driven in memory database. The typical latency is as low as 80 nano-seconds and supports throughput of 5-20 million messages/record updates per second.
This library also supports distributed, durable, observable collections (Map, List, Set) The performance depends on the data structures used, but simple data structures can achieve throughput of 5 million elements or key/value pairs in batches (eg addAll or putAll) and 500K elements or key/values per second when added/updated/removed individually.
It uses almost no heap, trivial GC impact, can be much larger than your physical memory size (only limited by the size of your disk) and can be shared between processes with better than 1/10th latency of using Sockets over loopback. It can change the way you design your system because it allows you to have independent processes which can be running or not at the same time (as no messages are lost) This is useful for restarting services and testing your services from canned data. e.g. like sub-microsecond durable messaging. You can attach any number of readers, including tools to see the exact state of the data externally. e.g. I use; od -t cx1 {file} to see the current state.
JVM Profiling Mode
There is no sense to run profiler in instrumentation mode on a high load.
Instead of using instrumentation you should use sampling mode.
This article describes the difference between instrumentation and sampling modes. JVisualVM is a good free tool for this task.
Give Good Names for Your Threads
When configuring executors in multithreaded application, do not forget to assign names to your threads. It simplifies later profiling a lot, when you see a meaningful thread names in your profiler.
For example, you may use CustomizableThreadFactory
from SpringFramework.