protected boolean getShowLinearCurve() throws IOException {
    boolean res = false;

    {
      ConfigFactory f = DefaultConfigFactory.getInstance();
      Config c = f.getConfig();

      String configNameLinearCurve = getConfigNameLinearCurve();
      boolean configValueDefault = false;

      // Set 'configValueDefault':
      {
        String mode = c.getProperty("mode");
        if (mode != null) {
          if ("Test".equals(mode)) {
            configValueDefault = true;
          }
        }
      }

      res = c.getPropertyAsBoolean(configNameLinearCurve, configValueDefault);
    }

    return res;
  }
示例#2
0
 /**
  * 获取数据库链接
  *
  * @return
  * @throws ClassNotFoundException
  * @throws java.sql.SQLException
  */
 public static final Connection getDatabaseConnection()
     throws ClassNotFoundException, SQLException {
   Class.forName("com.mysql.jdbc.Driver");
   return DriverManager.getConnection(
       Config.getProperty("mysql.url"),
       Config.getProperty("mysql.username"),
       Config.getProperty("mysql.password"));
 }
示例#3
0
  public void testLoadAll() throws Exception {
    Config config = Config.load(new ConfigRef(true));

    for (String key : keys) {
      assert config.getProperty(key) != null;
    }
  }
示例#4
0
  /**
   * Tests filtering of config props via a {@link IConfigFilter}.
   *
   * @throws Exception
   */
  public void testConfigFiltering() throws Exception {
    Config config = Config.load();

    // create a filter to extract only those keys beginning with: 'props.simple'
    IConfigFilter filter =
        new IConfigFilter() {

          @Override
          public boolean accept(String keyName) {
            return keyName.startsWith("props.simple");
          }
        };
    Config filtered = config.filter(filter);
    assert filtered != null && !filtered.isEmpty()
        : "Unable to obtain non-empty filtered config instance";
    assert filtered.getProperty("props.simple.propA") != null;
    assert filtered.getProperty("props.simple.propB") != null;
    int num = 0;
    for (Iterator<String> itr = filtered.getKeys(); itr.hasNext(); ) {
      String key = itr.next();
      assert key != null && key.startsWith("props.simple") : "Encountered invalid filtered key";
      num++;
    }
    assert num == 2 : "Invalid number of filtered keys.";
  }
  @Test
  public void testProperties() throws Exception {

    assertNotNull(clazz.getSomeValue1());
    assertNotNull(clazz.getSomeValue2());
    assertNotNull(clazz.getSomeValue4());
    assertNotNull(clazz.getSomeOtherValue());

    assertEquals(clazz.getSomeValue1(), "custom");
    assertEquals(clazz.getSomeValue2(), "value2");
    assertEquals(clazz.getSomeValue4(), "custom-custom2");
    assertEquals(clazz.getSomeOtherValue(), "custom2");

    assertNotNull(config.getProperty("property.1.name", String.class));
    assertEquals(config.getProperty("property.1.name", String.class), "custom");
  }
示例#6
0
  /** Create unique Session id. */
  protected String createSessionId() {
    // Use UUID if specified in config (thanks Uli Romahn)
    if (Config.hasProperty(SESSION_ID_GENERATION)
        && Config.getProperty(SESSION_ID_GENERATION).equals(SESSION_ID_GENERATION_UUID)) {
      // We want to be Java 1.4 compatible so use UID class (1.5+ we may
      // use java.util.UUID).
      return new UID().toString();
    }

    // Other cases use random name

    // Create a unique session id
    // In 99.9999 % of the cases this should be generated at once
    // We need the mutext to prevent the chance of creating
    // same-valued ids (thanks Uli Romahn)
    synchronized (mutex) {
      String id;
      while (true) {
        id = Rand.randomName(Config.getIntProperty(SESSION_ID_SIZE));
        if (!hasSession(id)) {
          // Created unique session id
          break;
        }
      }
      return id;
    }
  }
示例#7
0
  public static void setupDb(OrchestraSystem system, SqlDb d, SqlEngine tcd, List<String> tables)
      throws Exception {
    if (Config.getApply()) createDatabase(Config.getProperty("schema"), d);

    tcd.migrate();

    tcd.computeDeltaRules();
  }
