1
package org.apache.lucene.store;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import java.io.IOException;
22
public class MockLockFactoryWrapper extends LockFactory {
23
MockDirectoryWrapper dir;
26
public MockLockFactoryWrapper(MockDirectoryWrapper dir, LockFactory delegate) {
28
this.delegate = delegate;
32
public void setLockPrefix(String lockPrefix) {
33
delegate.setLockPrefix(lockPrefix);
37
public String getLockPrefix() {
38
return delegate.getLockPrefix();
42
public Lock makeLock(String lockName) {
43
return new MockLock(delegate.makeLock(lockName), lockName);
47
public void clearLock(String lockName) throws IOException {
48
delegate.clearLock(lockName);
49
dir.openLocks.remove(lockName);
53
public String toString() {
54
return "MockLockFactoryWrapper(" + delegate.toString() + ")";
57
private class MockLock extends Lock {
58
private Lock delegateLock;
61
MockLock(Lock delegate, String name) {
62
this.delegateLock = delegate;
67
public boolean obtain() throws IOException {
68
if (delegateLock.obtain()) {
69
dir.openLocks.add(name);
77
public void release() throws IOException {
78
delegateLock.release();
79
dir.openLocks.remove(name);
83
public boolean isLocked() throws IOException {
84
return delegateLock.isLocked();