Everybody needs semaphores. In the last couple of months I myself encounter 3 times the need to use semaphores.
Since my primary job is BizTalk – I need a semaphore solution for BTS.
Searching the net for open source semaphore solution results with such solutions, but (the best I found) limited to the current server running the application.
Since my production environment of BizTalk servers holding more than one server, these solutions don't work for me.
BizTalk has an option to use singleton as a mechanism to control resources. This is how to do it using singleton:
(Detailed instructions can be found here: http://aspalliance.com/1208_Singleton_Orchestration_in_BizTalk_Server.3)
Here is a picture of orchestration demonstrating this solution:
Challenges when using this way:
- Unable to limit the number of resources in case the number of resources is larger than 1.
- There is no easy way to trace direct binding ports, and therefore to debug errors in the mechanism.
- There is no accurate time to leave the singleton orchestration (how much time to set in the timeout hand).
- It might cause a zombies message (although it pretty rear) when a message coming to the MessageBox after timeout event already fired and orchestration still did not complete termination.
We found out a different way to handle the limited resource problem and to offer a solution for it.
How about using an adapter to get a semaphore?
In this way the solution is very simple.
Once configure the adapter, many resources can be managed, and number of items per resource can be defined.
Construct a message including the semaphore name and number of resource items need to be obtained (not only 1, but 1 is the default), and send a message to the adapter to get the semaphore. After getting it do the business process required the resource and then release the resource by sending the same message again to the adapter.
The next picture demonstrates the same operation using the semaphore adapter.
Shimshon Fishler