All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.anrisoftware.sscontrol.hosts.service.HostsServiceFactory Maven / Gradle / Ivy

There is a newer version: 1.0-alpha-4
Show newest version
/*
 * Copyright 2012-2015 Erwin Müller 
 *
 * This file is part of sscontrol-hosts.
 *
 * sscontrol-hosts is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * sscontrol-hosts is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with sscontrol-hosts. If not, see .
 */
package com.anrisoftware.sscontrol.hosts.service;

import java.util.concurrent.ExecutorService;

import org.mangosdk.spi.ProviderFor;

import com.anrisoftware.sscontrol.core.api.ProfileService;
import com.anrisoftware.sscontrol.core.api.Service;
import com.anrisoftware.sscontrol.core.api.ServiceFactory;
import com.google.inject.Injector;
import com.google.inject.Module;

/**
 * Creates the hosts service and makes it available as a service.
 * 
 * @author Erwin Mueller, [email protected]
 * @since 1.0
 */
@ProviderFor(ServiceFactory.class)
public class HostsServiceFactory implements ServiceFactory {

    /**
     * The name of the hosts service.
     */
    public static final String NAME = "hosts";

    private static final Module[] MODULES = new Module[] { new HostsModule() };

    private Injector injector;

    private ExecutorService threads;

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public Service create(ProfileService profile) {
        HostsServiceImpl service;
        service = injector.getInstance(HostsServiceImpl.class);
        service.setThreads(threads);
        service.setProfile(profile);
        return service;
    }

    @Override
    public void setParent(Object parent) {
        this.injector = ((Injector) parent).createChildInjector(MODULES);
    }

    /**
     * Sets the threads pool.
     * 
     * @param threads
     *            the {@link ExecutorService} threads pool.
     */
    @Override
    public void setThreads(ExecutorService threads) {
        this.threads = threads;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy