Example usage for org.eclipse.jgit.lib Config getLong

List of usage examples for org.eclipse.jgit.lib Config getLong

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Config getLong.

Prototype

public long getLong(final String section, String subsection, final String name, final long defaultValue) 

Source Link

Document

Obtain an integer value from the configuration.

Usage

From source file:com.google.gerrit.lucene.GerritIndexWriterConfig.java

License:Apache License

GerritIndexWriterConfig(Config cfg, String name) {
    analyzer = new CustomMappingAnalyzer(new StandardAnalyzer(CharArraySet.EMPTY_SET), CUSTOM_CHAR_MAPPING);
    luceneConfig = new IndexWriterConfig(analyzer).setOpenMode(OpenMode.CREATE_OR_APPEND)
            .setCommitOnClose(true);//w  ww  .j  av a  2 s . com
    double m = 1 << 20;
    luceneConfig.setRAMBufferSizeMB(cfg.getLong("index", name, "ramBufferSize",
            (long) (IndexWriterConfig.DEFAULT_RAM_BUFFER_SIZE_MB * m)) / m);
    luceneConfig.setMaxBufferedDocs(
            cfg.getInt("index", name, "maxBufferedDocs", IndexWriterConfig.DEFAULT_MAX_BUFFERED_DOCS));
    try {
        commitWithinMs = ConfigUtil.getTimeUnit(cfg, "index", name, "commitWithin",
                MILLISECONDS.convert(5, MINUTES), MILLISECONDS);
    } catch (IllegalArgumentException e) {
        commitWithinMs = cfg.getLong("index", name, "commitWithin", 0);
    }
}

From source file:com.google.gerrit.server.config.ConfigUtil.java

License:Apache License

/**
 * Load section by inspecting Java class attributes.
 * <p>/*  www.j a  v  a2  s. c  o  m*/
 * Config values are stored optimized: no default values are stored.
 * The loading is performed eagerly: all values are set.
 * <p>
 * Fields marked with final or transient modifiers are skipped.
 * <p>
 * Boolean fields are only set when their values are true.
 *
 * @param cfg config from which the values are loaded
 * @param section section
 * @param sub subsection
 * @param s instance of class in which the values are set
 * @param defaults instance of class with default values
 * @return loaded instance
 * @throws ConfigInvalidException
 */
public static <T> T loadSection(Config cfg, String section, String sub, T s, T defaults)
        throws ConfigInvalidException {
    try {
        for (Field f : s.getClass().getDeclaredFields()) {
            if (skipField(f)) {
                continue;
            }
            Class<?> t = f.getType();
            String n = f.getName();
            f.setAccessible(true);
            Object d = f.get(defaults);
            Preconditions.checkNotNull(d, "Default cannot be null");
            if (isString(t)) {
                f.set(s, MoreObjects.firstNonNull(cfg.getString(section, sub, n), d));
            } else if (isInteger(t)) {
                f.set(s, cfg.getInt(section, sub, n, (Integer) d));
            } else if (isLong(t)) {
                f.set(s, cfg.getLong(section, sub, n, (Long) d));
            } else if (isBoolean(t)) {
                boolean b = cfg.getBoolean(section, sub, n, (Boolean) d);
                if (b) {
                    f.set(s, b);
                }
            } else if (t.isEnum()) {
                f.set(s, cfg.getEnum(section, sub, n, (Enum<?>) d));
            } else {
                throw new ConfigInvalidException("type is unknown: " + t.getName());
            }
        }
    } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
        throw new ConfigInvalidException("cannot load values", e);
    }
    return s;
}

From source file:com.google.gerrit.server.config.ConfigUtilTest.java

License:Apache License

