Skip to content

Commit

Permalink
Add util method to create Lifecycle that only has shutdown action
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed Jul 31, 2018
1 parent c73ce3b commit c94da31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.kernel.lifecycle;

import org.neo4j.function.ThrowingAction;

/**
* Adapter for Lifecycle interface. Subclass and override methods as needed
*/
Expand All @@ -43,4 +45,16 @@ public void stop() throws Throwable
public void shutdown() throws Throwable
{
}

public static Lifecycle onShutdown( ThrowingAction action )
{
return new LifecycleAdapter()
{
@Override
public void shutdown() throws Exception
{
action.apply();
}
};
}
}
Expand Up @@ -748,19 +748,14 @@ private Lifecycle lifecycleToTriggerCheckPointOnShutdown()
// Write new checkpoint in the log only if the kernel is healthy.
// We cannot throw here since we need to shutdown without exceptions,
// so let's make the checkpointing part of the life, so LifeSupport can handle exceptions properly
return new LifecycleAdapter()
return LifecycleAdapter.onShutdown( () ->
{
@Override
public void shutdown() throws IOException
if ( databaseHealth.isHealthy() )
{
if ( databaseHealth.isHealthy() )
{
// Flushing of neo stores happens as part of the checkpoint
transactionLogModule.checkPointing()
.forceCheckPoint( new SimpleTriggerInfo( "database shutdown" ) );
}
// Flushing of neo stores happens as part of the checkpoint
transactionLogModule.checkPointing().forceCheckPoint( new SimpleTriggerInfo( "database shutdown" ) );
}
};
} );
}

public StoreId getStoreId()
Expand Down
Expand Up @@ -43,11 +43,11 @@
import org.neo4j.kernel.impl.util.Listener;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.kernel.lifecycle.LifeSupport;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.logging.FormattedLogProvider;
import org.neo4j.tools.console.input.ArgsCommand;
import org.neo4j.tools.console.input.ConsoleInput;

import static org.neo4j.kernel.lifecycle.LifecycleAdapter.onShutdown;
import static org.neo4j.tools.console.input.ConsoleUtil.NO_PROMPT;
import static org.neo4j.tools.console.input.ConsoleUtil.oneCommand;
import static org.neo4j.tools.console.input.ConsoleUtil.staticPrompt;
Expand Down Expand Up @@ -224,14 +224,7 @@ public String toString()
return "Runs consistency check on the database for data that has been applied up to this point";
}
} );
life.add( new LifecycleAdapter()
{
@Override
public void shutdown()
{
store.get().shutdown();
}
} );
life.add( onShutdown( () -> store.get().shutdown() ) );
return consoleInput;
}
}

0 comments on commit c94da31

Please sign in to comment.