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.tcp; 17 18 import net.sf.beep4j.Message; 19 20 /** 21 * Controller object that knows about the channel's send and receive 22 * buffers. It's main purpose is sending SEQ frames when the controller 23 * thinks that's necessary as well as to fragment / queue outgoing 24 * messages to respect the window of the other peer. 25 * 26 * @author Simon Raess 27 */ 28 public interface ChannelController { 29 30 /** 31 * To be invoked whenever a SEQ frame is received to update the sender 32 * window. The window start will be placed at <var>ackno</var> and 33 * the size will be updated to <var>size</var>. Note that the position 34 * will remain unaffected. If ackno is larger than the window size 35 * the communication with the other peer should be stopped as the 36 * peers lost the synchronization. 37 * 38 * @param ackno the acknowledged sequence number 39 * @param size the size of the window 40 */ 41 void updateSendWindow(long ackno, int size); 42 43 /** 44 * Send an ANS message with the given messageNumber and answerNumber on 45 * the channel of this controller. 46 * 47 * @param messageNumber the message number of the message 48 * @param answerNumber the answer number of the message 49 * @param message the Message to be sent 50 */ 51 void sendANS(int messageNumber, int answerNumber, Message message); 52 53 /** 54 * Sends an NUL message with the given messageNumber on the channel 55 * of this controller. 56 * 57 * @param messageNumber the message number of the Message 58 */ 59 void sendNUL(int messageNumber); 60 61 /** 62 * Sends an ERR message with the given messageNumber on the channel 63 * of this controller. 64 * 65 * @param messageNumber the message number of the Message 66 * @param message the Message to be sent 67 */ 68 void sendERR(int messageNumber, Message message); 69 70 /** 71 * Sends an MSG message with the given messageNumber on the channel 72 * of this controller. 73 * 74 * @param messageNumber the message number of the Message 75 * @param message the Message to be sent 76 */ 77 void sendMSG(int messageNumber, Message message); 78 79 /** 80 * Sends an RPY message with the given messageNumber on the channel 81 * of this controller. 82 * 83 * @param messageNumber the message number of the Message 84 * @param message the Message to be sent 85 */ 86 void sendRPY(int messageNumber, Message message); 87 88 /** 89 * <p>Validation of the sequence number according to the BEEP specification section 90 * 2.2.1.1.</p> 91 * 92 * <p>A frame is poorly formed if the value of the sequence number doesn't 93 * correspond to the expected value for the associated channel.</p> 94 * 95 * <p>Further, this method checks that the payload size is not greater than 96 * the remaining buffer space.</p> 97 */ 98 void checkFrame(long seqno, int payloadSize); 99 100 /** 101 * Notifies the controller that the frame with sequence number <var>seqno</var> 102 * and size <var>size</var> has been completely received. 103 * 104 * @param seqno the sequence number of the frame 105 * @param size the size of the frame 106 */ 107 void frameReceived(long seqno, int size); 108 109 }