Skip to content

Commit

Permalink
Simplify dependency registration and module interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Dec 13, 2016
1 parent 8c21090 commit c585f3b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 103 deletions.
36 changes: 0 additions & 36 deletions community/kernel/src/main/java/org/neo4j/kernel/KernelModule.java

This file was deleted.

Expand Up @@ -21,8 +21,6 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.Clock;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -269,8 +267,8 @@ boolean applicable( DiagnosticsPhase phase )
private final AccessCapability accessCapability;

private StorageEngine storageEngine;
private TransactionLogModule transactionLogModule;
private KernelModule kernelModule;
private NeoStoreTransactionLogModule transactionLogModule;
private NeoStoreKernelModule kernelModule;

/**
* Note that the tremendous number of dependencies for this class, clearly, is an architecture smell. It is part
Expand Down Expand Up @@ -416,7 +414,6 @@ public void start() throws IOException
{
UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore( logProvider );

// TODO Introduce a StorageEngine abstraction at the StoreLayerModule boundary
SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering = new SynchronizedArrayIdOrderingQueue( 20 );

storageEngine = buildStorageEngine(
Expand All @@ -428,11 +425,11 @@ public void start() throws IOException

TransactionIdStore transactionIdStore = dependencies.resolveDependency( TransactionIdStore.class );
LogVersionRepository logVersionRepository = dependencies.resolveDependency( LogVersionRepository.class );
TransactionLogModule transactionLogModule =
NeoStoreTransactionLogModule transactionLogModule =
buildTransactionLogs( storeDir, config, logProvider, scheduler, fs,
storageEngine, logEntryReader, legacyIndexTransactionOrdering,
transactionIdStore, logVersionRepository );
satisfyDependencies( transactionLogModule);
transactionLogModule.satisfyDependencies(dependencies);

buildRecovery( fs,
transactionIdStore,
Expand All @@ -441,12 +438,13 @@ public void start() throws IOException
transactionLogModule.logFiles(), startupStatistics,
storageEngine, logEntryReader, transactionLogModule.logicalTransactionStore() );

final KernelModule kernelModule = buildKernel(
final NeoStoreKernelModule kernelModule = buildKernel(
transactionLogModule.transactionAppender(),
dependencies.resolveDependency( IndexingService.class ),
storageEngine.storeReadLayer(),
updateableSchemaState, dependencies.resolveDependency( LabelScanStore.class ),
storageEngine, indexConfigStore, transactionIdStore, availabilityGuard, clock );
kernelModule.satisfyDependencies( dependencies );

// Do these assignments last so that we can ensure no cyclical dependencies exist
this.storageEngine = storageEngine;
Expand All @@ -458,7 +456,6 @@ public void start() throws IOException
dependencies.satisfyDependency( storageEngine.storeReadLayer() );
dependencies.satisfyDependency( logEntryReader );
dependencies.satisfyDependency( storageEngine );
satisfyDependencies( kernelModule );
}
catch ( Throwable e )
{
Expand Down Expand Up @@ -570,7 +567,7 @@ private StorageEngine buildStorageEngine(
return life.add( storageEngine );
}

private TransactionLogModule buildTransactionLogs(
private NeoStoreTransactionLogModule buildTransactionLogs(
File storeDir,
Config config,
LogProvider logProvider,
Expand Down Expand Up @@ -679,7 +676,7 @@ public void recoveryCompleted( int numberOfRecoveredTransactions )
life.add( recovery );
}

private KernelModule buildKernel( TransactionAppender appender,
private NeoStoreKernelModule buildKernel( TransactionAppender appender,
IndexingService indexingService,
StoreReadLayer storeLayer,
UpdateableSchemaState updateableSchemaState, LabelScanStore labelScanStore,
Expand Down Expand Up @@ -725,28 +722,6 @@ private KernelModule buildKernel( TransactionAppender appender,
return new NeoStoreKernelModule( transactionCommitProcess, kernel, kernelTransactions, fileListing );
}

// We do this last to ensure no one is cheating with dependency access
private void satisfyDependencies( Object... modules )
{
for ( Object module : modules )
{
for ( Method method : module.getClass().getMethods() )
{
if ( !method.getDeclaringClass().equals( Object.class ) && method.getReturnType() != void.class )
{
try
{
dependencies.satisfyDependency( method.invoke( module ) );
}
catch ( IllegalAccessException | InvocationTargetException e )
{
throw new RuntimeException( e );
}
}
}
}
}

@Override
public synchronized void stop()
{
Expand All @@ -755,6 +730,8 @@ public synchronized void stop()
return;
}

//:TODO comments are obsolete need to be cleaned up

// First kindly await all committing transactions to close. Do this without interfering with the
// log file monitor. Keep in mind that at this point the availability guard is raised and some time spent
// awaiting active transaction to close, on a more coarse-grained level, so no new transactions
Expand Down
Expand Up @@ -24,8 +24,9 @@
import org.neo4j.kernel.impl.api.KernelTransactions;
import org.neo4j.kernel.impl.api.TransactionCommitProcess;
import org.neo4j.kernel.impl.transaction.state.NeoStoreFileListing;
import org.neo4j.kernel.impl.util.Dependencies;

class NeoStoreKernelModule implements KernelModule
class NeoStoreKernelModule
{
private final TransactionCommitProcess transactionCommitProcess;
private final Kernel kernel;
Expand All @@ -41,27 +42,23 @@ class NeoStoreKernelModule implements KernelModule
this.fileListing = fileListing;
}

@Override
public TransactionCommitProcess transactionCommitProcess()
{
return transactionCommitProcess;
}

@Override
public KernelAPI kernelAPI()
{
return kernel;
}

@Override
public KernelTransactions kernelTransactions()
KernelTransactions kernelTransactions()
{
return kernelTransactions;
}

@Override
public NeoStoreFileListing fileListing()
NeoStoreFileListing fileListing()
{
return fileListing;
}

public void satisfyDependencies( Dependencies dependencies )
{
dependencies.satisfyDependencies( transactionCommitProcess, kernel, kernelTransactions, fileListing );
}
}
Expand Up @@ -27,10 +27,10 @@
import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer;
import org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointerImpl;
import org.neo4j.kernel.impl.transaction.log.rotation.LogRotation;
import org.neo4j.kernel.impl.util.IdOrderingQueue;
import org.neo4j.kernel.impl.util.Dependencies;
import org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue;

class NeoStoreTransactionLogModule implements TransactionLogModule
class NeoStoreTransactionLogModule
{
private final LogicalTransactionStore logicalTransactionStore;
private final LogFileInformation logFileInformation;
Expand All @@ -56,51 +56,40 @@ class NeoStoreTransactionLogModule implements TransactionLogModule
this.legacyIndexTransactionOrdering = legacyIndexTransactionOrdering;
}

@Override
public LogicalTransactionStore logicalTransactionStore()
{
return logicalTransactionStore;
}

@Override
public LogFileInformation logFileInformation()
{
return logFileInformation;
}

@Override
public PhysicalLogFiles logFiles()
{
return logFiles;
}

@Override
public LogFile logFile()
{
return logFile;
}

@Override
public LogRotation logRotation()
{
return logRotation;
}

@Override
public CheckPointer checkPointing()
{
return checkPointer;
}

@Override
public TransactionAppender transactionAppender()
{
return appender;
}

@Override
public IdOrderingQueue legacyIndexTransactionOrderingQueue()
public void satisfyDependencies( Dependencies dependencies )
{
return legacyIndexTransactionOrdering;
dependencies.satisfyDependencies( checkPointer,
logFile,
logFiles,
logFileInformation,
legacyIndexTransactionOrdering,
logicalTransactionStore,
logRotation,
appender );
}
}

0 comments on commit c585f3b

Please sign in to comment.