DefaultInitializer.java

  1. /*
  2.  * *********************************************************************************************************************
  3.  *
  4.  * blueMarine II: Semantic Media Centre
  5.  * http://tidalwave.it/projects/bluemarine2
  6.  *
  7.  * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *********************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  12.  * the License. You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  17.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations under the License.
  19.  *
  20.  * *********************************************************************************************************************
  21.  *
  22.  * git clone https://bitbucket.org/tidalwave/bluemarine2-src
  23.  * git clone https://github.com/tidalwave-it/bluemarine2-src
  24.  *
  25.  * *********************************************************************************************************************
  26.  */
  27. package it.tidalwave.bluemarine2.initializer.impl;

  28. import javax.annotation.PreDestroy;
  29. import javax.inject.Inject;
  30. import java.util.HashMap;
  31. import java.util.Map;
  32. import java.nio.file.Path;
  33. import java.nio.file.Paths;
  34. import it.tidalwave.util.Key;
  35. import it.tidalwave.messagebus.MessageBus;
  36. import it.tidalwave.bluemarine2.message.PowerOffNotification;
  37. import it.tidalwave.bluemarine2.message.PowerOnNotification;
  38. import it.tidalwave.bluemarine2.model.ModelPropertyNames;
  39. import it.tidalwave.bluemarine2.persistence.PersistencePropertyNames;
  40. import it.tidalwave.bluemarine2.downloader.DownloaderPropertyNames;
  41. import it.tidalwave.bluemarine2.initializer.Initializer;
  42. import lombok.extern.slf4j.Slf4j;

  43. /***********************************************************************************************************************
  44.  *
  45.  * @author  Fabrizio Giudici
  46.  *
  47.  **********************************************************************************************************************/
  48. @Slf4j
  49. public class DefaultInitializer implements Initializer
  50.   {
  51.     @Inject
  52.     private MessageBus messageBus;

  53.     /*******************************************************************************************************************
  54.      *
  55.      * {@inheritDoc}
  56.      *
  57.      ******************************************************************************************************************/
  58.     @Override
  59.     public void boot()
  60.       {
  61.         final Map<Key<?>, Object> properties = new HashMap<>();
  62.         final Path configPath = Paths.get(System.getProperty("blueMarine2.workspace"));
  63.         log.info("configPath is {}", configPath);
  64.         properties.put(ModelPropertyNames.ROOT_PATH, configPath);
  65.         properties.put(PersistencePropertyNames.STORAGE_FOLDER, configPath.resolve("storage"));
  66.         properties.put(PersistencePropertyNames.IMPORT_FILE, configPath.resolve("import").resolve("repository.n3"));
  67.         properties.put(PersistencePropertyNames.RENAME_IMPORT_FILE, true);
  68.         properties.put(DownloaderPropertyNames.CACHE_FOLDER_PATH, configPath.resolve("cache"));
  69.         messageBus.publish(new PowerOnNotification(properties));
  70.       }

  71.     /*******************************************************************************************************************
  72.      *
  73.      *
  74.      *
  75.      ******************************************************************************************************************/
  76.     @PreDestroy
  77.     private void shutdown()
  78.       {
  79.         messageBus.publish(new PowerOffNotification());
  80.       }
  81.   }