protected void flushBuffer() {
    synchronized (buffer) {
      if (buffer.size() == 0) {
        return;
      }
      System.out.println("Flush Buffer " + buffer.size());

      for (Entry<Subscriber, List<EventObject>> es : buffer.entrySet()) {

        eventsAPI.push(es.getKey(), es.getValue());
      }
      buffer.clear();
    }
  }
  private void fire(String eventID, Object dls, String collapseKey) {
    synchronized (this) {
      ArrayList<Subscriber> subscribers = eventsAPI.getSubscribers();
      final SimpleEventObject eventObject = new SimpleEventObject(this, eventID, dls, collapseKey);
      RemoteAPIController.getInstance()
          .getEventSender()
          .fireEvent(
              new RemoteAPIInternalEvent() {

                @Override
                public void fireTo(RemoteAPIInternalEventListener listener) {
                  listener.onRemoteAPIEvent(eventObject);
                }
              });
      for (Subscriber subscriber : subscribers) {

        pushToBuffer(subscriber, eventObject);
      }
    }
  }
 public DownloadControllerEventPublisher(EventsAPI eventsapi) {
   RemoteAPIController.validateInterfaces(
       DownloadControllerEventPublisherInterface.class, DownloadsEventsInterface.class);
   this.eventsAPI = eventsapi;
   eventsapi.getLocalEventSender().addListener(this);
 }