LibraryLink ToToggle FramesPrintFeedback

File Locking

It is possible to have multiple instances of a poller endpoint attempting to read a file on the system. To ensure that there are no conflicts in accessing the file, poller endpoints obtain an exclusive lock on a file while it is processing it.

The locking behavior is controlled by an implementation of the org.apache.servicemix.locks.LockManager interface. By default, poller endpoints use a provided implementation of this interface. If the default behavior is not appropriate for your application, you can implement the LockManager interface and configure your endpoints to use your implementation.

To implement a custom lock manager you need to provide your own implementation of the org.apache.servicemix.locks.LockManager interface. The LockManager has single method, getLock() that needs to be implemented. Example 2.7 shows the signature for getLock().


The getLock() method takes a string that represents the URI of the file being processes and it returns a java.util.concurrent.locks.Lock object. The returned Lock object holds the lock for the specified file.

Example 2.8 shows a simple lock manager implementation.


You configure a poller endpoint to use a custom lock manager using its lockManager attribute. The lockManager attribute's value is a reference to a bean element specifying the class of your custom lock manager implementation.

Example 2.9 shows configuration for a poller endpoint that uses a custom lock manager.


[Note]Note

You can also configure a poller endpoint to use a custom lock manager by adding a child lockManager element to the endpoint's configuration. The lockManager element simply wraps the bean element that configures the lock manager.