public class ResourceGuard extends Object implements AutoCloseable, Serializable
acquireResource()
call. As a result of the call, each client gets a
ResourceGuard.Lease
. The close()
method of the lease releases the resources and reduces the client count in
the ResourceGuard
object.
The protected resource should only be disposed once the corresponding resource guard is successfully closed, but
the guard can only be closed once all clients that acquired a lease for the guarded resource have released it.
Before this is happened, the call to close()
will block until the zero-open-leases condition is triggered.
After the resource guard is closed, calls to acquireResource()
will fail with exception. Notice that,
obviously clients are responsible to release the resource after usage. All clients are considered equal, i.e. there
is only a global count maintained how many times the resource was acquired but not by whom.Modifier and Type | Class and Description |
---|---|
class |
ResourceGuard.Lease
A lease is issued by the
ResourceGuard as result of calls to acquireResource() . |
Constructor and Description |
---|
ResourceGuard() |
Modifier and Type | Method and Description |
---|---|
ResourceGuard.Lease |
acquireResource()
Acquired access from one new client for the guarded resource.
|
void |
close()
Closed the resource guard.
|
int |
getLeaseCount()
Returns the current count of open leases.
|
boolean |
isClosed()
Returns true if the resource guard is closed, i.e.
|
public ResourceGuard.Lease acquireResource() throws IOException
IOException
- when the resource guard is already closed.public void close()
acquireResource()
have seen their
matching call to releaseResource()
.close
in interface AutoCloseable
public boolean isClosed()
close()
was called.public int getLeaseCount()
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.