Beispiel #1
0
 @Override
 public void listen(
     final RemoteAPIRequest request, final RemoteAPIResponse response, final long subscriptionid)
     throws APIFileNotFoundException, InternalApiException {
   final Subscriber subscriber = this.subscribers.get(subscriptionid);
   if (subscriber == null) {
     throw new APIFileNotFoundException();
   }
   final ArrayList<EventObject> events = new ArrayList<EventObject>();
   final ArrayList<EventObjectStorable> eventStorables = new ArrayList<EventObjectStorable>();
   try {
     EventObject event;
     while ((event = subscriber.poll(events.size() == 0 ? subscriber.getPollTimeout() : 0)) != null
         && this.subscribers.get(subscriptionid) == subscriber) {
       events.add(event);
       eventStorables.add(new EventObjectStorable(event));
     }
   } catch (final InterruptedException e) {
   }
   try {
     response.getRemoteAPI().writeStringResponse(eventStorables, null, request, response);
   } catch (final Throwable e) {
     subscriber.pushBack(events);
     throw new InternalApiException(e);
   }
 }