Example usage for org.apache.lucene.store NoLockFactory NoLockFactory

List of usage examples for org.apache.lucene.store NoLockFactory NoLockFactory

Introduction

In this page you can find the example usage for org.apache.lucene.store NoLockFactory NoLockFactory.

Prototype

private NoLockFactory() 

Source Link

Usage

From source file:com.nearinfinity.mele.store.db.MeleDirectory.java

License:Apache License

public MeleDirectory(MeleDirectoryStore store, BLOCK_SIZE blockSize) {
    this.store = store;
    this.blockShift = blockSize.getBlockShift();
    this.blockSize = blockSize.getBlockSize();
    this.blockMask = blockSize.getBlockMask();
    setLockFactory(new NoLockFactory());
}

From source file:com.sensei.indexing.hadoop.reduce.MixedDirectory.java

License:Apache License

public MixedDirectory(FileSystem readFs, Path readPath, FileSystem writeFs, Path writePath, Configuration conf)
        throws IOException {

    try {/*from www .  j a  v  a 2  s.  c  o  m*/
        readDir = new FileSystemDirectory(readFs, readPath, false, conf);
        // check writeFS is a local FS?
        writeDir = FSDirectory.open(new File(writePath.toString())); //FSDirectory.getDirectory(writePath.toString());

    } catch (IOException e) {
        try {
            close();
        } catch (IOException e1) {
            // ignore this one, throw the original one
        }
        throw e;
    }

    lockFactory = new NoLockFactory();
}

From source file:com.sensei.indexing.hadoop.reduce.MixedDirectory.java

License:Apache License

MixedDirectory(Directory readDir, Directory writeDir) throws IOException {
    this.readDir = readDir;
    this.writeDir = writeDir;

    lockFactory = new NoLockFactory();
}

From source file:org.apache.hadoop.contrib.index.lucene.MixedDirectory.java

License:Apache License

public MixedDirectory(FileSystem readFs, Path readPath, FileSystem writeFs, Path writePath, Configuration conf)
        throws IOException {

    try {/*from   www .  j  ava 2s .  c om*/
        readDir = new FileSystemDirectory(readFs, readPath, false, conf);
        // check writeFS is a local FS?
        writeDir = FSDirectory.getDirectory(writePath.toString());

    } catch (IOException e) {
        try {
            close();
        } catch (IOException e1) {
            // ignore this one, throw the original one
        }
        throw e;
    }

    lockFactory = new NoLockFactory();
}

From source file:org.compass.core.lucene.engine.store.AbstractLuceneSearchEngineStore.java

License:Apache License