示例#8
0
  public static void createDatabase(String schemaName, SqlDb db) {
    File dir = new File(Config.getProperty("workdir"));

    Calendar before = Calendar.getInstance();

    if (Config.isDB2() || Config.isOracle())
      db.evaluateFromShell(schemaName + ".create", dir, false);
    else if (Config.isHsql()) {
      try {
        BufferedReader r = new BufferedReader(new FileReader(dir + "/" + schemaName + ".create"));

        db.evaluate("CREATE SCHEMA " + Config.getProperty("sqlschema") + " AUTHORIZATION DBA");
        String ln = r.readLine();
        String sql = "";
        boolean startReading = false;
        while (ln != null) {
          if (ln.contains("CREATE")) {
            startReading = true;
            // db.evaluate(ln);
          }
          if (startReading) sql = sql + ln;

          if (ln.contains(";")) {
            startReading = false;
            sql = sql.replace("NOT LOGGED INITIALLY", "");
            sql =
                sql.replace(
                    "CREATE TABLE ", "CREATE TABLE " + Config.getProperty("sqlschema") + ".");
            db.evaluate(sql);
            sql = "";
          }

          ln = r.readLine();
        }

        r.close();

      } catch (java.io.IOException e) {
        e.printStackTrace();
      }
    } else throw new RuntimeException("Unimplemented DBMS!");

    Calendar after = Calendar.getInstance();
    long time = (after.getTimeInMillis() - before.getTimeInMillis());
    System.out.println("EXP: CREATE DB TIME: " + time + "msec");
  }
  public static String getProperty(String string) {

    Properties config = new Properties();
    try {
      config.load(
          Config.class.getResourceAsStream(
              "/fr/eelite/gamepath/" + Config.getProperty("gamepath") + ".properties"));

    } catch (IOException e) {
      e.printStackTrace();
    }
    return config.getProperty(string);
  }
  protected List<String> getUserRolesFromConfig(String property) throws IOException {
    List<String> res = null;

    {
      if (property != null) {
        ConfigFactory f = DefaultConfigFactory.getInstance();
        Config c = f.getConfig();

        String v = c.getProperty(property); // re-read; marks property read in 'Config'-impl. cache

        res = parseStringList(v);
      }
    }

    return res;
  }
  protected String getUserPresentationNameFromConfig(Principal userPrincipal) throws IOException {
    String res = null;

    {
      if (userPrincipal != null) {
        String userName = PrincipalUtil.getNameStripped(userPrincipal);

        if (userName != null) {
          String property = "security.authorization.user." + userName + ".presentation-name";

          ConfigFactory f = DefaultConfigFactory.getInstance();
          Config c = f.getConfig();

          res = c.getProperty(property);
        }
      }
    }

    return res;
  }
示例#12
0
文件: Session.java 项目: vito16/bysj
/**
 * Represents client pushlet session state.
 *
 * @author Just van den Broecke - Just Objects &copy;
 * @version $Id: Session.java,v 1.8 2007/11/23 14:33:07 justb Exp $
 */
public class Session implements Protocol, ConfigDefs {
  private Controller controller;
  private Subscriber subscriber;

  private String userAgent;
  private long LEASE_TIME_MILLIS = Config.getLongProperty(SESSION_TIMEOUT_MINS) * 60 * 1000;
  private volatile long timeToLive = LEASE_TIME_MILLIS;

  public static String[] FORCED_PULL_AGENTS =
      Config.getProperty(LISTEN_FORCE_PULL_AGENTS).split(",");

  private String address = "unknown";
  private String format = FORMAT_XML;

  private String id;

  /** Protected constructor as we create through factory method. */
  protected Session() {}

  /**
   * Create instance through factory method.
   *
   * @param anId a session id
   * @return a Session object (or derived)
   * @throws PushletException exception, usually misconfiguration
   */
  public static Session create(String anId) throws PushletException {
    Session session;
    try {
      session =
          (Session)
              Config.getClass(SESSION_CLASS, "nl.justobjects.pushlet.core.Session").newInstance();
    } catch (Throwable t) {
      throw new PushletException("Cannot instantiate Session from config", t);
    }

    // Init session
    session.id = anId;
    session.controller = Controller.create(session);
    session.subscriber = Subscriber.create(session);
    return session;
  }

  /**
   * * 新增方法,sessionId为用户id
   *
   * @param anId
   * @param anEvent
   * @return
   * @throws PushletException
   */
  public static Session create(String anId, Event anEvent) throws PushletException {
    Session session;
    try {
      session =
          (Session)
              Config.getClass(SESSION_CLASS, "nl.justobjects.pushlet.core.Session").newInstance();
    } catch (Throwable t) {
      throw new PushletException("Cannot instantiate Session from config", t);
    }
    // Init session
    session.id = anEvent.getField("id"); // sessionId为有意义的用户id</span><span>
    session.controller = Controller.create(session);
    session.subscriber = Subscriber.create(session);
    return session;
  }

  /** Return (remote) Subscriber client's IP address. */
  public String getAddress() {
    return address;
  }

  /** Return command controller. */
  public Controller getController() {
    return controller;
  }

  /** Return Event format to send to client. */
  public String getFormat() {
    return format;
  }

  /** Return (remote) Subscriber client's unique id. */
  public String getId() {
    return id;
  }

  /** Return subscriber. */
  public Subscriber getSubscriber() {
    return subscriber;
  }

  /** Return remote HTTP User-Agent. */
  public String getUserAgent() {
    return userAgent;
  }

  /** Set address. */
  protected void setAddress(String anAddress) {
    address = anAddress;
  }

  /** Set event format to encode. */
  protected void setFormat(String aFormat) {
    format = aFormat;
  }

