01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * 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.server.queue;
22
23 import org.apache.qpid.AMQException;
24 import org.apache.qpid.framing.ContentHeaderBody;
25 import org.apache.qpid.framing.abstraction.ContentChunk;
26 import org.apache.qpid.framing.abstraction.MessagePublishInfo;
27 import org.apache.qpid.server.store.StoreContext;
28 import org.apache.qpid.server.transactionlog.TransactionLog;
29
30 public class PersistentAMQMessage extends TransientAMQMessage
31 {
32 protected TransactionLog _transactionLog;
33
34 public PersistentAMQMessage(Long messageId, TransactionLog transactionLog)
35 {
36 super(messageId);
37 _transactionLog = transactionLog;
38 }
39
40 @Override
41 public void addContentBodyFrame(StoreContext storeContext, ContentChunk contentChunk, boolean isLastContentBody)
42 throws AMQException
43 {
44 super.addContentBodyFrame(storeContext, contentChunk, isLastContentBody);
45 _transactionLog.storeContentBodyChunk(storeContext, _messageId, _contentBodies.size() - 1,
46 contentChunk, isLastContentBody);
47 }
48
49 @Override
50 public void setPublishAndContentHeaderBody(StoreContext storeContext, MessagePublishInfo messagePublishInfo,
51 ContentHeaderBody contentHeaderBody)
52 throws AMQException
53 {
54 super.setPublishAndContentHeaderBody(storeContext, messagePublishInfo, contentHeaderBody);
55 MessageMetaData mmd = new MessageMetaData(messagePublishInfo, contentHeaderBody, _contentBodies == null ? 0 : _contentBodies.size(), _arrivalTime);
56
57 _transactionLog.storeMessageMetaData(storeContext, _messageId, mmd);
58 }
59
60 @Override
61 public boolean isPersistent()
62 {
63 return true;
64 }
65
66 public void recoverFromMessageMetaData(MessageMetaData mmd)
67 {
68 _arrivalTime = mmd.getArrivalTime();
69 _contentHeaderBody = mmd.getContentHeaderBody();
70 _messagePublishInfo = mmd.getMessagePublishInfo();
71 }
72
73 public void recoverContentBodyFrame(ContentChunk contentChunk, boolean isLastContentBody) throws AMQException
74 {
75 super.addContentBodyFrame(null, contentChunk, isLastContentBody);
76 }
77
78 }
|