summaryrefslogtreecommitdiff
path: root/java/broker/src/main/java/org/apache/qpid/server/txn/ServerTransaction.java
blob: c568ae67aae98cdec0c95ccadc155861cf298e31 (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
/*
 *
 * 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.server.txn;

import java.util.Collection;
import java.util.List;
import org.apache.qpid.server.message.EnqueableMessage;
import org.apache.qpid.server.queue.BaseQueue;
import org.apache.qpid.server.queue.QueueEntry;


/**
 * The ServerTransaction interface allows a set enqueue/dequeue operations to be
 * performed against the transaction belonging the underlying TransactionLog object.
 * 
 * Typically all ServerTransaction implementations decide if a message should be enlisted
 * into a store transaction by examining the durable property of the queue, and the persistence
 * property of the message. 
 * 
 * A caller may register a list of post transaction Actions to be
 * performed on commit() (or rollback()).
 * 
 */
public interface ServerTransaction
{


    /**
     * Represents an action to be performed on transaction commit or rollback
     */
    public static interface Action
    {
        public void postCommit();

        public void onRollback();
    }

    /**
     * Return the time the current transaction started.
     * 
     * @return the time this transaction started or 0 if not in a transaction
     */
    long getTransactionStartTime();

    /** 
     * Register an Action for execution after transaction commit or rollback.  Actions
     * will be executed in the order in which they are registered.
     */
    void addPostTransactionAction(Action postTransactionAction);

    /** 
     * Dequeue a message from a queue registering a post transaction action.
     * 
     * A store operation will result only for a persistent message on a durable queue.
     */
    void dequeue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction);

    /** 
     * Dequeue a message(s) from queue(s) registering a post transaction action.
     * 
     * Store operations will result only for a persistent messages on durable queues.
     */
    void dequeue(Collection<QueueEntry> messages, Action postTransactionAction);

    /** 
     * Enqueue a message to a queue registering a post transaction action.
     * 
     * A store operation will result only for a persistent message on a durable queue.
     */
    void enqueue(BaseQueue queue, EnqueableMessage message, Action postTransactionAction);

    /** 
     * Enqueue a message(s) to queue(s) registering a post transaction action.
     * 
     * Store operations will result only for a persistent messages on durable queues.
     */
    void enqueue(List<? extends BaseQueue> queues, EnqueableMessage message, Action postTransactionAction, long currentTime);

    /** 
     * Commit the transaction represented by this object.
     * 
     * If the caller has registered one or more Actions, the postCommit() method on each will
     * be executed immediately after the underlying transaction has committed. 
     */
    void commit();

    void commit(Runnable immediatePostTransactionAction);

    /** Rollback the transaction represented by this object.
     * 
     * If the caller has registered one or more Actions, the onRollback() method on each will
     * be executed immediately after the underlying transaction has rolled-back. 
     */
    void rollback();

    boolean isTransactional();
}