// Path: cicomponents-api/src/main/java/org/cicomponents/ResourceListener.java
// @FunctionalInterface
// public interface ResourceListener<T extends Resource> {
//     void onEmittedResource(ResourceHolder<T> holder,
//                            ResourceEmitter<T> emitter);
// 
//     default boolean isMatchingListener(Class klass) {
//         for (Type type : getClass().getGenericInterfaces()) {
//             if (type instanceof ParameterizedType &&
//                     ((ParameterizedType) type).getRawType() == ResourceListener.class) {
//                 ParameterizedType parameterizedType = (ParameterizedType) type;
//                 Type target = parameterizedType.getActualTypeArguments()[0];
//                 if (target == klass) {
//                     return true;
//                 }
//             }
//         }
//         return false;
//     }
// }
// 
// Path: cicomponents-github-api/src/main/java/org/cicomponents/github/GithubPullRequest.java
// public interface GithubPullRequest extends GitRevision {
//     GHPullRequest getPullRequest();
// }
// 
// Path: cicomponents-github-api/src/main/java/org/cicomponents/github/GithubPullRequestEmitter.java
// public interface GithubPullRequestEmitter extends ResourceEmitter<GithubPullRequest> {
//     String getRepository();
//     void onPullRequestEvent(int number);
// }


import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.cicomponents.ResourceListener;
import org.cicomponents.github.GithubPullRequest;
import org.cicomponents.github.GithubPullRequestEmitter;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.*;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Map;
import java.util.function.Consumer;
            consumer.accept(service);
            context.getBundleContext().ungetService(reference);
        }
    }


    @SneakyThrows
    @Activate
    protected void activate(ComponentContext context) {
        log.info("Activating with {} potential listener(s)", listeners.size());
        forEachService(context, (emitter) -> {
            if (emitter instanceof AbstractGithubPullRequestEmitter) {
                ((AbstractGithubPullRequestEmitter) emitter).pause();
            }
        });
        for (Map.Entry<Map<String, Object>, ResourceListener<GithubPullRequest>> listener : listeners) {
            if (listener.getValue().isMatchingListener(GithubPullRequest.class)) {
                Map<String, Object> props = listener.getKey();
                String filter = getEmitterFilter(props);
                Collection<ServiceReference<GithubPullRequestEmitter>> references =
                        context.getBundleContext().getServiceReferences(GithubPullRequestEmitter.class, filter);

                if (!references.isEmpty()) {
                    log.info("Adding GithubPullRequest listener {} {}" + listener.getValue(), props);
                    for (ServiceReference<GithubPullRequestEmitter> reference : references) {
                        GithubPullRequestEmitter service = context.getBundleContext().getService(reference);
                        service.addResourceListener(listener.getValue());
                        context.getBundleContext().ungetService(reference);
                    }
                } else {
// Path: cicomponents-api/src/main/java/org/cicomponents/ResourceListener.java
// @FunctionalInterface
// public interface ResourceListener<T extends Resource> {
//     void onEmittedResource(ResourceHolder<T> holder,
//                            ResourceEmitter<T> emitter);
// 
//     default boolean isMatchingListener(Class klass) {
//         for (Type type : getClass().getGenericInterfaces()) {
//             if (type instanceof ParameterizedType &&
//                     ((ParameterizedType) type).getRawType() == ResourceListener.class) {
//                 ParameterizedType parameterizedType = (ParameterizedType) type;
//                 Type target = parameterizedType.getActualTypeArguments()[0];
//                 if (target == klass) {
//                     return true;
//                 }
//             }
//         }
//         return false;
//     }
// }
// 
// Path: cicomponents-github-api/src/main/java/org/cicomponents/github/GithubPullRequest.java
// public interface GithubPullRequest extends GitRevision {
//     GHPullRequest getPullRequest();
// }
// 
// Path: cicomponents-github-api/src/main/java/org/cicomponents/github/GithubPullRequestEmitter.java
// public interface GithubPullRequestEmitter extends ResourceEmitter<GithubPullRequest> {
//     String getRepository();
//     void onPullRequestEvent(int number);
// }


// Path: cicomponents-github/src/main/java/org/cicomponents/github/impl/GithubEmitterProvider.java
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.cicomponents.ResourceListener;
import org.cicomponents.github.GithubPullRequest;
import org.cicomponents.github.GithubPullRequestEmitter;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.*;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Map;
import java.util.function.Consumer;

            consumer.accept(service);
            context.getBundleContext().ungetService(reference);
        }
    }


    @SneakyThrows
    @Activate
    protected void activate(ComponentContext context) {
        log.info("Activating with {} potential listener(s)", listeners.size());
        forEachService(context, (emitter) -> {
            if (emitter instanceof AbstractGithubPullRequestEmitter) {
                ((AbstractGithubPullRequestEmitter) emitter).pause();
            }
        });
        for (Map.Entry<Map<String, Object>, ResourceListener<GithubPullRequest>> listener : listeners) {
            if (listener.getValue().isMatchingListener(GithubPullRequest.class)) {
                Map<String, Object> props = listener.getKey();
                String filter = getEmitterFilter(props);
                Collection<ServiceReference<GithubPullRequestEmitter>> references =
                        context.getBundleContext().getServiceReferences(GithubPullRequestEmitter.class, filter);

                if (!references.isEmpty()) {
                    log.info("Adding GithubPullRequest listener {} {}" + listener.getValue(), props);
                    for (ServiceReference<GithubPullRequestEmitter> reference : references) {
                        GithubPullRequestEmitter service = context.getBundleContext().getService(reference);
                        service.addResourceListener(listener.getValue());
                        context.getBundleContext().ungetService(reference);
                    }
                } else {
                    log.info("Starting GithubPullRequest for listener {} {}", listener.getValue(), props);