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 * A minimal implementation of the EventHandler interface.
26 *
27 * @author Dirk Hünniger
28 *
29 */
30 public class SimpleEventHandler implements EventHandler {
31 /**
32 * The channel the handler is associated with
33 */
34 protected SelectableChannel channel;
35 /**
36 * the reactor the handler is registered with
37 */
38 protected Reactor reactor;
39 /**
40 * bitmask of the operation the handler is registered for
41 */
42 protected int registeredOperations;
43
44 /**
45 * class constructor
46 *
47 * @param r
48 * the reactor to register with
49 * @param ch
50 * the channel to use
51 */
52 public SimpleEventHandler(Reactor r, SelectableChannel ch) {
53 this.reactor = r;
54 this.channel = ch;
55 };
56
57 /**
58 * @see org.indi.reactor.EventHandler#register(int)
59 */
60 public void register(int ops) {
61 this.reactor.register(this, ops);
62 this.registeredOperations = ops;
63 };
64
65 /**
66 * @see org.indi.reactor.EventHandler#channel()
67 */
68 public SelectableChannel channel() {
69 return this.channel;
70 }
71
72 /**
73 * @see org.indi.reactor.EventHandler#onRead()
74 */
75 public void onRead() throws IOException {
76 throw new IOException();
77 };
78
79 /**
80 * @see org.indi.reactor.EventHandler#onAccept()
81 */
82 public void onAccept() throws IOException, ClosedChannelException {
83 throw new IOException();
84 };
85
86 /**
87 * @see org.indi.reactor.EventHandler#onConnect()
88 */
89 public void onConnect() throws IOException {
90 throw new IOException();
91 };
92
93 /**
94 * @see org.indi.reactor.EventHandler#onWrite()
95 */
96 public void onWrite() throws IOException {
97 throw new IOException();
98 };
99
100 /**
101 * @see org.indi.reactor.EventHandler#onClose()
102 */
103 public void onClose() {
104 };
105 }