3939import com .arcadedb .server .ha .HAServer ;
4040import com .arcadedb .server .ha .ReplicatedDatabase ;
4141import com .arcadedb .server .http .HttpServer ;
42+ import com .arcadedb .server .plugin .PluginManager ;
4243import com .arcadedb .server .security .ServerSecurity ;
4344import com .arcadedb .server .security .ServerSecurityException ;
4445import com .arcadedb .server .security .ServerSecurityUser ;
45- import com .arcadedb .server .plugin .PluginManager ;
4646import com .arcadedb .utility .CodeUtils ;
4747import com .arcadedb .utility .FileUtils ;
4848import com .arcadedb .utility .ServerPathUtils ;
5959import java .io .IOException ;
6060import java .io .InputStream ;
6161import java .lang .reflect .InvocationTargetException ;
62- import java .util .*;
62+ import java .util .ArrayList ;
63+ import java .util .Collection ;
64+ import java .util .Collections ;
65+ import java .util .LinkedHashMap ;
66+ import java .util .LinkedHashSet ;
67+ import java .util .List ;
68+ import java .util .Locale ;
69+ import java .util .Map ;
70+ import java .util .Set ;
6371import java .util .concurrent .ConcurrentHashMap ;
6472import java .util .concurrent .ConcurrentMap ;
6573import java .util .logging .Level ;
@@ -77,15 +85,13 @@ public enum STATUS {OFFLINE, STARTING, ONLINE, SHUTTING_DOWN}
7785 private String hostAddress ;
7886 private final boolean replicationLifecycleEventsEnabled ;
7987 private FileServerEventLog eventLog ;
80- private final Map <String , ServerPlugin > plugins =
81- new LinkedHashMap <>();
88+ private final Map <String , ServerPlugin > plugins = new LinkedHashMap <>();
8289 private PluginManager pluginManager ;
8390 private String serverRootPath ;
8491 private HAServer haServer ;
8592 private ServerSecurity security ;
8693 private HttpServer httpServer ;
87- private final ConcurrentMap <String , ServerDatabase > databases =
88- new ConcurrentHashMap <>();
94+ private final ConcurrentMap <String , ServerDatabase > databases = new ConcurrentHashMap <>();
8995 private final List <ReplicationCallback > testEventListeners = new ArrayList <>();
9096 private volatile STATUS status = STATUS .OFFLINE ;
9197// private ServerMonitor serverMonitor;
@@ -175,8 +181,8 @@ public synchronized void start() {
175181 // START HTTP SERVER IMMEDIATELY. THE HTTP ADDRESS WILL BE USED BY HA
176182 httpServer = new HttpServer (this );
177183
178- registerPlugins (ServerPlugin .INSTALLATION_PRIORITY .BEFORE_HTTP_ON );
179- pluginManager .startPlugins (ServerPlugin .INSTALLATION_PRIORITY .BEFORE_HTTP_ON );
184+ // registerPlugins(ServerPlugin.PluginInstallationPriority .BEFORE_HTTP_ON);
185+ pluginManager .startPlugins (ServerPlugin .PluginInstallationPriority .BEFORE_HTTP_ON );
180186
181187 httpServer .startService ();
182188
@@ -185,16 +191,16 @@ public synchronized void start() {
185191 haServer .startService ();
186192 }
187193
188- registerPlugins (ServerPlugin .INSTALLATION_PRIORITY .AFTER_HTTP_ON );
189- pluginManager .startPlugins (ServerPlugin .INSTALLATION_PRIORITY .AFTER_HTTP_ON );
194+ // registerPlugins(ServerPlugin.PluginInstallationPriority .AFTER_HTTP_ON);
195+ pluginManager .startPlugins (ServerPlugin .PluginInstallationPriority .AFTER_HTTP_ON );
190196
191197 loadDefaultDatabases ();
192198
193199 // RELOAD DATABASE IF A PLUGIN REGISTERED A NEW DATABASE (LIKE THE GREMLIN SERVER)
194200 loadDatabases ();
195201
196- registerPlugins (ServerPlugin .INSTALLATION_PRIORITY .AFTER_DATABASES_OPEN );
197- pluginManager .startPlugins (ServerPlugin .INSTALLATION_PRIORITY .AFTER_DATABASES_OPEN );
202+ // registerPlugins(ServerPlugin.PluginInstallationPriority .AFTER_DATABASES_OPEN);
203+ pluginManager .startPlugins (ServerPlugin .PluginInstallationPriority .AFTER_DATABASES_OPEN );
198204
199205 status = STATUS .ONLINE ;
200206
@@ -293,7 +299,7 @@ private Set<String> getAllPluginNames() {
293299 return result ;
294300 }
295301
296- private void registerPlugins (final ServerPlugin .INSTALLATION_PRIORITY installationPriority ) {
302+ private void registerPlugins (final ServerPlugin .PluginInstallationPriority installationPriority ) {
297303 final String registeredPlugins = configuration .getValueAsString (GlobalConfiguration .SERVER_PLUGINS );
298304 if (registeredPlugins != null && !registeredPlugins .isEmpty ()) {
299305 final String [] pluginEntries = registeredPlugins .split ("," );
@@ -495,7 +501,7 @@ public String toString() {
495501 }
496502
497503 public ServerDatabase getDatabase (final String databaseName , final boolean createIfNotExists ,
498- final boolean allowLoad ) {
504+ final boolean allowLoad ) {
499505 if (databaseName == null || databaseName .trim ().isEmpty ())
500506 throw new IllegalArgumentException ("Invalid database name " + databaseName );
501507
@@ -516,7 +522,7 @@ public ServerDatabase getDatabase(final String databaseName, final boolean creat
516522
517523 ComponentFile .MODE defaultDbMode =
518524 configuration .getValueAsEnum (GlobalConfiguration .SERVER_DEFAULT_DATABASE_MODE ,
519- ComponentFile .MODE .class );
525+ ComponentFile .MODE .class );
520526 if (defaultDbMode == null )
521527 defaultDbMode = READ_WRITE ;
522528
@@ -613,46 +619,46 @@ private void loadDefaultDatabases() {
613619 final String commandParams = command .substring (commandSeparator + 1 );
614620
615621 switch (commandType ) {
616- case "restore" :
617- // DROP THE DATABASE BECAUSE THE RESTORE OPERATION WILL TAKE CARE OF CREATING A NEW DATABASE
618- if (database != null ) {
619- ((DatabaseInternal ) database ).getEmbedded ().drop ();
620- databases .remove (dbName );
621- }
622- final String dbPath =
623- configuration .getValueAsString (GlobalConfiguration .SERVER_DATABASE_DIRECTORY ) + File .separator + dbName ;
622+ case "restore" :
623+ // DROP THE DATABASE BECAUSE THE RESTORE OPERATION WILL TAKE CARE OF CREATING A NEW DATABASE
624+ if (database != null ) {
625+ ((DatabaseInternal ) database ).getEmbedded ().drop ();
626+ databases .remove (dbName );
627+ }
628+ final String dbPath =
629+ configuration .getValueAsString (GlobalConfiguration .SERVER_DATABASE_DIRECTORY ) + File .separator + dbName ;
624630// new Restore(commandParams, dbPath).restoreDatabase();
625631
626- try {
627- final Class <?> clazz = Class .forName ("com.arcadedb.integration.restore.Restore" );
628- final Object restorer = clazz .getConstructor (String .class , String .class ).newInstance (commandParams ,
629- dbPath );
632+ try {
633+ final Class <?> clazz = Class .forName ("com.arcadedb.integration.restore.Restore" );
634+ final Object restorer = clazz .getConstructor (String .class , String .class ).newInstance (commandParams ,
635+ dbPath );
630636
631- clazz .getMethod ("restoreDatabase" ).invoke (restorer );
637+ clazz .getMethod ("restoreDatabase" ).invoke (restorer );
632638
633- } catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException |
634- InstantiationException e ) {
635- throw new CommandExecutionException ("Error on restoring database, restore libs not found in " +
636- "classpath" , e );
637- } catch (final InvocationTargetException e ) {
638- throw new CommandExecutionException ("Error on restoring database" , e .getTargetException ());
639- }
639+ } catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException |
640+ InstantiationException e ) {
641+ throw new CommandExecutionException ("Error on restoring database, restore libs not found in " +
642+ "classpath" , e );
643+ } catch (final InvocationTargetException e ) {
644+ throw new CommandExecutionException ("Error on restoring database" , e .getTargetException ());
645+ }
640646
641- getDatabase (dbName );
642- break ;
647+ getDatabase (dbName );
648+ break ;
643649
644- case "import" :
645- if (database == null ) {
646- // CREATE THE DATABASE
647- LogManager .instance ().log (this , Level .INFO , "Creating default database '%s'..." , null , dbName );
648- database = createDatabase (dbName , defaultDbMode );
649- }
650- database .command ("sql" , "import database " + commandParams );
651- break ;
650+ case "import" :
651+ if (database == null ) {
652+ // CREATE THE DATABASE
653+ LogManager .instance ().log (this , Level .INFO , "Creating default database '%s'..." , null , dbName );
654+ database = createDatabase (dbName , defaultDbMode );
655+ }
656+ database .command ("sql" , "import database " + commandParams );
657+ break ;
652658
653- default :
654- LogManager .instance ().log (this , Level .SEVERE , "Unsupported command %s in startup command: '%s'" , null
655- , commandType );
659+ default :
660+ LogManager .instance ().log (this , Level .SEVERE , "Unsupported command %s in startup command: '%s'" , null
661+ , commandType );
656662 }
657663 }
658664 } else {
@@ -693,7 +699,7 @@ private void parseCredentials(final String dbName, final String credentials) {
693699 user = security .authenticate (userName , userPassword , dbName );
694700
695701 // UPDATE DB LIST + GROUP
696- user .addDatabase (dbName , new String []{ userGroup });
702+ user .addDatabase (dbName , new String [] { userGroup });
697703 security .saveUsers ();
698704
699705 } catch (final ServerSecurityException e ) {
@@ -704,7 +710,7 @@ private void parseCredentials(final String dbName, final String credentials) {
704710 }
705711 } else {
706712 // UPDATE DB LIST
707- user .addDatabase (dbName , new String []{ userGroup });
713+ user .addDatabase (dbName , new String [] { userGroup });
708714 security .saveUsers ();
709715 }
710716 } else {
@@ -715,7 +721,7 @@ private void parseCredentials(final String dbName, final String credentials) {
715721
716722 // UPDATE DB LIST + GROUP
717723 ServerSecurityUser user = security .getUser (userName );
718- user .addDatabase (dbName , new String []{ userGroup });
724+ user .addDatabase (dbName , new String [] { userGroup });
719725 security .saveUsers ();
720726 }
721727 }
0 commit comments