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.internal; 17 18 import net.sf.beep4j.Message; 19 20 /** 21 * A TransportMapping implements a transport mapping as described by 22 * section 2.5 of the BEEP specification (RFC 3080). The interface is meant to 23 * be generally applicable. But it could be that it needs some 24 * rework for other transport mappings as those specified by RFC 3081. 25 * 26 * <p>General responsibilities of implementors are:</p> 27 * <ul> 28 * <li>ensure that sent frames fit into the receivers advertised buffer window</li> 29 * <li>fragment messages into several frames as necessary</li> 30 * <li>validate that the other peer respects the local advertised buffer window</li> 31 * <li>process any transport specific mapping frame</li> 32 * </ul> 33 * 34 * @author Simon Raess 35 */ 36 public interface TransportMapping extends SessionListener { 37 38 /** 39 * Process a mapping frame. This method receives the header tokens. 40 * As the TCP mapping is currently the only existing mapping, this 41 * is sufficient. If there ever exists another mapping that defines 42 * a payload for mapping frames, some changes would have to be 43 * implemented. 44 * 45 * @param token the header tokens (i.e. header is split on spaces) 46 */ 47 void processMappingFrame(String[] token); 48 49 /** 50 * Checks that an incoming frame is valid. This method is called 51 * after the header has been parsed, but before the parsing of 52 * the body has started. 53 * 54 * @param channel the channel number of the message 55 * @param seqno the sequence number of the message 56 * @param size the payload size of the message 57 */ 58 void checkFrame(int channel, long seqno, int size); 59 60 /** 61 * Invoked by the framework to notify the mapping that the parsing 62 * of the message has completed. 63 * 64 * @param channel the channel number of the message 65 * @param seqno the sequence number of the message 66 * @param size the size of the message 67 */ 68 void frameReceived(int channel, long seqno, int size); 69 70 /** 71 * Sends a message of type MSG. 72 * 73 * @param channel the channel number 74 * @param messageNumber the message number 75 * @param message the message 76 */ 77 void sendMSG(int channel, int messageNumber, Message message); 78 79 /** 80 * Sends a message of type RPY. 81 * 82 * @param channel the channel number 83 * @param messageNumber the message number 84 * @param message the message 85 */ 86 void sendRPY(int channel, int messageNumber, Message message); 87 88 /** 89 * Sends a message of type ERR. 90 * 91 * @param channel the channel number 92 * @param messageNumber the message number 93 * @param message the message 94 */ 95 void sendERR(int channel, int messageNumber, Message message); 96 97 /** 98 * Sends a message of type ANS. 99 * 100 * @param channel the channel number 101 * @param messageNumber the message number 102 * @param message the message 103 */ 104 void sendANS(int channel, int messageNumber, int answerNumber, Message message); 105 106 /** 107 * Sends a message of type NUL. 108 * 109 * @param channel the channel number 110 * @param messageNumber the message number 111 * @param message the message 112 */ 113 void sendNUL(int channel, int messageNumber); 114 115 /** 116 * Instructs the mapping to close the underlying Transport object. 117 */ 118 void closeTransport(); 119 120 }