Example usage for org.eclipse.jgit.transport Daemon setTimeout

List of usage examples for org.eclipse.jgit.transport Daemon setTimeout

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport Daemon setTimeout.

Prototype

public void setTimeout(int seconds) 

Source Link

Document

Set the timeout before willing to abort an IO call.

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();//from w  w w.j  a  v a  2 s .c  o  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()));
}