001/* 002 * Ad Hoc Polling Application 003 * Copyright (C) 2018 Michael N. Lipp 004 * 005 * This program is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Affero General Public License as published by 007 * the Free Software Foundation; either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, but 011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 013 * for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License along 016 * with this program; if not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jgrapes.io; 020 021import org.jgrapes.core.Channel; 022import org.jgrapes.core.Component; 023import org.jgrapes.core.annotation.Handler; 024import org.jgrapes.io.events.Close; 025import org.jgrapes.io.events.Purge; 026 027/** 028 * A component that handles {@link Purge} events 029 * by unconditionally firing a {@link Close} events as response. 030 */ 031public class PurgeTerminator extends Component { 032 033 /** 034 * @param componentChannel 035 */ 036 public PurgeTerminator(Channel componentChannel) { 037 super(componentChannel); 038 } 039 040 /** 041 * Handles a {@link Purge} event by sending a {@link Close} event. 042 * 043 * @param event the event 044 * @param channel the channel 045 */ 046 @Handler 047 public void onPurge(Purge event, IOSubchannel channel) { 048 // Needn't close this more than once 049 event.stop(); 050 channel.respond(new Close()); 051 } 052}