Skip to content

Commit

Permalink
Moved LuceneKernelExtension out of the public API
Browse files Browse the repository at this point in the history
  • Loading branch information
klaren committed Sep 12, 2017
1 parent b60fd09 commit 97bb264
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 22 deletions.
Expand Up @@ -22,52 +22,51 @@
import java.io.File;
import java.util.function.Supplier;

import org.neo4j.index.impl.lucene.explicit.LuceneIndexImplementation;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.kernel.spi.explicitindex.IndexProviders;

/**
* @deprecated removed in 4.0
*/
@Deprecated
public class LuceneKernelExtension extends LifecycleAdapter
{
private final File storeDir;
private final Config config;
private final Supplier<IndexConfigStore> indexStore;
private final FileSystemAbstraction fileSystemAbstraction;
private final IndexProviders indexProviders;
private final OperationalMode operationalMode;
private final org.neo4j.kernel.api.impl.index.LuceneKernelExtension delegate;

/**
* @deprecated removed in 4.0
*/
@Deprecated
public LuceneKernelExtension( File storeDir, Config config, Supplier<IndexConfigStore> indexStore,
FileSystemAbstraction fileSystemAbstraction, IndexProviders indexProviders )
{
this( storeDir, config, indexStore, fileSystemAbstraction, indexProviders, OperationalMode.single );
}

/**
* @deprecated removed in 4.0
*/
@Deprecated
public LuceneKernelExtension( File storeDir, Config config, Supplier<IndexConfigStore> indexStore,
FileSystemAbstraction fileSystemAbstraction, IndexProviders indexProviders, OperationalMode operationalMode )
{
this.storeDir = storeDir;
this.config = config;
this.indexStore = indexStore;
this.fileSystemAbstraction = fileSystemAbstraction;
this.indexProviders = indexProviders;
this.operationalMode = operationalMode;
delegate = new org.neo4j.kernel.api.impl.index.LuceneKernelExtension( storeDir, config, indexStore,
fileSystemAbstraction, indexProviders, operationalMode );
}

@Override
public void init()
{

LuceneIndexImplementation indexImplementation =
new LuceneIndexImplementation( storeDir, config, indexStore, fileSystemAbstraction, operationalMode );
indexProviders.registerIndexProvider( LuceneIndexImplementation.SERVICE_NAME, indexImplementation );
delegate.init();
}

@Override
public void shutdown()
{
indexProviders.unregisterIndexProvider( LuceneIndexImplementation.SERVICE_NAME );
delegate.shutdown();
}
}
Expand Up @@ -19,6 +19,10 @@
*/
package org.neo4j.index.lucene;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.neo4j.index.impl.lucene.explicit.LuceneIndexImplementation;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
Expand All @@ -28,19 +32,31 @@
import org.neo4j.kernel.lifecycle.Lifecycle;
import org.neo4j.kernel.spi.explicitindex.IndexProviders;

