Converting string configuration properties to other types, with a bit of Optional.

Somedays you come across some code and think that's pretty, why didn't I think of that? So my long time colleague Mark Warner has a nice twist on the standard name/value store pattern using method references to deal with converting from a String.

    int size = store.getProperty("cache.limit", 500, Integer::parseInt);
    boolean enabled = store.getProperty("cache.enabled", true, Boolean::getBoolean);

I took his example and refactored it slightly to return Optional, and I ended up with (more...)

Your first Lagom service – getting started with Java Microservices

I've been heads-down in writing my next O'Reilly report and didn't had enough time to blog in a while. Time to catch up here and give you a real quick start into the new microservices framework named Lagom. It is different to what you might know from Java EE or other application frameworks. And this is both a challenge and opportunity for you to learn something new. If you can wait for a couple of (more...)

Save MapR Streams messages into MapR DB JSON

Read this article on my new blog In this article you will learn how to create a MapR Streams Consumer that saves all the messages into a MapR-DB JSON Table. Install and Run the sample MapR Streams application The steps to install and run the applications are the same as the one defined in the following article: MapR Streams application Once you have the default producer and

Finalizers and References in Java

Automatic memory management (garbage collection) is one of essential aspects of Java platform. Garbage collection relieves developers from pain of memory management and protects them from whole range of memory related issues. Though, working with external resources (e.g. files and socket) from Java becomes tricky, because garbage collector alone is not enough to manage such resources.

Originally Java had finalizers facility. Later special reference classes were added to deal with same problem.

If we (more...)

Lambda of Lambda, if/else from an Optional

So I got frustrated with two limitations of the Optional interface in JDK 8. The first problem is that there is no obvious way to perform an else operation in a block as there is only a isPresent method unless you are using an old school if statement. The second problem is of course the old chestnut that even if you could do that the methods would not be able to throw a checked exception. (more...)

Getting Started with MapR Streams

Read this article on my new blog You can find a new tutorial that explains how to deploy an Apache Kafka application to MapR Streams, the tutorial is available here: Getting Started with MapR Streams MapR Streams is a new distributed messaging system for streaming event data at scale, and it’s integrated into the MapR converged platform. MapR Streams uses the Apache Kafka API, so

Microservices trouble? Lagom is here to help. Try it!

The cake is backed. We're proud to announce that the new Apache licensed microservice framework Lagom is available on GitHub! While other frameworks focus on packaging and instance startup, Lagom redefines the way that Java developers build microservice based applications. Services are asynchronous. Intra-service communication is managed for you. Streaming is out of the box. Your microservices are resilient by nature. And you can program in the language you love the most: Java.

What is (more...)

Getting hold of an un-used port when writing a test

A really quick post today, I was writing a unit test that needed to put up a temporary JAX-RS resource in order to test something very specific with out the need of a large testing framework. Unfortunately the code I was using didn't know about replacing zero with a random allocated port so I had to do something different. The nice tidy code that does this looks like the following:

try(ServerSocket ss = new ServerSocket(0))  (more...)

Getting Started With Sample Programs for Apache Kafka 0.9

Read this article on my new blog Ted Dunning and I have worked on a tutorial that explains how to write your first Kafka application. In this tutorial you will learn how to: Install and start Kafka Create and Run a producer and a consumer You can find the tutorial on the MapR blog: Getting Started with Sample Programs for Apache Kafka 0.9

Automated testing of Android applications in Java with Appium

Appium is an open source API which can be used for black-box testing of apps. It is built on top of Selenium WebDriver, which was covered in a previous post. Appium can be used to test native, hybrid and mobile web apps on Android or iOS. Several languages are supported, including Java. This blog will focus testing native Android applications in Java using Eclipse. Writing such tests requires you to have access to an .apk (more...)

Flame Graphs Vs. Cold Numbers

Stack trace sampling is very powerful technique for performance troubleshooting. Advantages of stack trace sampling are

  • it doesn't require upfront configuration
  • cost added by sampling is small and controllable
  • it is easy to compare analysis result from different experiments

Unfortunately, tools offered for stack trace analysis by stock profilers are very limited.

