/**
 * DefineDirectoryRepository.java
 *
 * Created on 23 April 2007, 19:33
 * @author Duc M Le <a href="mailto:dmle@doc.ic.ac.uk"><i>dmle@doc.ic.ac.uk</i></a>
 *
 * Department of Computing, Imperial College
 *
 */

package basic;

import java.sql.SQLException;
import uk.ac.ic.doc.automed.AutoMedException;
import uk.ac.ic.doc.automed.DSRConfiguration;
import uk.ac.ic.doc.automed.p2p.directory.P2PDirectoryRepository;
import uk.ac.ic.doc.automed.util.Debugger;
import uk.ac.ic.doc.automed.util.LogOutputHandler;
import uk.ac.ic.doc.automed.util.Logger;

public class DefineDirectoryRepository {
  
  /**
   * Creates a new instance of DefineDirectoryRepository
   */
  public DefineDirectoryRepository() {
  }
  
  public static void main(String[] args) {
    try {
      // IMPORTANT: for embedded dbs with auto-commit=false, must
      // gracefully shutdown db after use
      Debugger.setSectionDebugLevel(args);
      Logger.setOutputHandler(new LogOutputHandler(LogOutputHandler.CONSOLE));
      
      if (args == null || args.length < 2) {
        System.out.println("Usage: java basic.DefineDirectoryRepository -c <cfgfile>");
        System.exit(1);
      }

      String cfgFile = args[1]; //System.getProperty("-c");
      P2PDirectoryRepository drep = null;

      if (cfgFile != null)
        drep = P2PDirectoryRepository.getRepository(cfgFile);
      else
        drep = P2PDirectoryRepository.getRepository(P2PDirectoryRepository.DEFAULT_DSP_REP_CFG);
      
      drep.initialiseRepository();
      drep.shutdown();      
    } catch (AutoMedException ex) {
      ex.printStackTrace();
    } catch (SQLException ex) {
      ex.printStackTrace();
    }
    
    System.exit(0);
  }
}
