1 /*
2 Copyright (C) 2007 Dirk Huenniger
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 package org.indi.reactor;
19
20 import java.io.IOException;
21 import java.nio.channels.ClosedChannelException;
22 import java.nio.channels.SelectableChannel;
23
24 /**
25 * Basic Handler class for IO events.
26 *
27 * @author Dirk Hünniger
28 *
29 */
30 public interface EventHandler {
31 /**
32 * @return the SelectableChannel for which this Handler is to be
33 * listening
34 */
35 public SelectableChannel channel();
36
37 /**
38 * Called by the reactor whenever data is ready for reading.
39 *
40 * @throws java.io.IOException
41 */
42 public void onRead() throws java.io.IOException;
43
44 /**
45 * Called by the reactor whenever a new connection is ready to be
46 * accepted (passive connection establishment)
47 *
48 * @throws java.io.IOException
49 * @throws ClosedChannelException
50 */
51 public void onAccept() throws java.io.IOException, ClosedChannelException;
52
53 /**
54 * Called by the reactor whenever a new Connection is ready to be
55 * estabished (active connection establishment)
56 *
57 * @throws java.io.IOException
58 */
59 public void onConnect() throws java.io.IOException;
60
61 /**
62 * Called by the reactor whenever a connection is ready for writing
63 *
64 * @throws java.io.IOException
65 */
66 public void onWrite() throws java.io.IOException;
67
68 /**
69 * Called by the reactor when the handler is removed
70 */
71 public void onClose();
72
73 /**
74 * Register the handler with the reactor for certain IO events
75 *
76 * @param ops
77 * Bitmask descibing the events the handler is to be
78 * registered for
79 * @throws ClosedChannelException
80 * @throws IOException
81 */
82 public void register(int ops) throws ClosedChannelException, IOException;
83 }