Solving performance problem in complex applications (a lot of business logic etc) is one of my regular challenges. Let's assume I have another (more...)

Beware of slightly different behaviour between ConcurrentMap and ConcurrentHashMap for computeIfAbsent

So I was refactoring some code to use non-locking collection classes and I noticed the this significant different between ConcurrentMap.computeIfAbsent and ConcurrentHashMap.computeIfAbsent. They key different is that for the former default implementing the mapping function can be called many times for a particular key where as for the concrete implementation it will be called only once.

Right okay so armed with that you know that any collection that implements just ConcurrentMap will inherit (more...)

Automated regression testing in Java with Selenium IDE, Selenium WebDriver and Selenide

After an update it is often desirable to check whether existing features of an application are still working correctly. This process is called ‘regression testing’. Several tools can be used to automate this process. This blog will focus on Selenium IDE, Selenium WebDriver and Selenide which can be used for front-end/ black-box testing of browserapplications.

Selenium IDE

Selenium IDE is a Firefox plugin which can be used to record interactions with a web application. After (more...)

A very simple implementation of Suite to make it easy to run across a bunch of test machines at the same time.

So I was presented with a large suite that I need to distribute amongst an arbitrary number of Hudson slaves. Now my first guess would be to hand balance this into N sub suites; but that would require on-going work and would need to change depending on the number of nodes. (We have a target of 30 minutes to run all tests in parallel which is going to take some machines)

@RunWith(Suite.class)
@Suite.SuiteClasses({
     (more...)

JavaScript and PeopleCode Array Parameters

I have been experimenting with scripting PeopleCode using JavaScript. This is possible because Java includes Mozilla's Rhino JavaScript engine. I took one of my experiments to OpenWorld 2015 which shows creating a Microsoft Excel Spreadsheet using POI and JavaScript. Here we are, a couple of weeks later, and I see this in the PeopleSoft OTN Discussion Forum: Java Exception: java.lang.reflect.InvocationTargetException: during call of java.lang.reflect.Method .invoke. Perfect! That is (more...)

Does Linux hate Java?

Recently, I have discovered a fancy bug affecting few version of Linux kernel. Without any warnings JVM just hangs in GC pause forever. Root cause is a improper memory access in kernel code. This post by Gil Tene gives a good technical explanation with deep emotional coloring.

While this bug is not JVM specific, there are few other multithreaded processes you can find on typical Linux box.

This recent bug make me remember few other (more...)

PeopleSoft Streams from Oracle University

In February of this year, Oracle University launched the PeopleSoft Learning Stream. Oracle's Learning Streams are short, educational vignettes. I was given the privilege of recording 6 streams:

  • Using JavaScript with Pagelet Wizard is a 21 minute video showing you how to use Pagelet Wizard to convert a PeopleSoft query into an interactive D3 chart, a navigation collection into a carousel, a navigation collection into an accordion, and RequireJS for JavaScript dependency management.
  • REST Query (more...)

Batch processing in JEE7 (JSR 352)

A new feature in JEE7 is Batch Processing, an implementation of JSR 352 based on the programming model of Spring Batch. With batch processing, we understand the execution of a series of jobs (steps) , sequential or in parallel, without any user interaction. In this blog, we want to give a small overview of the capabilities of this new feature.
The code of this blog can be downloaded from here.
The zip file contains an Eclipse (more...)

JavaScript on the App Server: Scripting PeopleCode

It has been nearly a decade since I started playing with JavaScript on the PeopleSoft application server. Back then I had to deploy a couple of JAR files to the app server. At that time, maintaining and deploying unmanaged files seemed more headache than benefit. Today Java provides full scripting support through the ScriptEngineManager and embedded Mozilla Rhino JavaScript script engine. Why would I want to script PeopleCode? Here are a few of my favorite (more...)

SJK – missing link in Java profiling tool chain

Sometimes it just happens. You have a bloated Java application at your hand and it does not perform well. You may have built this application yourself or just got it as it is now. It doesn't matter, thing is - you do not have a slightest idea what is wrong here.

Java ecosystem have abundance of diagnostic tools (thank for interfaces exposed at JVM itself), but they are mostly focused on some specific narrow kinds (more...)