  /** Set client HTTP UserAgent. */
  public void setUserAgent(String aUserAgent) {
    userAgent = aUserAgent;
  }

  /** Decrease time to live. */
  public void age(long aDeltaMillis) {
    timeToLive -= aDeltaMillis;
  }

  /** Has session timed out? */
  public boolean isExpired() {
    return timeToLive <= 0;
  }

  /** Keep alive by resetting TTL. */
  public void kick() {
    timeToLive = LEASE_TIME_MILLIS;
  }

  public void start() {
    SessionManager.getInstance().addSession(this);
  }

  public void stop() {
    subscriber.stop();
    SessionManager.getInstance().removeSession(this);
  }

  /** Info. */
  public void info(String s) {
    Log.info("S-" + this + ": " + s);
  }

  /** Exceptional print util. */
  public void warn(String s) {
    Log.warn("S-" + this + ": " + s);
  }

  /** Exceptional print util. */
  public void debug(String s) {
    Log.debug("S-" + this + ": " + s);
  }

  public String toString() {
    return getAddress() + "[" + getId() + "]";
  }
}
示例#13
0
  public static void main(String[] args) {
    Config.parseCommandLine(args);
    Config.dumpParams(System.out);

    if (Config.getPrepare() && Config.getUnion() && Config.getStratified()) {
      throw new RuntimeException(
          "Current Implementation of stratified deletions"
              + " with prepared statements maps one list of parameters to every query"
              + " and thus doesn't work with union");
    }

    try {
      // NOTE:  a general user will actually call open, importUpdates, etc.
      // but instead we are calling lower-level routines right now, to test.

      RepositorySchemaDAO dao = new FlatFileRepositoryDAO(Config.getSchemaFile());
      OrchestraSystem system = dao.loadAllPeers();
      List<String> tables = SqlEngine.getNamesOfAllTables(system, false, false, true);
      //			List<String> tables = SqlEngine.getNamesOfAllTables(system, true, true, true);

      SqlDb d = new SqlDb(tables, system.getAllSchemas(), system);
      if (Config.getApply()) {
        d.connect();
      }
      SqlEngine tcd =
          new SqlEngine(
              d, // null,
              system);

      Peer p = system.getPeers().iterator().next();

      try {
        if (Config.getApply() && !Config.getBoolean("scalability2"))
          createDatabase(Config.getProperty("schema"), d);

        Debug.println("+++ Basic System Schema +++");
        for (String t : tables) Debug.print(t + "\t");
        Debug.println("");

        Debug.println("+++ Mappings +++");
        List<Mapping> mappings = system.getAllSystemMappings(true);
        for (Mapping s : mappings) Debug.println(s.toString());

        Debug.println("+++ Inverted/Composed Mappings with Provenance Relations +++");
        List<Rule> ruleSet = tcd.computeTranslationRules();

        //				for(RelationContext rel : tcd.getState().getIdbs()){
        //					List<RelationContext> p = tcd.getState().provenanceTablesForRelation(rel);
        //
        //					System.out.println("Provenance tables for " + rel + ": " + p);
        //				}

        for (Rule r : ruleSet) Debug.println(r.toString());

        boolean origApply = true;
        if (Config.getBoolean("scalability2")) {
          origApply = Config.getApply();
          Config.setApply(false);
        }

        if (Config.getApply()) tcd.migrate();

        if (Config.getBoolean("scalability2")) {
          Config.setApply(origApply);
        }

        // DeltaRules ourRules =
        tcd.computeDeltaRules();

        Debug.println("+++ Insertion Rules +++");
        List<DatalogSequence> insRules = tcd.getIncrementalInsertionProgram();
        insRules.get(0).printString();
        insRules.get(1).printString();
        insRules.get(2).printString();

        List<DatalogSequence> delRules = tcd.getIncrementalDeletionProgram();
        Debug.println("+++ Deletion Rules +++");
        delRules.get(0).printString();
        delRules.get(1).printString();
        delRules.get(2).printString();

        List<String> newTables =
            SqlEngine.getNamesOfAllTablesFromDeltas(/*ourRules,*/ system, true, true, true);
        d.setAllTables(newTables);

        if (Config.getBoolean("scalability")) {
          runScalability(tcd, d, p);
        } else if (Config.getBoolean("scalability1")) {
          runScalability1(tcd, d, p);
        } else if (Config.getBoolean("scalability2")) {
          runScalability2(tcd, d, p);
        } else if (Config.getBoolean("nullscycles")) {
          runAllnoMigrateInsOnly(tcd, p);
        } else if (Config.getDebug()) {
          runOnce(tcd, p);
        } else {
          //					runAllmigrateEveryTime(system, tcd, d, tables);
          runAllnoMigrate(tcd, d, p);
        }

        tcd.finalize();
        //				tcd.clean();
        if (Config.getApply()) {
          d.disconnect();
        }

      } catch (Exception e) {
        e.printStackTrace();
        tcd.clean();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#14
0
 public static void main(String[] args) {
   System.out.println(Config.getProperty("itemList"));
 }