Image by Winter

Recently, I published a post of an application called WitsGenerator to provide random Wits data through a TCP port. Today I’m publishing another application related to the Oil & Gas business, but now it’s to count the amount of parameters being transmitted through Wits.

For this project, I’m using:

This code is also available in my GitHub page. Feel free to comment if you have any doubt or suggestion. 😄


This software is licensed under the MIT license, what basically means that you can use it for any purpose without any warranty. ⚠️


This simple application provides 2 different information:



The application works as an implementation of Producer-Consumer over a matrix data structure. This matrix works as a memory and each cell of this matrix represents, in any given moment, the amount of record-item received for that position since last matrix clean up. If the number 3 is found in the position 0x0, it means that the record 1 item 1 was received 3 times since the last matrix clean up. If the number 2 is found in the position 9x3, it means that the record 10 item 4 was received 2 times since the last matrix clean up. To count the total amount of items received in a given moment, it’s necessary to do a big sum of all the values present in the matrix. To count the number of unique items received in a given moment, it’s necessary to do a sum of the number of cells which values differs to 0. This matrix is based in the type byte, that offers good sizing for big amount of time, and, at the same time, is cheaper in terms of memory.

The Producer-Consumer aspect comes from the way the matrix is used: one thread keeps reading data from the Wits server and adds into the matrix, while another thread, from time to time, counts the total and unique values in the matrix and cleans it up.

Thus, there are 5 important classes:

The usage is as follow:

{% highlight text %} Usage: java -jar wits-counter-1.1.jar [host] [port] [interval] Connects to a Wits server through TCP Socket and prints the number of parameters being received per time interval. It does not reconnect if the connection fails. [host] The IP of hostname of the server [port] The port of the server [interval] The time interval, in milliseconds, to aggregate values. If less or equal 0, 1000 is used. {% endhighlight %}

When executed, it will start a TCP Client socket client to the data provider, and will start counting the parameters being received. No major treatment is done in the inputs, so you may have errors when wrong/unreal parameters are passed.


I’m not attaching here the Main.class. If necessary, visit my GitHub page.

Tags: java  O&G 
comments powered by Disqus