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.client.connection.strategy.connector; 023 024import com.google.gwt.user.client.rpc.AsyncCallback; 025import de.novanic.eventservice.client.event.DomainEvent; 026import de.novanic.eventservice.client.event.listener.EventNotification; 027import de.novanic.eventservice.client.event.service.EventServiceAsync; 028 029import java.util.List; 030 031/** 032 * The {@link ConnectionStrategyClientConnector} listens for occurred events ({@link de.novanic.eventservice.client.event.Event}) 033 * of the server side and has the task to encode / process the transferred events at the client side. 034 * 035 * The {@link DefaultClientConnector} implements the listen method with simple calls to the {@link de.novanic.eventservice.client.event.service.EventServiceAsync} 036 * and no special encoding of the occurred events. 037 * 038 * @author sstrohschein 039 * <br>Date: 16.04.2010 040 * <br>Time: 23:24:00 041 */ 042public class DefaultClientConnector implements ConnectionStrategyClientConnector 043{ 044 private EventServiceAsync myEventService; 045 046 /** 047 * Initializes the {@link de.novanic.eventservice.client.connection.strategy.connector.ConnectionStrategyClientConnector} with 048 * the {@link de.novanic.eventservice.client.event.service.EventServiceAsync}. 049 * @param anEventService the {@link de.novanic.eventservice.client.event.service.EventServiceAsync} 050 */ 051 public void init(EventServiceAsync anEventService) { 052 myEventService = anEventService; 053 } 054 055 /** 056 * Deactivates the {@link de.novanic.eventservice.client.connection.strategy.connector.ConnectionStrategyClientConnector}. 057 */ 058 public void deactivate() {} 059 060 /** 061 * Checks if the {@link de.novanic.eventservice.client.connection.strategy.connector.ConnectionStrategyClientConnector} is 062 * initialized. 063 * @return true when the {@link de.novanic.eventservice.client.connection.strategy.connector.ConnectionStrategyClientConnector} is 064 * initialized, otherwise false 065 */ 066 public boolean isInitialized() { 067 return myEventService != null; 068 } 069 070 /** 071 * The listen method implements the listen / connection strategy to receive occurred events. The occurred events 072 * will be passed to the {@link de.novanic.eventservice.client.event.listener.EventNotification} and to the callback. 073 * The {@link DefaultClientConnector} implements the listen method with simple calls to the {@link de.novanic.eventservice.client.event.service.EventServiceAsync} 074 * and no special encoding of the occurred events. 075 * @param anEventNotification {@link de.novanic.eventservice.client.event.listener.EventNotification} which will be notified about occurred / received events 076 * @param aCallback The callback will be notified about occurred / received events. 077 */ 078 public void listen(EventNotification anEventNotification, AsyncCallback<List<DomainEvent>> aCallback) { 079 myEventService.listen(aCallback); 080 } 081}