Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Madan Jampani
2014-11-11 10:49:05 -0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f73fb040a3419da2d42669142f184575ab92c38e
f73fb040
1 parent
29a6a783
Added LockService interface.
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
0 deletions
core/api/src/main/java/org/onlab/onos/store/service/Lock.java
core/api/src/main/java/org/onlab/onos/store/service/LockEventListener.java
core/api/src/main/java/org/onlab/onos/store/service/LockService.java
core/api/src/main/java/org/onlab/onos/store/service/Lock.java
0 → 100644
View file @
f73fb04
package
org
.
onlab
.
onos
.
store
.
service
;
/**
* A lock is a tool for controlling access to a shared resource by multiple processes.
* Commonly, a lock provides exclusive access to a resource such as a network device
* or exclusive permission to a controller to perform a particular role such as serve
* as the master controller for a device.
* At any given time one and only process can acquire the lock.
*/
public
interface
Lock
{
/**
* Acquires the lock.
* If the lock is not available then the caller thread becomes
* disabled for thread scheduling purposes and lies dormant until
* the lock has been acquired.
* <p>
* Locks are reentrant. A thread invoking this method multiple times
* without an intervening unlock or lease expiration must invoke unlock()
* the same number of times before the lock is released (unless the lease expires).
* When this method is invoked for a lock that is already acquired,
* the lease time will be set to the maximum of the remaining lease time
* from the previous invocation, or leaseDurationMillis.
* @param leaseDurationMillis the number of milliseconds to hold the
* lock after granting it, before automatically releasing it if it hasn't
* already been released by invoking unlock(). Must be in the range
* (0, MAX_LEASE_MILLIS]
*/
void
lock
(
long
leaseDurationMillis
);
/**
* Acquires the lock only if it is free at the time of invocation.
* @param leaseDurationMillis the number of milliseconds the must be
* locked after it is granted, before automatically releasing it if it hasn't
* already been released by an invocation of unlock(). Must be in the range
* (0, MAX_LEASE_MILLIS]
* @return true if the lock was acquired and false otherwise
*/
boolean
tryLock
(
long
leaseDurationMillis
);
/**
* Acquires the lock if it is free within the given waiting
* time and the current thread has not been interrupted.
* @param waitTimeMillis the maximum time (in milliseconds) to wait for the lock
* @param leaseDurationMillis the number of milliseconds to hold the
* lock after granting it, before automatically releasing it if it hasn't
* already been released by invoking unlock(Object). Must be in the range
* (0, MAX_LEASE_MILLIS]
* @return true if the lock was acquired and false if the waiting time
* elapsed before the lock was acquired
*/
boolean
tryLock
(
long
waitTimeMillis
,
long
leaseDurationMillis
);
/**
* Returns true if this Lock instance currently holds the lock.
* @return true if this instance is the owner of the lock.
*/
boolean
isLocked
();
/**
* Releases the lock.
*/
void
unlock
();
/**
* Extends the lease for this lock.
* @param extensionDurationMillis is the amount of additional
* time to add to the end of the current expiration time. For example,
* if the lock is currently set to expire at time T, a successful call to
* extendLease with an argument of 5000 will cause the lock to
* now expire at 5 seconds past T.
* @return true if the extension is successful, false otherwise. Note
* that a failure to extend the lease does not result in unlocking. The lock
* will be released either by an explicit call to unlock or when previously
* acquired lease runs out.
*/
boolean
extendLease
(
long
extensionDurationMillis
);
}
\ No newline at end of file
core/api/src/main/java/org/onlab/onos/store/service/LockEventListener.java
0 → 100644
View file @
f73fb04
package
org
.
onlab
.
onos
.
store
.
service
;
/**
* Listener for lock events.
*/
public
interface
LockEventListener
{
/**
* Notifies the listener of a lock's lease expiration event.
* @param lock lock whose lease has expired.
*/
void
leaseExpired
(
Lock
lock
);
}
core/api/src/main/java/org/onlab/onos/store/service/LockService.java
0 → 100644
View file @
f73fb04
package
org
.
onlab
.
onos
.
store
.
service
;
public
interface
LockService
{
/**
* Create a new lock instance.
* A successful return from this method does not mean the resource guarded by the path is locked.
* The caller is expect to call Lock.lock() to acquire the lock.
* @param path unique lock name.
* @return
*/
Lock
create
(
String
path
);
/**
* Adds a listener to be notified of lock events.
* @param listener listener to be added.
*/
void
addListener
(
LockEventListener
listener
);
/**
* Removes a listener that was previously added.
* @param listener listener to be removed.
*/
void
removeListener
(
LockEventListener
listener
);
}
\ No newline at end of file
Please
register
or
login
to post a comment