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

org.seedstack.scheduler.internal.SchedulerModule Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
/**
 * Copyright (c) 2013-2016, The SeedStack authors 
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package org.seedstack.scheduler.internal;

import com.google.common.collect.Multimap;
import com.google.inject.PrivateModule;
import com.google.inject.multibindings.MapBinder;
import org.quartz.Scheduler;
import org.seedstack.scheduler.ScheduledTasks;
import org.seedstack.scheduler.Task;
import org.seedstack.scheduler.TaskListener;

import java.util.Collection;
import java.util.Map;

class SchedulerModule extends PrivateModule {
    private final Collection> taskClasses;
    private final Multimap, Class> taskListenerMap;
    private final Scheduler scheduler;

    SchedulerModule(Collection> taskClasses, Scheduler scheduler, Multimap, Class> taskListenerMap) {
        this.taskClasses = taskClasses;
        this.scheduler = scheduler;
        this.taskListenerMap = taskListenerMap;
    }

    @Override
    protected void configure() {
        bind(GuiceTaskFactory.class);
        bind(ScheduledTasks.class).to(ScheduledTasksImpl.class);
        bind(Scheduler.class).toInstance(scheduler);
        bind(DelegateJobListener.class);

        for (Class taskClass : taskClasses) {
            bind(taskClass);
        }

        MapBinder mapBinder = MapBinder.newMapBinder(binder(), String.class, TaskListener.class);
        mapBinder.permitDuplicates();

        for (Map.Entry, Class> taskListenerEntry : taskListenerMap.entries()) {
            mapBinder.addBinding(taskListenerEntry.getKey().getCanonicalName()).to(taskListenerEntry.getValue());
        }

        requestStaticInjection(SchedulerPlugin.class);
        expose(ScheduledTasks.class);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy