public static void initEmbeddedDataSource(String dbUrl) {
   eds = new EmbeddedDataSource();
   eds.setDatabaseName(dbUrl);
   eds.setUser(Constants.DERBY_DATABASE.STRING_DB_USER);
   eds.setPassword(Constants.DERBY_DATABASE.STRING_DB_PASSWORD);
   eds.setConnectionAttributes("create=true");
   logger.log(Level.INFO, eds.getDatabaseName());
 }
Example #2
0
  /** Starts the server. */
  @CommandArgument
  public void start() {
    System.out.println("Starting server");
    try {

      Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
      EmbeddedDataSource ds = new EmbeddedDataSource();
      ds.setConnectionAttributes("create=true");
      ds.setDatabaseName("classes");

      logger.info("Initializing jobProgressStates monitor");
      ProgressStateFactory factory = new ProgressStateFactory();
      jobProgressStates = factory.getProgressStates();

      logger.info("Initializing folders...");
      Preferences pref = Preferences.userNodeForPackage(JobServer.class);
      String path = pref.get("rootDirectory", "./server");
      File rootDirectory = new File(path);
      File jobsDirectory = new File(rootDirectory, "jobs");

      rootDirectory.mkdir();
      jobsDirectory.mkdir();

      logger.info("Initializing service");
      DbClassManager classManager = new DbClassManager(ds);
      classManager.prepareDataSource();

      TaskScheduler scheduler = new PrioritySerialTaskScheduler();
      Executor executor = Executors.newCachedThreadPool();
      jobServer = new JobServer(jobsDirectory, factory, scheduler, classManager, executor);
      AuthenticationServer authServer = new AuthenticationServer(jobServer, JdcpUtil.DEFAULT_PORT);

      logger.info("Binding service");
      Registry registry = getRegistry();
      registry.bind("AuthenticationService", authServer);

      logger.info("Server ready");
      System.out.println("Server started");

    } catch (Exception e) {
      System.err.println("Failed to start server");
      logger.error("Failed to start server", e);
    }
  }