@Override public LoadingCache<CacheKey, List<TransientActionFactory<?>>> load(final ExtensionList<TransientActionFactory> allFactories) throws Exception { final LoadingCache<CacheKey, List<TransientActionFactory<?>>> perJenkinsCache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<TransientActionFactory<?>>>() { @Override public List<TransientActionFactory<?>> load(CacheKey key) throws Exception { List<TransientActionFactory<?>> factories = new ArrayList<>(); for (TransientActionFactory<?> taf : allFactories) { Class<? extends Action> actionType = taf.actionType(); if (taf.type().isAssignableFrom(key.type) && (key.actionType.isAssignableFrom(actionType) || actionType.isAssignableFrom(key.actionType))) { factories.add(taf); } } return factories; } }); allFactories.addListener(new ExtensionListListener() { @Override public void onChange() { perJenkinsCache.invalidateAll(); } }); return perJenkinsCache; } });
/** * Install this listener to the Downloadable extension list after all extensions have been loaded; we only * care about those that are added after initialization */ @Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED) public static void installListener() { ExtensionList.lookup(Downloadable.class).addListener(new DownloadableListener()); }
@Initializer(after= JOB_LOADED) public static void init() { // start all PeriodicWorks ExtensionList<PeriodicWork> extensionList = all(); extensionList.addListener(new PeriodicWorkExtensionListListener(extensionList)); for (PeriodicWork p : extensionList) { schedulePeriodicWork(p); } }
@Initializer(after= JOB_LOADED) public static void init() { // start all AperidocWorks ExtensionList<AperiodicWork> extensionList = all(); extensionList.addListener(new AperiodicWorkExtensionListListener(extensionList)); for (AperiodicWork p : AperiodicWork.all()) { scheduleAperiodWork(p); } }
@Override public LoadingCache<CacheKey, List<TransientActionFactory<?>>> load(final ExtensionList<TransientActionFactory> allFactories) throws Exception { final LoadingCache<CacheKey, List<TransientActionFactory<?>>> perJenkinsCache = CacheBuilder.newBuilder().build(new CacheLoader<CacheKey, List<TransientActionFactory<?>>>() { @Override public List<TransientActionFactory<?>> load(CacheKey key) throws Exception { List<TransientActionFactory<?>> factories = new ArrayList<>(); for (TransientActionFactory<?> taf : allFactories) { Class<? extends Action> actionType = taf.actionType(); if (taf.type().isAssignableFrom(key.type) && (key.actionType.isAssignableFrom(actionType) || actionType.isAssignableFrom(key.actionType))) { factories.add(taf); } } return factories; } }); allFactories.addListener(new ExtensionListListener() { @Override public void onChange() { perJenkinsCache.invalidateAll(); } }); return perJenkinsCache; } });
/** * Install this listener to the Downloadable extension list after all extensions have been loaded; we only * care about those that are added after initialization */ @Initializer(after = InitMilestone.EXTENSIONS_AUGMENTED) public static void installListener() { ExtensionList.lookup(Downloadable.class).addListener(new DownloadableListener()); }
/** * Get the installed {@link PubsubBus} implementation. * @return The installed {@link PubsubBus} implementation, or default * implementation if none are found. */ public synchronized static @Nonnull PubsubBus getBus() { if (pubsubBus == null) { ExtensionList<PubsubBus> installedBusImpls = ExtensionList.lookup(PubsubBus.class); if (!installedBusImpls.isEmpty()) { pubsubBus = installedBusImpls.get(0); } else { pubsubBus = new GuavaPubsubBus(); } // Register the auto-subscribers. registerAutoChannelSubscribers(pubsubBus); // And listen for new ones being installed e.g. after a plugin is installed. ExtensionList.lookup(AbstractChannelSubscriber.class).addListener(new ExtensionListListener() { @Override public void onChange() { registerAutoChannelSubscribers(pubsubBus); } }); } return pubsubBus; }