@Test
public void testStoreLoadSection() throws Exception {
    SectionInfo d = SectionInfo.defaults();
    SectionInfo in = new SectionInfo();
    in.missing = "42";
    in.i = 1;//www  .ja v  a  2  s.  c  om
    in.ii = 43;
    in.l = 4L;
    in.ll = -43L;
    in.b = false;
    in.bb = true;
    in.bd = false;
    in.s = "baz";
    in.t = Theme.MIDNIGHT;

    Config cfg = new Config();
    ConfigUtil.storeSection(cfg, SECT, SUB, in, d);

    assertThat(cfg.getString(SECT, SUB, "CONSTANT")).isNull();
    assertThat(cfg.getString(SECT, SUB, "missing")).isNull();
    assertThat(cfg.getBoolean(SECT, SUB, "b", false)).isEqualTo(in.b);
    assertThat(cfg.getBoolean(SECT, SUB, "bb", false)).isEqualTo(in.bb);
    assertThat(cfg.getInt(SECT, SUB, "i", 0)).isEqualTo(0);
    assertThat(cfg.getInt(SECT, SUB, "ii", 0)).isEqualTo(in.ii);
    assertThat(cfg.getLong(SECT, SUB, "l", 0L)).isEqualTo(0L);
    assertThat(cfg.getLong(SECT, SUB, "ll", 0L)).isEqualTo(in.ll);
    assertThat(cfg.getString(SECT, SUB, "s")).isEqualTo(in.s);
    assertThat(cfg.getString(SECT, SUB, "sd")).isNull();

    SectionInfo out = new SectionInfo();
    ConfigUtil.loadSection(cfg, SECT, SUB, out, d);
    assertThat(out.i).isEqualTo(in.i);
    assertThat(out.ii).isEqualTo(in.ii);
    assertThat(out.id).isEqualTo(d.id);
    assertThat(out.l).isEqualTo(in.l);
    assertThat(out.ll).isEqualTo(in.ll);
    assertThat(out.ld).isEqualTo(d.ld);
    assertThat(out.b).isEqualTo(in.b);
    assertThat(out.bb).isEqualTo(in.bb);
    assertThat(out.bd).isNull();
    assertThat(out.s).isEqualTo(in.s);
    assertThat(out.sd).isEqualTo(d.sd);
    assertThat(out.t).isEqualTo(in.t);
    assertThat(out.td).isEqualTo(d.td);
}

From source file:com.google.gerrit.server.git.ProjectConfig.java

License:Apache License

private void loadReceiveSection(Config rc) {
    checkReceivedObjects = rc.getBoolean(RECEIVE, KEY_CHECK_RECEIVED_OBJECTS, true);
    maxObjectSizeLimit = rc.getLong(RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT, 0);
}

From source file:com.google.gitiles.ConfigUtil.java

License:Open Source License

/**
 * Get a {@link CacheBuilder} from a config.
 *
 * @param config JGit config object./*from   w w  w. java 2s . c  o m*/
 * @param name name of the cache subsection under the "cache" section.
 * @return a new cache builder.
 */
public static CacheBuilder<Object, Object> getCacheBuilder(Config config, String name) {
    CacheBuilder<Object, Object> b = CacheBuilder.newBuilder();
    try {
        if (config.getString("cache", name, "maximumWeight") != null) {
            b.maximumWeight(config.getLong("cache", name, "maximumWeight", 20 << 20));
        }
        if (config.getString("cache", name, "maximumSize") != null) {
            b.maximumSize(config.getLong("cache", name, "maximumSize", 16384));
        }
        Duration expireAfterWrite = getDuration(config, "cache", name, "expireAfterWrite", null);
        if (expireAfterWrite != null) {
            b.expireAfterWrite(expireAfterWrite.getMillis(), TimeUnit.MILLISECONDS);
        }
        Duration expireAfterAccess = getDuration(config, "cache", name, "expireAfterAccess", null);
        if (expireAfterAccess != null) {
            b.expireAfterAccess(expireAfterAccess.getMillis(), TimeUnit.MILLISECONDS);
        }
        // Add other methods as needed.
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Error getting CacheBuilder for " + name, e);
    } catch (IllegalStateException e) {
        throw new IllegalStateException("Error getting CacheBuilder for " + name, e);
    }
    return b;
}

From source file:com.googlesource.gerrit.plugins.rabbitmq.config.section.Sections.java

License:Apache License

public static <T extends Section> Section fromConfig(T section, Config... configs) {
    for (Config config : configs) {
        if (config != null) {
            Set<String> names = config.getNames(getName(section));
            Field[] fs = section.getClass().getFields();

            for (Field f : fs) {
                try {
                    if (names.contains(f.getName())) {
                        Class<?> type = f.getType();
                        if (type == String.class) {
                            f.set(section, config.getString(getName(section), null, f.getName()));
                        } else if (type == Integer.class) {
                            f.set(section, config.getInt(getName(section), null, f.getName(), 0));
                        } else if (type == Long.class) {
                            f.set(section, config.getLong(getName(section), null, f.getName(), 0));
                        } else if (type == Boolean.class) {
                            f.set(section, config.getBoolean(getName(section), null, f.getName(), false));
                        }/*from  ww  w .j av  a2  s. c o  m*/
                    }
                } catch (IllegalAccessException ex) {
                    LOGGER.warn("Cannot access field {}. Cause: {}", f.getName(), ex.getMessage());
                }
            }
        }
    }
    return section;
}