private Directory openDirectoryBySubIndex(String subIndex, boolean create) throws SearchEngineException {
    Directory dir = doOpenDirectoryBySubIndex(subIndex, create);
    if (dir == null) {
        return null;
    }/*from   w w w  .j ava  2s .  c  om*/
    String lockFactoryType = luceneSettings.getSettings().getSetting(LuceneEnvironment.LockFactory.TYPE);
    if (lockFactoryType != null) {
        String path = luceneSettings.getSettings().getSetting(LuceneEnvironment.LockFactory.PATH);
        if (path != null) {
            path = StringUtils.replace(path, "#subindex#", subIndex);
        }
        LockFactory lockFactory;
        if (LuceneEnvironment.LockFactory.Type.NATIVE_FS.equalsIgnoreCase(lockFactoryType)) {
            String lockDir = path;
            if (lockDir == null) {
                lockDir = connectionString + "/" + subIndex;
            }
            try {
                lockFactory = new NativeFSLockFactory(lockDir);
            } catch (IOException e) {
                throw new SearchEngineException(
                        "Failed to create native fs lock factory with lock dir [" + lockDir + "]", e);
            }
            if (log.isDebugEnabled()) {
                log.debug("Using native fs lock for sub index [" + subIndex + "] and lock directory [" + lockDir
                        + "]");
            }
        } else if (LuceneEnvironment.LockFactory.Type.SIMPLE_FS.equalsIgnoreCase(lockFactoryType)) {
            String lockDir = path;
            if (lockDir == null) {
                lockDir = connectionString + "/" + subIndex;
            }
            try {
                lockFactory = new SimpleFSLockFactory(lockDir);
            } catch (IOException e) {
                throw new SearchEngineException(
                        "Failed to create simple fs lock factory with lock dir [" + lockDir + "]", e);
            }
            if (log.isDebugEnabled()) {
                log.debug("Using simple fs lock for sub index [" + subIndex + "] and lock directory [" + lockDir
                        + "]");
            }

        } else if (LuceneEnvironment.LockFactory.Type.SINGLE_INSTANCE.equalsIgnoreCase(lockFactoryType)) {
            lockFactory = new SingleInstanceLockFactory();
        } else if (LuceneEnvironment.LockFactory.Type.NO_LOCKING.equalsIgnoreCase(lockFactoryType)) {
            lockFactory = new NoLockFactory();
        } else {
            Object temp;
            try {
                temp = ClassUtils.forName(lockFactoryType, luceneSettings.getSettings().getClassLoader())
                        .newInstance();
            } catch (Exception e) {
                throw new SearchEngineException("Failed to create lock type [" + lockFactoryType + "]", e);
            }
            if (temp instanceof LockFactory) {
                lockFactory = (LockFactory) temp;
            } else if (temp instanceof LockFactoryProvider) {
                lockFactory = ((LockFactoryProvider) temp).createLockFactory(path, subIndex,
                        luceneSettings.getSettings());
            } else {
                throw new SearchEngineException("No specific type of lock factory");
            }

            if (lockFactory instanceof CompassConfigurable) {
                ((CompassConfigurable) lockFactory).configure(luceneSettings.getSettings());
            }
        }
        dir.setLockFactory(lockFactory);
    }
    if (directoryWrapperProviders != null) {
        for (DirectoryWrapperProvider directoryWrapperProvider : directoryWrapperProviders) {
            dir = directoryWrapperProvider.wrap(subIndex, dir);
        }
    }
    return localDirectoryCacheManager.createLocalCache(subIndex, dir);
}

From source file:org.compass.core.lucene.engine.store.DefaultLuceneSearchEngineStore.java

License:Apache License

