List of usage examples for org.apache.lucene.store Lock Lock
Lock
From source file:cc.solr.lucene.store.lock.BlurLockFactory.java
License:Apache License
@Override public Lock makeLock(String lockName) { final Path lockPath = new Path(_dir, lockName); return new Lock() { private boolean _set; @Override/*from w w w . j av a 2 s . com*/ public boolean obtain() throws IOException { if (_set) { throw new IOException("Lock for [" + _baseLockKey + "] can only be set once."); } try { _lockKey = (_baseLockKey + "/" + System.currentTimeMillis()).getBytes(); FSDataOutputStream outputStream = _fileSystem.create(lockPath, true); outputStream.write(_lockKey); outputStream.close(); } finally { _set = true; } return true; } @Override public void release() throws IOException { _fileSystem.delete(lockPath, false); } @Override public boolean isLocked() throws IOException { if (!_set) { return false; } if (!_fileSystem.exists(lockPath)) { return false; } FileStatus fileStatus = _fileSystem.getFileStatus(lockPath); long len = fileStatus.getLen(); if (len != _lockKey.length) { return false; } byte[] buf = new byte[_lockKey.length]; FSDataInputStream inputStream = _fileSystem.open(lockPath); inputStream.readFully(buf); inputStream.close(); if (Arrays.equals(_lockKey, buf)) { return true; } return false; } }; }
From source file:cc.wikitools.lucene.hadoop.FileSystemDirectory.java
License:Apache License
public Lock makeLock(final String name) { return new Lock() { public boolean obtain() { return true; }//www . j a va 2 s. c o m public void release() { } public boolean isLocked() { throw new UnsupportedOperationException(); } public String toString() { return "Lock@" + new Path(directory, name); } }; }
From source file:com.bah.lucene.hdfs.BlurLockFactory.java
License:Apache License
@Override public Lock makeLock(String lockName) { final Path lockPath = new Path(_dir, lockName); return new Lock() { private boolean _set; @Override//from w w w. j ava2 s .co m public boolean obtain() throws IOException { if (_set) { throw new IOException("Lock for [" + _baseLockKey + "] can only be set once."); } try { _lockKey = (_baseLockKey + "/" + System.currentTimeMillis()).getBytes(); FSDataOutputStream outputStream = _fileSystem.create(lockPath, true); outputStream.write(_lockKey); outputStream.close(); } finally { _set = true; } return true; } @Override public void release() throws IOException { _fileSystem.delete(lockPath, false); } @Override public boolean isLocked() throws IOException { if (!_set) { LOG.info("The lock has NOT been set."); return false; } if (!_fileSystem.exists(lockPath)) { LOG.info("The lock file has been removed."); return false; } FileStatus fileStatus = _fileSystem.getFileStatus(lockPath); long len = fileStatus.getLen(); if (len != _lockKey.length) { LOG.info("The lock file length has changed."); return false; } byte[] buf = new byte[_lockKey.length]; FSDataInputStream inputStream = _fileSystem.open(lockPath); inputStream.readFully(buf); inputStream.close(); if (Arrays.equals(_lockKey, buf)) { return true; } LOG.info("The lock information has been changed."); return false; } }; }
From source file:com.svenjacobs.lugaene.GaeLockFactory.java
License:Apache License
@Override public Lock makeLock(final String lockName) { return new Lock() { @Override//from w w w. j a v a2s .c om public boolean obtain() throws IOException { GaeLockEntity lock = loadLock(lockName); if (lock != null) { if (lock.locked) { return false; } lock.locked = true; ofy().save().entity(lock).now(); return true; } else { lock = new GaeLockEntity(directory, lockName); lock.locked = true; ofy().save().entity(lock).now(); return true; } } @Override public void release() throws IOException { final GaeLockEntity lock = loadLock(lockName); if (lock != null) { lock.locked = false; ofy().save().entity(lock).now(); } } @Override public boolean isLocked() throws IOException { final GaeLockEntity lock = loadLock(lockName); return lock != null && lock.locked; } }; }
From source file:com.xiaomi.linden.hadoop.indexing.reduce.FileSystemDirectory.java
License:Apache License
@Override public Lock makeLock(final String name) { return new Lock() { @Override/*from w ww .ja v a2 s.c o m*/ public boolean obtain() { return true; } @Override public void close() throws IOException { } @Override public boolean isLocked() { throw new UnsupportedOperationException(); } @Override public String toString() { return "Lock@" + new Path(directory, name); } }; }
From source file:org.apache.blur.index.OptimisticLockFactory.java
License:Apache License
@Override public Lock makeLock(String lockName) { final Path lockPath = new Path(_dir, lockName); return new Lock() { private boolean _set; @Override/*from ww w.j a v a2s. c o m*/ public boolean obtain() throws IOException { Tracer trace = Trace.trace("filesystem - release", Trace.param("lockPath", lockPath)); try { if (_set) { throw new IOException("Lock for [" + _baseLockKey + "] can only be set once."); } try { _lockKey = (_baseLockKey + "/" + System.currentTimeMillis()).getBytes(); FSDataOutputStream outputStream = _fileSystem.create(lockPath, true); outputStream.write(_lockKey); outputStream.close(); } finally { _set = true; } return true; } finally { trace.done(); } } @Override public void release() throws IOException { Tracer trace = Trace.trace("filesystem - release", Trace.param("lockPath", lockPath)); try { _fileSystem.delete(lockPath, false); } finally { trace.done(); } } @Override public boolean isLocked() throws IOException { Tracer trace = Trace.trace("filesystem - isLocked", Trace.param("lockPath", lockPath)); try { if (!_set) { return false; } if (!_fileSystem.exists(lockPath)) { return false; } FileStatus fileStatus = _fileSystem.getFileStatus(lockPath); long len = fileStatus.getLen(); if (len != _lockKey.length) { return false; } byte[] buf = new byte[_lockKey.length]; FSDataInputStream inputStream = _fileSystem.open(lockPath); inputStream.readFully(buf); inputStream.close(); if (Arrays.equals(_lockKey, buf)) { return true; } return false; } finally { trace.done(); } } }; }
From source file:org.apache.mahout.text.ReadOnlyFileSystemDirectory.java
License:Apache License
@Override public Lock makeLock(final String name) { return new Lock() { public boolean obtain() { return true; }//from w w w . j a v a 2s. c om public void release() { } public boolean isLocked() { throw new UnsupportedOperationException(); } public String toString() { return "Lock@" + new Path(directory, name); } }; }
From source file:org.apache.nutch.indexer.FsDirectory.java
License:Apache License
public Lock makeLock(final String name) { return new Lock() { public boolean obtain() { try { fs.lock(new Path(directory, name), false); return true; } catch (IOException e) { return false; }//from w ww.ja v a 2 s . c om } public void release() { try { fs.release(new Path(directory, name)); } catch (IOException e) { throw new RuntimeException(e); } } public boolean isLocked() { throw new UnsupportedOperationException(); } public String toString() { return "Lock@" + new Path(directory, name); } }; }