package votorola.a.diff.harvest.kick;// Copyright 2012. Christian Weilbach. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software") import java.util.Collections; import java.util.List; import java.util.LinkedList; import java.util.logging.Level; import java.util.logging.Logger; import votorola.a.diff.harvest.PipermailHarvester; import votorola.g.logging.LoggerX; /** * Service to pass kick-events from detectors to harvesters. */ public class Kicker { private static final Logger LOGGER = LoggerX.i(Kicker.class); /** * Implemented as singleton. */ public static Kicker i() { if (instance == null) { synchronized (Kicker.class) { try { instance = new Kicker(); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Could not initialize the kicker."); System.exit(1); } instance.initHarvesters(); } } return instance; } private static Kicker instance; private Kicker() { } private void initHarvesters() { new PipermailHarvester(); } final private List receivers = Collections .synchronizedList(new LinkedList()); /** * Passes a kick to all registered harvesters. * * @param kick */ public void broadcast(final Kick kick) { for (final KickReceiver r : receivers) { r.handle(kick); } } /** * Each Harvester has to register here. It then learns about each archive * through a {@linkplain UpdateKick}. * * @param receiver * to register. */ public void register(KickReceiver receiver) { receivers.add(receiver); } }