001/* 002 * GWTEventService 003 * Copyright (c) 2011 and beyond, strawbill UG (haftungsbeschr?nkt) 004 * 005 * This is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Lesser General Public License as 007 * published by the Free Software Foundation; either version 3 of 008 * the License, or (at your option) any later version. 009 * Other licensing for GWTEventService may also be possible on request. 010 * Please view the license.txt of the project for more information. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this software; if not, write to the Free 019 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 020 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 021 */ 022package de.novanic.eventservice.service.connection.strategy.connector.longpolling; 023 024import de.novanic.eventservice.client.event.DomainEvent; 025import de.novanic.eventservice.config.EventServiceConfiguration; 026import de.novanic.eventservice.service.EventServiceException; 027import de.novanic.eventservice.service.connection.strategy.connector.ConnectionStrategyServerConnectorAdapter; 028import de.novanic.eventservice.service.registry.user.UserInfo; 029 030import java.util.List; 031 032/** 033 * The {@link de.novanic.eventservice.service.connection.strategy.connector.longpolling.LongPollingServerConnector} implements 034 * the long-polling event listen method. Long-polling means that the connection is hold open for a specified time and when an event 035 * occurs, the answer / event is sent directly to the client. 036 * 037 * The {@link de.novanic.eventservice.service.connection.strategy.connector.ConnectionStrategyServerConnector} listens for occurring events ({@link de.novanic.eventservice.client.event.Event}) 038 * on the server side and has the task to prepare the transfer from the server side to the client side. 039 * @author sstrohschein 040 * <br>Date: 15.03.2010 041 * <br>Time: 23:00:24 042 */ 043public class LongPollingServerConnector extends ConnectionStrategyServerConnectorAdapter 044{ 045 /** 046 * Creates a new {@link de.novanic.eventservice.service.connection.strategy.connector.longpolling.LongPollingServerConnector}. 047 * The {@link de.novanic.eventservice.service.connection.strategy.connector.longpolling.LongPollingServerConnector} implements 048 * the long-polling event listen method. 049 * @param aConfiguration configuration 050 */ 051 public LongPollingServerConnector(EventServiceConfiguration aConfiguration) { 052 super(aConfiguration); 053 } 054 055 /** 056 * Listens for occurring events with the long-polling strategy. The connection is hold open for a specified time and when an event occurs, 057 * the answer / event is sent directly to the client. 058 * @param aUserInfo {@link de.novanic.eventservice.service.registry.user.UserInfo} which holds new occurred events 059 * @return occurred events 060 * @throws EventServiceException 061 */ 062 public List<DomainEvent> listen(UserInfo aUserInfo) throws EventServiceException { 063 waitMinWaitingTime(); 064 waitMaxWaitingTime(aUserInfo); 065 return aUserInfo.retrieveEvents(getConfiguration().getMaxEvents()); 066 } 067}