summaryrefslogtreecommitdiff
path: root/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/Session.java
blob: 1d1b10e580e911b08645762659ba82f01af6fec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.qpid.messaging;

/**
 * A session represents a distinct 'conversation' which can involve sending and receiving messages to and from different addresses.
 */
public interface Session
{
    /**
     * Returns true if the session is closed.
     */
    public boolean isClosed();

    /**
     * Closes a session and all associated senders and receivers.
     */
    public void  close();

    /**
     * Commits all messages sent or received during the current transaction.
     */
    public void commit();

    /**
     * Rolls back all messages sent or received during the current transaction.
     */
    public void rollback();

    /**
     * Acknowledges all outstanding messages that have been received by the application on this session.
     * @param sync If true, request synchronization with the peer.
     */
    public void acknowledge(boolean sync);

    /**
     * Acknowledges the specified message.
     * @param message The message to be acknowledged
     * @param sync If true, request synchronization with the peer.
     */
    public <T> void acknowledge (Message message, boolean sync);

    /**
     * Rejects the specified message.
     * @param message The message to be rejected.
     */
    public <T> void reject(Message message);

    /**
     * Releases the specified message.
     * @param message The message to be released.
     */
    public <T> void release(Message message);

    /**
     * Request synchronization with the peer.
     * @param block If true, block until synchronization is complete.
     */
    public void sync(boolean block);

    /**
     * Returns the total number of messages received and waiting to be fetched by all Receivers belonging to this session.
     */
    public int getReceivable();

    /**
     * Returns The number of messages received by this session that have been acknowledged, but for which that acknowledgment has not yet been confirmed by the peer.
     */
    public int getUnsettledAcks();

    /**
     * Returns the receiver for the next available message.
     * This method blocks until a message arrives or the timeout expires.
     * A timeout of zero never expires, and the call blocks indefinitely until a message arrives.
     * @param timeout The timeout value in milliseconds.
     * @return The receiver for the next available message.
     */
    public Receiver nextReceiver(long timeout);

    /**
     * Create a new sender through which messages can be sent to the specified address.
     * @param address @see Address
     */
    public Sender createSender(Address address);

    /**
     * Create a new sender through which messages can be sent to the specified address.
     * @param address The string containing a valid address @see Address for the format.
     */
    public Sender createSender (String address);

    /**
     * Create a new receiver through which messages can be received from the specified address.
     * @param address @see Address
     */
    public Receiver createReceiver (Address address);

    /**
     * Create a new receiver through which messages can be received from the specified address.
     * @param address The string containing a valid address @see Address for the format.
     */
    public Receiver createReceiver (String address);

    /**
     * Returns the connection this session is associated with.
     * @return
     */
    public Connection getConnection();
}