Example usage for org.eclipse.jgit.storage.pack PackConfig getThreads

List of usage examples for org.eclipse.jgit.storage.pack PackConfig getThreads

Introduction

In this page you can find the example usage for org.eclipse.jgit.storage.pack PackConfig getThreads.

Prototype

public int getThreads() 

Source Link

Document

Get the number of threads used during delta compression.

Usage

From source file:com.sap.poc.jgit.storage.jdbc.pgm.JdbcDaemon.java

License:Eclipse Distribution License

@Override
protected void run() throws Exception {
    final PackConfig packConfig = new PackConfig();

    if (configFile != null) {
        if (!configFile.exists())
            throw die(MessageFormat.format(CLIText.get().configFileNotFound, configFile.getAbsolutePath()));

        final FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED);
        cfg.load();/*  w w  w. ja  v a2s.  co  m*/
        packConfig.fromConfig(cfg);
    }

    int threads = packConfig.getThreads();
    if (threads <= 0)
        threads = Runtime.getRuntime().availableProcessors();
    if (1 < threads)
        packConfig.setExecutor(Executors.newFixedThreadPool(threads));

    final org.eclipse.jgit.transport.Daemon d;

    d = new org.eclipse.jgit.transport.Daemon(
            host != null ? new InetSocketAddress(host, port) : new InetSocketAddress(port));

    final JdbcDatabase db = new JdbcDatabaseBuilder().setURI(uri).build();

    final RepositoryResolver<DaemonClient> resolver = new RepositoryResolver<DaemonClient>() {
        @Override
        public Repository open(DaemonClient req, String name) throws RepositoryNotFoundException {
            try {
                return new JdbcRepositoryBuilder().setDatabase(db).setRepositoryName(name).build();
            } catch (DhtException e) {
                throw new RepositoryNotFoundException(name, e);
            }
        }
    };

    d.setPackConfig(packConfig);
    d.setRepositoryResolver(resolver);
    if (0 <= timeout)
        d.setTimeout(timeout);

    for (final String n : enable)
        service(d, n).setEnabled(true);
    for (final String n : disable)
        service(d, n).setEnabled(false);

    for (final String n : canOverride)
        service(d, n).setOverridable(true);
    for (final String n : forbidOverride)
        service(d, n).setOverridable(false);

    d.start();
    out.println(MessageFormat.format(CLIText.get().listeningOn, d.getAddress()));
}