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.transport;
17
18 import java.net.SocketAddress;
19 import java.nio.ByteBuffer;
20
21 /**
22 * The TransportContext defines the methods that a Transport implementation
23 * can use to notify the BEEP implementation about important events.
24 *
25 * @author Simon Raess
26 */
27 public interface TransportContext {
28
29 /**
30 * Notifies the context that the physical connection has
31 * been established. This allows the BEEP peer to start initializing the
32 * BEEP session by sending the greeting.
33 *
34 * @param address the SocketAddress of the remote peer
35 */
36 void connectionEstablished(SocketAddress address);
37
38 /**
39 * Invoked by the Transport to notify the context about an exception
40 * that has been caught while sending or processing a message.
41 *
42 * @param cause the causing exception
43 */
44 void exceptionCaught(Throwable cause);
45
46 /**
47 * Invoked by the Transport whenever new content has been received.
48 * This method is invoked whenever a new chunk of bytes arrives.
49 * There is no guarantee whatsoever that the received buffer contains
50 * a full message. Only the application knows what constitutes a
51 * message.
52 *
53 * @param buffer the received bytes
54 */
55 void messageReceived(ByteBuffer buffer);
56
57 /**
58 * Invoked by the Transport when the underlying physical connection
59 * has been closed.
60 */
61 void connectionClosed();
62
63 }