Madan Jampani

Removed lockservice and related classes since they provide no useful functionality at the moment.

Change-Id: I20bfb9aa6ede61ac813a464eceb946bcbc2b1bbb
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.service;
17 -
18 -import java.util.concurrent.CompletableFuture;
19 -
20 -/**
21 - * A lock is a tool for controlling access to a shared resource by multiple processes.
22 - * Commonly, a lock provides exclusive access to a resource such as a network device
23 - * or exclusive permission to a controller to perform a particular role such as serve
24 - * as the master controller for a device.
25 - * At any given time one and only process can acquire the lock.
26 - */
27 -public interface Lock {
28 -
29 - /**
30 - * Returns the path this lock will be used to guard from concurrent access.
31 - * @return path.
32 - */
33 - String path();
34 -
35 - /**
36 - * Acquires the lock.
37 - * If the lock is not available then the caller thread becomes
38 - * disabled for thread scheduling purposes and lies dormant until
39 - * the lock has been acquired.
40 - * <p>
41 - * Locks are reentrant. A thread invoking this method multiple times
42 - * without an intervening unlock or lease expiration must invoke unlock()
43 - * the same number of times before the lock is released (unless the lease expires).
44 - * When this method is invoked for a lock that is already acquired,
45 - * the lease time will be set to the maximum of the remaining lease time
46 - * from the previous invocation, or leaseDurationMillis.
47 - * @param leaseDurationMillis the number of milliseconds to hold the
48 - * lock after granting it, before automatically releasing it if it hasn't
49 - * already been released by invoking unlock(). Must be in the range
50 - * (0, LockManager.MAX_LEASE_MILLIS]
51 - * @throws InterruptedException if the thread is interrupted while waiting
52 - */
53 - void lock(int leaseDurationMillis) throws InterruptedException;
54 -
55 - /**
56 - * Acquires the lock asynchronously.
57 - * @param leaseDurationMillis leaseDurationMillis the number of milliseconds the lock
58 - * will be reserved before it becomes available for others.
59 - * @return Future that can be used for blocking until lock is acquired.
60 - */
61 - CompletableFuture<Void> lockAsync(int leaseDurationMillis);
62 -
63 - /**
64 - * Acquires the lock only if it is free at the time of invocation.
65 - * @param leaseDurationMillis the number of milliseconds the must be
66 - * locked after it is granted, before automatically releasing it if it hasn't
67 - * already been released by an invocation of unlock(). Must be in the range
68 - * (0, LockManager.MAX_LEASE_MILLIS]
69 - * @return true if the lock was acquired and false otherwise
70 - */
71 - boolean tryLock(int leaseDurationMillis);
72 -
73 - /**
74 - * Acquires the lock if it is free within the given waiting
75 - * time and the current thread has not been interrupted.
76 - * @param waitTimeMillis the maximum time (in milliseconds) to wait for the lock
77 - * @param leaseDurationMillis the number of milliseconds to hold the
78 - * lock after granting it, before automatically releasing it if it hasn't
79 - * already been released by invoking unlock(Object). Must be in the range
80 - * (0, LockManager.MAX_LEASE_MILLIS]
81 - * @return true if the lock was acquired and false if the waiting time
82 - * elapsed before the lock was acquired
83 - * @throws InterruptedException if the thread is interrupted while waiting
84 - */
85 - boolean tryLock(int waitTimeMillis, int leaseDurationMillis) throws InterruptedException;
86 -
87 - /**
88 - * Returns true if this Lock instance currently holds the lock.
89 - * @return true if this instance is the owner of the lock.
90 - */
91 - boolean isLocked();
92 -
93 - /**
94 - * Returns the epoch for this lock.
95 - * If this lock is currently locked i.e. isLocked() returns true, epoch signifies the logical time
96 - * when the lock was acquired. The concept of epoch lets one come up with a global ordering for all
97 - * lock acquisition events
98 - * @return epoch
99 - */
100 - long epoch();
101 -
102 - /**
103 - * Releases the lock.
104 - */
105 - void unlock();
106 -
107 - /**
108 - * Extends the expiration time for a lock that is currently owned
109 - * by a specified duration. The new expiration time is computed
110 - * by adding the specified duration to the current time. If this point
111 - * in time is earlier than the existing expiration time then this method
112 - * has no effect.
113 - * @param leaseDurationMillis extension duration.
114 - * @return true if successfully extended expiration, false if attempt to
115 - * extend expiration fails or if the path is currently not locked by this instance.
116 - */
117 - boolean extendExpiration(int leaseDurationMillis);
118 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.service;
17 -
18 -/**
19 - * Listener for lock events.
20 - */
21 -public interface LockEventListener {
22 -
23 - /**
24 - * Notifies the listener of a lock's lease expiration event.
25 - * @param lock lock whose lease has expired.
26 - */
27 - void leaseExpired(Lock lock);
28 -}
1 -/*
2 - * Copyright 2014 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.service;
17 -
18 -/**
19 - * Service interface for mutual exclusion primitives.
20 - */
21 -public interface LockService {
22 -
23 - /**
24 - * Creates a new lock instance.
25 - * A successful return from this method does not mean the resource guarded by the path is locked.
26 - * The caller is expected to call Lock.lock() to acquire the lock.
27 - * @param path unique lock name.
28 - * @return a Lock instance that can be used to acquire the lock.
29 - */
30 - Lock create(String path);
31 -
32 - /**
33 - * Adds a listener to be notified of lock events.
34 - * @param listener listener to be added.
35 - */
36 - void addListener(LockEventListener listener);
37 -
38 - /**
39 - * Removes a listener that was previously added.
40 - * @param listener listener to be removed.
41 - */
42 - void removeListener(LockEventListener listener);
43 -}