View Javadoc

1   /*
2    *  Copyright 2006 Simon Raess
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package net.sf.beep4j;
17  
18  
19  /**
20   * Represents the incoming view of a channel. The interface contains 
21   * callback methods which are invoked when the channel is established
22   * ({@link #channelOpened(Channel)}), when a request from the
23   * remote peer is received 
24   * ({@link #receiveRequest(Channel, Message, Reply)}), or 
25   * when the channel has been closed
26   * ({@link #channelClosed(Channel)}).
27   * 
28   * @author Simon Raess
29   */
30  public interface ChannelHandler {
31  	
32  	/**
33  	 * Invoked by the framework when the channel has been successfully
34  	 * started.
35  	 * 
36  	 * @param c the channel that was opened
37  	 */
38  	void channelOpened(Channel c);
39  	
40  	/**
41  	 * Invoked by the framework when the channel could not be started.
42  	 * 
43  	 * @param code the error code
44  	 * @param message the human readable error message
45  	 */
46  	void channelStartFailed(int code, String message);
47  	
48  	/**
49  	 * Invoked by the framework when the other peer sent a message
50  	 * to this peer on this channel. 
51  	 * 
52  	 * @param c the channel on which the message was received
53  	 * @param message the received message
54  	 * @param reply the handler used to return a response.
55  	 */
56  	void messageReceived(Message message, Reply reply);
57  	
58  	/**
59  	 * Invoked by the framework when the other peer requested to
60  	 * close the channel. 
61  	 * 
62  	 * @param request the request
63  	 */
64  	void channelCloseRequested(CloseChannelRequest request);
65  	
66  	/**
67  	 * Invoked by the framework when the other peer decided to close
68  	 * this channel.
69  	 * 
70  	 * @param c the Channel that was closed
71  	 */
72  	void channelClosed();
73  	
74  }