summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferMessage.java
blob: 08006435f8e5c59c333253e7253b7695adbef5c9 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 *
 * 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.message;

import org.apache.qpid.transport.*;
import org.apache.qpid.server.configuration.SessionConfig;
import org.apache.qpid.server.store.StoredMessage;
import org.apache.qpid.server.transport.ServerSession;

import java.nio.ByteBuffer;
import java.lang.ref.WeakReference;


public class MessageTransferMessage implements InboundMessage, ServerMessage
{


    private StoredMessage<MessageMetaData_0_10> _storeMessage;


    private WeakReference<Session> _sessionRef;

    public MessageTransferMessage(StoredMessage<MessageMetaData_0_10> storeMessage, WeakReference<Session> sessionRef)
    {

        _storeMessage = storeMessage;
        _sessionRef = sessionRef;
    }

    private MessageMetaData_0_10 getMetaData()
    {
        return _storeMessage.getMetaData();
    }

    public String getRoutingKey()
    {
        return getMetaData().getRoutingKey();

    }

    public AMQMessageHeader getMessageHeader()
    {
        return getMetaData().getMessageHeader();
    }

    public boolean isPersistent()
    {
        return getMetaData().isPersistent();
    }


    public boolean isRedelivered()
    {
        // The *Message* is never redelivered, only queue entries are... this is here so that filters
        // can run against the message on entry to an exchange
        return false;
    }

    public long getSize()
    {

        return getMetaData().getSize();
    }

    public boolean isImmediate()
    {
        return getMetaData().isImmediate();
    }

    public long getExpiration()
    {
        return getMetaData().getExpiration();
    }

    public MessageReference newReference()
    {
        return new TransferMessageReference(this);
    }

    public Long getMessageNumber()
    {
        return _storeMessage.getMessageNumber();
    }

    public long getArrivalTime()
    {
        return getMetaData().getArrivalTime();
    }

    public int getContent(ByteBuffer buf, int offset)
    {
        return _storeMessage.getContent(offset, buf);
    }

    public Header getHeader()
    {
        return getMetaData().getHeader();
    }

    public ByteBuffer getBody()
    {
        ByteBuffer body = getMetaData().getBody();
        if(body == null && getSize() != 0l)
        {
            final int size = (int) getSize();
            int pos = 0;
            body = ByteBuffer.allocate(size);

            while(pos < size)
            {
                pos += getContent(body, pos);
            }

            body.flip();

            getMetaData().setBody(body.duplicate());
        }
        return body;
    }

    public Session getSession()
    {
        return _sessionRef == null ? null : _sessionRef.get();
    }

    public SessionConfig getSessionConfig()
    {
        return _sessionRef == null ? null : (ServerSession) _sessionRef.get();
    }
    
}