public Directory openDirectory(String subContext, String subIndex) throws SearchEngineException {
    Map<String, Directory> subContextDirs = dirs.get(subContext);
    if (subContextDirs == null) {
        subContextDirs = new ConcurrentHashMap<String, Directory>();
        dirs.put(subContext, subContextDirs);
    }/*  w  w  w  .  j a v  a 2s. co  m*/
    Directory dir = subContextDirs.get(subIndex);
    if (dir != null) {
        return dir;
    }
    synchronized (subContextDirs) {
        dir = subContextDirs.get(subIndex);
        if (dir != null) {
            return dir;
        }
        dir = directoryStore.open(subContext, subIndex);
        Object lockFactoryType = settings.getSettingAsObject(LuceneEnvironment.LockFactory.TYPE);
        if (lockFactoryType != null) {
            String path = settings.getSetting(LuceneEnvironment.LockFactory.PATH);
            if (path != null) {
                path = StringUtils.replace(path, "#subindex#", subIndex);
                path = StringUtils.replace(path, "#subContext#", subContext);
            }
            LockFactory lockFactory;
            if (lockFactoryType instanceof String && LuceneEnvironment.LockFactory.Type.NATIVE_FS
                    .equalsIgnoreCase((String) lockFactoryType)) {
                String lockDir = path;
                if (lockDir == null) {
                    if (directoryStore instanceof FSDirectoryStore) {
                        lockDir = ((FSDirectoryStore) directoryStore).buildPath(subContext, subIndex);
                    } else {
                        lockDir = connectionString + "/" + subContext + "/" + subIndex;
                        if (lockDir.startsWith(FSDirectoryStore.PROTOCOL)) {
                            lockDir = lockDir.substring(FSDirectoryStore.PROTOCOL.length());
                        }
                    }
                }
                try {
                    lockFactory = new NativeFSLockFactory(lockDir);
                } catch (IOException e) {
                    throw new SearchEngineException(
                            "Failed to create native fs lock factory with lock dir [" + lockDir + "]", e);
                }
                if (log.isDebugEnabled()) {
                    log.debug("Using native fs lock for sub index [" + subIndex + "] and lock directory ["
                            + lockDir + "]");
                }
            } else if (lockFactoryType instanceof String && LuceneEnvironment.LockFactory.Type.SIMPLE_FS
                    .equalsIgnoreCase((String) lockFactoryType)) {
                String lockDir = path;
                if (lockDir == null) {
                    if (directoryStore instanceof FSDirectoryStore) {
                        lockDir = ((FSDirectoryStore) directoryStore).buildPath(subContext, subIndex);
                    } else {
                        lockDir = connectionString + "/" + subContext + "/" + subIndex;
                        if (lockDir.startsWith(FSDirectoryStore.PROTOCOL)) {
                            lockDir = lockDir.substring(FSDirectoryStore.PROTOCOL.length());
                        }
                    }
                }
                try {
                    lockFactory = new SimpleFSLockFactory(lockDir);
                } catch (IOException e) {
                    throw new SearchEngineException(
                            "Failed to create simple fs lock factory with lock dir [" + lockDir + "]", e);
                }
                if (log.isDebugEnabled()) {
                    log.debug("Using simple fs lock for sub index [" + subIndex + "] and lock directory ["
                            + lockDir + "]");
                }

            } else if (lockFactoryType instanceof String && LuceneEnvironment.LockFactory.Type.SINGLE_INSTANCE
                    .equalsIgnoreCase((String) lockFactoryType)) {
                lockFactory = new SingleInstanceLockFactory();
            } else if (lockFactoryType instanceof String && LuceneEnvironment.LockFactory.Type.NO_LOCKING
                    .equalsIgnoreCase((String) lockFactoryType)) {
                lockFactory = new NoLockFactory();
            } else {
                Object temp;
                if (lockFactoryType instanceof String) {
                    try {
                        temp = ClassUtils.forName((String) lockFactoryType, settings.getClassLoader())
                                .newInstance();
                    } catch (Exception e) {
                        throw new SearchEngineException("Failed to create lock type [" + lockFactoryType + "]",
                                e);
                    }
                } else {
                    temp = lockFactoryType;
                }

                if (temp instanceof LockFactory) {
                    lockFactory = (LockFactory) temp;
                } else if (temp instanceof LockFactoryProvider) {
                    lockFactory = ((LockFactoryProvider) temp).createLockFactory(path, subContext, subIndex,
                            settings);
                } else {
                    throw new SearchEngineException("No specific type of lock factory");
                }

                if (lockFactory instanceof CompassConfigurable) {
                    ((CompassConfigurable) lockFactory).configure(settings);
                }
            }
            dir.setLockFactory(lockFactory);
        }
        if (directoryWrapperProviders != null) {
            for (DirectoryWrapperProvider directoryWrapperProvider : directoryWrapperProviders) {
                dir = directoryWrapperProvider.wrap(subIndex, dir);
            }
        }
        if (!closed) {
            dir = localCacheManager.createLocalCache(subContext, subIndex, dir);
        }
        subContextDirs.put(subIndex, dir);
    }
    return dir;
}

From source file:org.elasticsearch.index.store.fs.FsStore.java

License:Apache License

protected LockFactory buildLockFactory() throws IOException {
    String fsLock = componentSettings.get("fs_lock", "native");
    LockFactory lockFactory = new NoLockFactory();
    if (fsLock.equals("native")) {
        // TODO LUCENE MONITOR: this is not needed in next Lucene version
        lockFactory = new NativeFSLockFactory() {
            @Override/*www .  j ava2 s. c om*/
            public void clearLock(String lockName) throws IOException {
                // Note that this isn't strictly required anymore
                // because the existence of these files does not mean
                // they are locked, but, still do this in case people
                // really want to see the files go away:
                if (lockDir.exists()) {

                    // Try to release the lock first - if it's held by another process, this
                    // method should not silently fail.
                    // NOTE: makeLock fixes the lock name by prefixing it w/ lockPrefix.
                    // Therefore it should be called before the code block next which prefixes
                    // the given name.
                    makeLock(lockName).release();

                    if (lockPrefix != null) {
                        lockName = lockPrefix + "-" + lockName;
                    }

                    // As mentioned above, we don't care if the deletion of the file failed.
                    new File(lockDir, lockName).delete();
                }
            }
        };
    } else if (fsLock.equals("simple")) {
        lockFactory = new SimpleFSLockFactory();
    }
    return lockFactory;
}