Sunday, December 7, 2014

Custom ThreadPoolExecutor based on spinlock approach.

      In one project we used ActiveMQ(JMS API) to communicate between business services and custom engine that worked asynchronously behind the scene to process financial data.
The flow to add/remove entity from ui was done as it usually organized in context of three-tier architecture: call to ui controller, route appropriate method, use service and then DAO to add/delete entity and then notify active mq corresponding consumers to process add/delete actions.

     But the issue was in the following: entity might be created in database, but not fully processed by engine while user tries to delete it from web interface.
It's not the issue on the  database side, this is multithreading synchronization question.

    I decided to use spin lock approach to sync two add/delete threads that did their work when the corresponding messages came to ActiveMQ queue.

    This is how JMS handler looks like. When message comes to queue it's then appropriate handled by  tickerEngineRequestProcessor, that is simply container for ThreadPoolExecutor performing tasks execution(add or delete one).

     Below is definition for tickerEngineRequestProcessor:
Let's now describe TickerTask, it just implemented Runnable interface to be processed within custom spin lock thread pool which I will describe further.

   The main idea in TickerEngineAddRemoveSyncThreadPoolExecutor is to perform spin iterations on thread that performs removing ticker while thread which adds ticker is not finished yet. This logic is placed in beforeExecute action. In afterExecute we just remove corresponding tickerId key from tickerIdsToAddInProgressState set.
   One more word about tickerIdsToAddInProgressState. This is ConcurrentHashSet that I choosed for storing state as per given tickerId, because we need to maintain sync add/remove operations based on the given tickerId and don't affect other tickers that might be processed at the same time. Thread.yield() is signal for threads scheduler to switch its work to other threads but the yielding thread can be scheduled back in one interrupt period later.






Tuesday, December 2, 2014

[mobile] How to overcome 'adb devices empty list' issue on Linux Mint 17

Recently I needed to install small  phonegap application with custom oauth2 authentication to my old htc desire.
It's not so big deal to run such applications on emulator devices via
phonegap run android,
But when I switched to the real device this caused some difficulties.
I work in Linux mint 17 and as it turned out adb devices is empty on this case.
After a little bit hacking and digging through internet I've found working solution.

1) type lsusb in shell and know vendor id: 
Device 007: ID 0bb4:0cb0 HTC (High Tech Computer Corp.)

So I see my old htc)
2) create 51-android.rules in /etc/udev/rules.d folder:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
3) Edited the adb_usb.ini file, added the 0x0bb4 
4) Enabled debugging on htc device(settings->developers)
And now list of devices is not empty!
List of devices attached HT15XTR04859 device
So we can run app on htc after that:

phonegap run android --device=HT15XTR04859






Monday, December 1, 2014

How To Fix NTFS Mount Issue In Linux Mint And Windows 8

After installing new Linux mint cinanmon 17 in dual bot with Windows 8 I'have faced with boring issue when mint could not mount disks belonging to Windows 8. The answer is this is because of Fast boot feature and it's might be simply resolved with turning off it from within Win 8. How?
Just follow this link for example :
http://itsfoss.com/solve-ntfs-mount-problem-ubuntu-windows-8-dual-boot/