| 1 |
/* |
| 2 |
* |
| 3 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 4 |
* or more contributor license agreements. See the NOTICE file |
| 5 |
* distributed with this work for additional information |
| 6 |
* regarding copyright ownership. The ASF licenses this file |
| 7 |
* to you under the Apache License, Version 2.0 (the |
| 8 |
* "License"); you may not use this file except in compliance |
| 9 |
* with the License. You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, |
| 14 |
* software distributed under the License is distributed on an |
| 15 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 |
* KIND, either express or implied. See the License for the |
| 17 |
* specific language governing permissions and limitations |
| 18 |
* under the License. |
| 19 |
* |
| 20 |
*/ |
| 21 |
package org.apache.qpid.proton.engine; |
| 22 |
|
| 23 |
import org.apache.qpid.proton.codec.ReadableBuffer; |
| 24 |
|
| 25 |
/** |
| 26 |
* Sender |
| 27 |
* |
| 28 |
*/ |
| 29 |
public interface Sender extends Link |
| 30 |
{ |
| 31 |
|
| 32 |
/** |
| 33 |
* indicates pending deliveries |
| 34 |
* |
| 35 |
* @param credits the number of pending deliveries |
| 36 |
*/ |
| 37 |
//TODO is this absolute or cumulative? |
| 38 |
public void offer(int credits); |
| 39 |
|
| 40 |
/** |
| 41 |
* Sends some data for the current delivery. The application may call this method multiple |
| 42 |
* times for the same delivery. |
| 43 |
* |
| 44 |
* @param bytes the byte array containing the data to be sent. |
| 45 |
* @param offset the offset into the given array to start reading. |
| 46 |
* @param length the number of bytes to read from the given byte array. |
| 47 |
* |
| 48 |
* @return the number of bytes accepted |
| 49 |
* |
| 50 |
* TODO Proton-j current copies all the bytes it has been given so the return value will always be |
| 51 |
* length. Should this be changed? How does Proton-c behave? What should the application do if |
| 52 |
* the number of bytes accepted is smaller than length. |
| 53 |
*/ |
| 54 |
public int send(byte[] bytes, int offset, int length); |
| 55 |
|
| 56 |
/** |
| 57 |
* Sends some data for the current delivery. The application may call this method multiple |
| 58 |
* times for the same delivery. |
| 59 |
* |
| 60 |
* @param buffer the buffer to read the data from. |
| 61 |
* |
| 62 |
* @return the number of bytes read from the provided buffer. |
| 63 |
*/ |
| 64 |
public int send(ReadableBuffer buffer); |
| 65 |
|
| 66 |
/** |
| 67 |
* Sends data to the current delivery attempting not to copy the data unless a previous |
| 68 |
* send has already added data to the Delivery in which case a copy may occur depending on |
| 69 |
* the implementation. |
| 70 |
* <p> |
| 71 |
* Care should be taken when passing ReadableBuffer instances that wrapped pooled bytes |
| 72 |
* as the send does not mean the data will be sent immediately when the transport is |
| 73 |
* flushed so the pooled bytes could be held for longer than expected. |
| 74 |
* |
| 75 |
* @param buffer |
| 76 |
* An immutable ReadableBuffer that can be held until the next transport flush. |
| 77 |
* |
| 78 |
* @return the number of bytes read from the provided buffer. |
| 79 |
*/ |
| 80 |
public int sendNoCopy(ReadableBuffer buffer); |
| 81 |
|
| 82 |
/** |
| 83 |
* Abort the current delivery. |
| 84 |
* |
| 85 |
* Note "pn_link_abort" is commented out in the .h |
| 86 |
*/ |
| 87 |
public void abort(); |
| 88 |
|
| 89 |
/** |
| 90 |
* {@inheritDoc} |
| 91 |
* |
| 92 |
* Informs the sender that all the bytes of the current {@link Delivery} have been written. |
| 93 |
* The application must call this method in order for the delivery to be considered complete. |
| 94 |
* |
| 95 |
* @see #send(byte[], int, int) |
| 96 |
* |
| 97 |
* TODO fully state the rules regarding when you have to call this method, what happens if you don't call it |
| 98 |
* before creating another delivery etc. |
| 99 |
*/ |
| 100 |
@Override |
| 101 |
public boolean advance(); |
| 102 |
|
| 103 |
} |