Sunday, May 23, 2021

A simple pool leveraging guava cache and java concurrency apis

 A simple pool SimpleJschPool with no threads

I implemented recently a simple pool for the Jsch session leveraging guava cache and java concurrency APIs. Jsch is a tiny old library use by enterprises for mft/sftp files transfer. 

Jsch is not definitively a very convenient library but sometimes, as developers, using some specific tools is part of the job. 

This is irrelevant for the purpose of this sample demo project as the underlying solution is just a pool of something you don't want to create again and again.

  • 3 simple classes project. Comments welcome

https://github.com/bfayette/SimpleJschPool

I have tried common-pool which has the overhead of managing a threads pool.

Component of this solution

  • A Jsch Session Provider creates a new session when needed
  • A tickets Generator which provides unique ticket per request
  • A JVM cache (Guava) to save temporary the unique ChannelSft  per ticket
  • A semaphore to moderate tickets generation, hence channels allocation to requests
  • The ChannelSft is a non-thread-safe object so cannot be shared between threads. The semaphore helps us achieve this goal.



No comments:

Post a Comment