/**
* @deprecated removed in 4.0
*/
@Deprecated
public class LuceneKernelExtensionFactory extends KernelExtensionFactory<LuceneKernelExtensionFactory.Dependencies>
{
/**
* @deprecated removed in 4.0
*/
@Deprecated
public interface Dependencies
{
Config getConfig();

IndexProviders getIndexProviders();
org.neo4j.kernel.spi.legacyindex.IndexProviders getIndexProviders();

IndexConfigStore getIndexStore();

FileSystemAbstraction fileSystem();
}

/**
* @deprecated removed in 4.0
*/
@Deprecated
public LuceneKernelExtensionFactory()
{
super( LuceneIndexImplementation.SERVICE_NAME );
Expand All @@ -49,12 +65,39 @@ public LuceneKernelExtensionFactory()
@Override
public Lifecycle newInstance( KernelContext context, Dependencies dependencies ) throws Throwable
{
return new LuceneKernelExtension(
IndexProviders indexProvider = mimicClassWith( IndexProviders.class, dependencies.getIndexProviders() );
return new org.neo4j.kernel.api.impl.index.LuceneKernelExtension(
context.storeDir(),
dependencies.getConfig(),
dependencies::getIndexStore,
dependencies.fileSystem(),
dependencies.getIndexProviders(),
indexProvider,
context.databaseInfo().operationalMode );
}

/**
* Create a mimicking proxy since it's in the public API and can't be changed
*/
@SuppressWarnings( "unchecked" )
private static <T,F> T mimicClassWith( Class<T> clazz, F base )
{
return (T)Proxy.newProxyInstance( null, new Class<?>[]{clazz}, new MimicWrapper<>( base ) );
}

private static class MimicWrapper<F> implements InvocationHandler
{
private final F wrapped;

MimicWrapper( F wrapped )
{
this.wrapped = wrapped;
}

@Override
public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
{
Method match = wrapped.getClass().getMethod(method.getName(), method.getParameterTypes());
return match.invoke( wrapped, args);
}
}
}
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.api.impl.index;

import java.io.File;
import java.util.function.Supplier;

import org.neo4j.index.impl.lucene.explicit.LuceneIndexImplementation;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.OperationalMode;
import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.kernel.spi.explicitindex.IndexProviders;

public class LuceneKernelExtension extends LifecycleAdapter
{
private final File storeDir;
private final Config config;
private final Supplier<IndexConfigStore> indexStore;
private final FileSystemAbstraction fileSystemAbstraction;
private final IndexProviders indexProviders;
private final OperationalMode operationalMode;

public LuceneKernelExtension( File storeDir, Config config, Supplier<IndexConfigStore> indexStore,
FileSystemAbstraction fileSystemAbstraction, IndexProviders indexProviders, OperationalMode operationalMode )
{
this.storeDir = storeDir;
this.config = config;
this.indexStore = indexStore;
this.fileSystemAbstraction = fileSystemAbstraction;
this.indexProviders = indexProviders;
this.operationalMode = operationalMode;
}

@Override
public void init()
{

LuceneIndexImplementation indexImplementation =
new LuceneIndexImplementation( storeDir, config, indexStore, fileSystemAbstraction, operationalMode );
indexProviders.registerIndexProvider( LuceneIndexImplementation.SERVICE_NAME, indexImplementation );
}

@Override
public void shutdown()
{
indexProviders.unregisterIndexProvider( LuceneIndexImplementation.SERVICE_NAME );
}
}
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.api.impl.index;

import org.neo4j.index.impl.lucene.explicit.LuceneIndexImplementation;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.extension.KernelExtensionFactory;
import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.spi.KernelContext;
import org.neo4j.kernel.lifecycle.Lifecycle;
import org.neo4j.kernel.spi.explicitindex.IndexProviders;

public class LuceneKernelExtensionFactory extends KernelExtensionFactory<LuceneKernelExtensionFactory.Dependencies>
{
public interface Dependencies
{
Config getConfig();

IndexProviders getIndexProviders();

IndexConfigStore getIndexStore();

FileSystemAbstraction fileSystem();
}

public LuceneKernelExtensionFactory()
{
super( LuceneIndexImplementation.SERVICE_NAME );
}

@Override
public Lifecycle newInstance( KernelContext context, Dependencies dependencies ) throws Throwable
{
return new LuceneKernelExtension(
context.storeDir(),
dependencies.getConfig(),
dependencies::getIndexStore,
dependencies.fileSystem(),
dependencies.getIndexProviders(),
context.databaseInfo().operationalMode );
}
}
@@ -0,0 +1,17 @@
package org.neo4j.kernel.spi.legacyindex;


import org.neo4j.kernel.spi.explicitindex.IndexImplementation;

/**
* Registry of currently active index implementations. Indexing extensions should register the implementation
* here on startup, and unregister it on stop.
* @deprecated removed in 4.0
*/
@Deprecated
public interface IndexProviders
{
void registerIndexProvider( String name, IndexImplementation index );

boolean unregisterIndexProvider( String name );
}
@@ -1,3 +1,3 @@
org.neo4j.index.lucene.LuceneKernelExtensionFactory
org.neo4j.kernel.api.impl.index.LuceneKernelExtensionFactory
org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProviderFactory
org.neo4j.kernel.api.impl.schema.NativeLuceneFusionSchemaIndexProviderFactory

0 comments on commit 97bb264

Please sign in to comment.