// Path: jashing/src/main/java/com/github/avarabyeu/jashing/core/eventsource/ScheduledEventSource.java
// public abstract class ScheduledEventSource<T extends JashingEvent> extends AbstractScheduledService {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(ScheduledEventSource.class);
// 
//     /**
//      * Time period between sending events
//      */
//     @Frequency
//     @Inject
//     private Duration period;
// 
//     /**
//      * ID of event this event source bound to
//      */
//     @EventId
//     @Inject
//     private String eventId;
// 
//     /**
//      * EventBus to send events
//      */
//     @Inject
//     private EventBus eventBus;
// 
// 
//     /**
//      * Executes one iteration of {@link com.google.common.util.concurrent.AbstractScheduledService}
//      * Sends event to event bus
//      *
//      * @throws Exception
//      */
//     @Override
//     protected final void runOneIteration() throws Exception {
//         try {
//             sendEvent(produceEvent());
//         } catch (Exception e){
//             LOGGER.error(MessageFormatter.format("Cannot produce event with id {}", eventId).getMessage(), e);
//         }
// 
//     }
// 
// 
//     protected final void sendEvent(JashingEvent t) {
//         if (null != t) {
//             if (isNull(t.getId())) t.setId(eventId);
//             this.eventBus.post(t);
//         }
//     }
// 
//     @Override
//     protected final Scheduler scheduler() {
//         return AbstractScheduledService.Scheduler.newFixedDelaySchedule(3, period.toMillis(), TimeUnit.MILLISECONDS);
//     }
// 
//     @Override
//     protected final String serviceName() {
//         return "ScheduledEventSource[eventID=" + eventId + "]";
//     }
// 
//     protected abstract T produceEvent();
// }
// 
// Path: jashing/src/main/java/com/github/avarabyeu/jashing/events/MeterEvent.java
// public class MeterEvent extends JashingEvent {
// 
//     private final byte value;
// 
//     public MeterEvent(byte value) {
//         this.value = value;
//     }
// 
//     public MeterEvent(String title, byte value) {
//         this.value = value;
//         setTitle(title);
//     }
// 
//     public byte getValue() {
//         return value;
//     }
// }


import com.github.avarabyeu.jashing.core.EventSource;
import com.github.avarabyeu.jashing.core.eventsource.ScheduledEventSource;
import com.github.avarabyeu.jashing.events.MeterEvent;
import com.google.common.util.concurrent.Uninterruptibles;
import javax.inject.Inject;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
package com.github.avarabyeu.jashing.integration.jenkins;



/**
 * @author Andrei Varabyeu
 */
@EventSource(value = "jenkins-active-jobs-source", explicitConfiguration = JenkinsModule.class)
public class JenkinsActiveJobsEventSource extends ScheduledEventSource<MeterEvent> {

    @Inject
    private JenkinsClient jenkinsClient;

    @Override
    protected MeterEvent produceEvent() {
        Jobs runningJobs = jenkinsClient.getRunningJobs();
// Path: jashing/src/main/java/com/github/avarabyeu/jashing/core/eventsource/ScheduledEventSource.java
// public abstract class ScheduledEventSource<T extends JashingEvent> extends AbstractScheduledService {
// 
//     private static final Logger LOGGER = LoggerFactory.getLogger(ScheduledEventSource.class);
// 
//     /**
//      * Time period between sending events
//      */
//     @Frequency
//     @Inject
//     private Duration period;
// 
//     /**
//      * ID of event this event source bound to
//      */
//     @EventId
//     @Inject
//     private String eventId;
// 
//     /**
//      * EventBus to send events
//      */
//     @Inject
//     private EventBus eventBus;
// 
// 
//     /**
//      * Executes one iteration of {@link com.google.common.util.concurrent.AbstractScheduledService}
//      * Sends event to event bus
//      *
//      * @throws Exception
//      */
//     @Override
//     protected final void runOneIteration() throws Exception {
//         try {
//             sendEvent(produceEvent());
//         } catch (Exception e){
//             LOGGER.error(MessageFormatter.format("Cannot produce event with id {}", eventId).getMessage(), e);
//         }
// 
//     }
// 
// 
//     protected final void sendEvent(JashingEvent t) {
//         if (null != t) {
//             if (isNull(t.getId())) t.setId(eventId);
//             this.eventBus.post(t);
//         }
//     }
// 
//     @Override
//     protected final Scheduler scheduler() {
//         return AbstractScheduledService.Scheduler.newFixedDelaySchedule(3, period.toMillis(), TimeUnit.MILLISECONDS);
//     }
// 
//     @Override
//     protected final String serviceName() {
//         return "ScheduledEventSource[eventID=" + eventId + "]";
//     }
// 
//     protected abstract T produceEvent();
// }
// 
// Path: jashing/src/main/java/com/github/avarabyeu/jashing/events/MeterEvent.java
// public class MeterEvent extends JashingEvent {
// 
//     private final byte value;
// 
//     public MeterEvent(byte value) {
//         this.value = value;
//     }
// 
//     public MeterEvent(String title, byte value) {
//         this.value = value;
//         setTitle(title);
//     }
// 
//     public byte getValue() {
//         return value;
//     }
// }


// Path: extensions/jashing-jenkins/src/main/java/com/github/avarabyeu/jashing/integration/jenkins/JenkinsActiveJobsEventSource.java
import com.github.avarabyeu.jashing.core.EventSource;
import com.github.avarabyeu.jashing.core.eventsource.ScheduledEventSource;
import com.github.avarabyeu.jashing.events.MeterEvent;
import com.google.common.util.concurrent.Uninterruptibles;
import javax.inject.Inject;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

package com.github.avarabyeu.jashing.integration.jenkins;



/**
 * @author Andrei Varabyeu
 */
@EventSource(value = "jenkins-active-jobs-source", explicitConfiguration = JenkinsModule.class)
public class JenkinsActiveJobsEventSource extends ScheduledEventSource<MeterEvent> {

    @Inject
    private JenkinsClient jenkinsClient;

    @Override
    protected MeterEvent produceEvent() {
        Jobs runningJobs = jenkinsClient.getRunningJobs();
        if (!runningJobs.getNames().isEmpty()) {