Skip to content

Commit

Permalink
Move entry points for bootstrappers into their own classes
Browse files Browse the repository at this point in the history
  • Loading branch information
benbc committed Mar 16, 2016
1 parent a86ad8e commit 0236e9c
Show file tree
Hide file tree
Showing 25 changed files with 207 additions and 123 deletions.
2 changes: 1 addition & 1 deletion community/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<neo4j.version>${project.version}</neo4j.version>
<neo4j-browser.version>1.0.1</neo4j-browser.version>

<neo4j-server.mainClass>org.neo4j.server.CommunityBootstrapper</neo4j-server.mainClass>
<neo4j-server.mainClass>org.neo4j.server.CommunityEntryPoint</neo4j-server.mainClass>
<neo-server.home>target/generated-resources/appassembler/jsw</neo-server.home>
<neo-server.confdir>target/test-classes/etc/neo-server</neo-server.confdir>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public BlockingBootstrapper( Bootstrapper wrapped )
public final int start( File configFile, Pair<String, String>... configOverrides )
{
int status = wrapped.start( configFile, configOverrides );
if ( status != BaseBootstrapper.OK )
if ( status != ServerBootstrapper.OK )
{
return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,11 @@

import static java.util.Arrays.asList;

public class CommunityBootstrapper extends BaseBootstrapper
public class CommunityBootstrapper extends ServerBootstrapper
{
public static final List<Class<?>> settingsClasses =
asList( ServerSettings.class, GraphDatabaseSettings.class, DatabaseManagementSystemSettings.class );

public static void main( String[] args )
{
int status = start( new CommunityBootstrapper(), args );
if ( status != 0 )
{
System.exit( status );
}
}

private static BlockingBootstrapper bootstrapper;

public static void start( String[] args )
{
bootstrapper = new BlockingBootstrapper( new CommunityBootstrapper() );
System.exit( start( bootstrapper, args ) );
}

public static void stop( @SuppressWarnings("UnusedParameters") String[] args )
{
if ( bootstrapper != null )
{
bootstrapper.stop();
}
}

@Override
protected NeoServer createNeoServer( Config config, GraphDatabaseDependencies dependencies,
LogProvider logProvider )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2002-2016 "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.server;

public class CommunityEntryPoint
{
private static BlockingBootstrapper bootstrapper;

public static void main( String[] args )
{
int status = ServerBootstrapper.start( new CommunityBootstrapper(), args );
if ( status != 0 )
{
System.exit( status );
}
}

public static void start( String[] args )
{
bootstrapper = new BlockingBootstrapper( new CommunityBootstrapper() );
System.exit( ServerBootstrapper.start( bootstrapper, args ) );
}

public static void stop( @SuppressWarnings("UnusedParameters") String[] args )
{
if ( bootstrapper != null )
{
bootstrapper.stop();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import static org.neo4j.server.configuration.ServerSettings.SERVER_CONFIG_FILE;
import static org.neo4j.server.configuration.ServerSettings.SERVER_CONFIG_FILE_KEY;

public abstract class BaseBootstrapper implements Bootstrapper
public abstract class ServerBootstrapper implements Bootstrapper
{
public static final int OK = 0;
public static final int WEB_SERVER_STARTUP_ERROR_CODE = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract class BaseBootstrapperTest extends ExclusiveServerTestBase
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

protected BaseBootstrapper bootstrapper;
protected ServerBootstrapper bootstrapper;

@Before
public void before() throws IOException
Expand All @@ -69,7 +69,7 @@ public void after()
}
}

protected abstract BaseBootstrapper newBootstrapper() throws IOException;
protected abstract ServerBootstrapper newBootstrapper() throws IOException;

protected abstract void start( String[] args );

Expand All @@ -79,7 +79,7 @@ public void after()
public void shouldStartStopNeoServerWithoutAnyConfigFiles() throws IOException
{
// When
int resultCode = BaseBootstrapper.start( bootstrapper,
int resultCode = ServerBootstrapper.start( bootstrapper,
"-c", configOption( data_directory, tempDir.getRoot().getAbsolutePath() ),
"-c", configOption( auth_store, tempDir.newFile().getAbsolutePath() ),
"-c", configOption( tls_certificate_file,
Expand All @@ -90,7 +90,7 @@ public void shouldStartStopNeoServerWithoutAnyConfigFiles() throws IOException
);

// Then
assertEquals( BaseBootstrapper.OK, resultCode );
assertEquals( ServerBootstrapper.OK, resultCode );
assertEventually( "Server was not started", bootstrapper::isRunning, is( true ), 1, TimeUnit.MINUTES );
}

Expand All @@ -102,10 +102,12 @@ public void canSpecifyConfigFile() throws Throwable

Map<String, String> properties = stringMap( forced_kernel_id.name(), "ourcustomvalue" );
properties.putAll( ServerTestUtils.getDefaultRelativeProperties() );
properties.put( "dbms.connector.1.type", "HTTP" );
properties.put( "dbms.connector.1.enabled", "true" );
store( properties, configFile );

// When
BaseBootstrapper.start( bootstrapper, "-C", configFile.getAbsolutePath() );
ServerBootstrapper.start( bootstrapper, "-C", configFile.getAbsolutePath() );

// Then
assertThat( bootstrapper.getServer().getConfig().get( forced_kernel_id ), equalTo( "ourcustomvalue" ) );
Expand All @@ -119,10 +121,12 @@ public void canOverrideConfigValues() throws Throwable

Map<String, String> properties = stringMap( forced_kernel_id.name(), "thisshouldnotshowup" );
properties.putAll( ServerTestUtils.getDefaultRelativeProperties() );
properties.put( "dbms.connector.1.type", "HTTP" );
properties.put( "dbms.connector.1.enabled", "true" );
store( properties, configFile );

// When
BaseBootstrapper.start( bootstrapper,
ServerBootstrapper.start( bootstrapper,
"-C", configFile.getAbsolutePath(),
"-c", configOption( forced_kernel_id, "mycustomvalue" ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
public class CommunityBootstrapperTest extends BaseBootstrapperTest
{
@Override
protected BaseBootstrapper newBootstrapper()
protected ServerBootstrapper newBootstrapper()
{
return new CommunityBootstrapper();
}

@Override
protected void start(String[] args)
{
CommunityBootstrapper.start( args );
CommunityEntryPoint.start( args );
}

@Override
protected void stop(String[] args)
{
CommunityBootstrapper.stop( args );
CommunityEntryPoint.stop( args );
}
}
2 changes: 1 addition & 1 deletion enterprise/server-enterprise/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<bundle.namespace>org.neo4j.server.enterprise</bundle.namespace>
<short-name>server-enterprise</short-name>
<version-package>server.enterprise</version-package>
<neo4j-server.mainClass>org.neo4j.server.enterprise.EnterpriseBootstrapper</neo4j-server.mainClass>
<neo4j-server.mainClass>org.neo4j.server.enterprise.EnterpriseEntryPoint</neo4j-server.mainClass>
<neo-server.home>target/generated-resources/appassembler/jsw</neo-server.home>
<neo-server.confdir>target/test-classes/etc/neo-server</neo-server.confdir>
<felix-fileinstall.version>3.0.2</felix-fileinstall.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.neo4j.kernel.monitoring.Monitors;
import org.neo4j.logging.FormattedLogProvider;
import org.neo4j.server.Bootstrapper;
import org.neo4j.server.configuration.ServerSettings;

import static org.neo4j.helpers.Exceptions.peel;

Expand All @@ -55,32 +54,6 @@ public class ArbiterBootstrapper implements Bootstrapper, AutoCloseable
private final LifeSupport life = new LifeSupport();
private final Timer timer = new Timer( true );

public static void main( String[] args ) throws IOException
{
int status = new ArbiterBootstrapper().start( getConfigFile() );
if ( status != 0 )
{
System.exit( status );
}
}

static File getConfigFile()
{
String configPath = System.getProperty( ServerSettings.SERVER_CONFIG_FILE_KEY );
if ( configPath == null )
{
throw new RuntimeException( "System property " + ServerSettings.SERVER_CONFIG_FILE_KEY +
" must be provided" );
}

File configFile = new File( configPath );
if ( !configFile.exists() )
{
throw new IllegalArgumentException( configFile + " doesn't exist" );
}
return configFile;
}

@SafeVarargs
@Override
public final int start( File configFile, Pair<String, String>... configOverrides )
Expand Down Expand Up @@ -132,6 +105,7 @@ public void close()
stop();
}

@SafeVarargs
private static Config getConfig( File configFile, Pair<String, String>... configOverrides )
{
Map<String, String> config = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2002-2016 "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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.server.enterprise;

import java.io.File;
import java.io.IOException;

import org.neo4j.server.configuration.ServerSettings;

public class ArbiterEntryPoint
{
public static void main( String[] args ) throws IOException
{
int status = new ArbiterBootstrapper().start( getConfigFile() );
if ( status != 0 )
{
System.exit( status );
}
}

static File getConfigFile()
{
String configPath = System.getProperty( ServerSettings.SERVER_CONFIG_FILE_KEY );
if ( configPath == null )
{
throw new RuntimeException( "System property " + ServerSettings.SERVER_CONFIG_FILE_KEY +
" must be provided" );
}

File configFile = new File( configPath );
if ( !configFile.exists() )
{
throw new IllegalArgumentException( configFile + " doesn't exist" );
}
return configFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.ha.HaSettings;
import org.neo4j.logging.LogProvider;
import org.neo4j.server.BlockingBootstrapper;
import org.neo4j.server.CommunityBootstrapper;
import org.neo4j.server.NeoServer;

Expand All @@ -37,31 +36,6 @@

public class EnterpriseBootstrapper extends CommunityBootstrapper
{
public static void main( String[] args )
{
int exit = start( new EnterpriseBootstrapper(), args );
if ( exit != 0 )
{
System.exit( exit );
}
}

private static BlockingBootstrapper bootstrapper;

public static void start( String[] args )
{
bootstrapper = new BlockingBootstrapper( new EnterpriseBootstrapper() );
System.exit( start( bootstrapper, args ) );
}

public static void stop( @SuppressWarnings("UnusedParameters") String[] args )
{
if ( bootstrapper != null )
{
bootstrapper.stop();
}
}

@Override
protected NeoServer createNeoServer( Config configurator, GraphDatabaseDependencies dependencies, LogProvider
userLogProvider )
Expand Down

0 comments on commit 0236e9c

Please sign in to comment.