qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r594647 - in /incubator/qpid/trunk/qpid/cpp/src/qpid: broker/Message.cpp framing/FrameSet.cpp framing/TypeFilter.h framing/frame_functors.h
Date Tue, 13 Nov 2007 21:33:16 GMT
Author: aconway
Date: Tue Nov 13 13:33:16 2007
New Revision: 594647

URL: http://svn.apache.org/viewvc?rev=594647&view=rev
Log:

Stopped frameset from assembling messages piecewise.
Roughly halves allocations on the broker, not much effect on client.

Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Message.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameSet.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/TypeFilter.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/frame_functors.h

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Message.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Message.cpp?rev=594647&r1=594646&r2=594647&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Message.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Message.cpp Tue Nov 13 13:33:16 2007
@@ -74,7 +74,7 @@
 {
     //add up payload for all header and content frames in the frameset
     SumBodySize sum;
-    frames.map_if(sum, TypeFilter(HEADER_BODY, CONTENT_BODY));
+    frames.map_if(sum, TypeFilter2<HEADER_BODY, CONTENT_BODY>());
     return sum.getSize();
 }
 
@@ -82,18 +82,18 @@
 {
     //encode method and header frames
     EncodeFrame f1(buffer);
-    frames.map_if(f1, TypeFilter(METHOD_BODY, HEADER_BODY));
+    frames.map_if(f1, TypeFilter2<METHOD_BODY, HEADER_BODY>());
 
     //then encode the payload of each content frame
     EncodeBody f2(buffer);
-    frames.map_if(f2, TypeFilter(CONTENT_BODY));
+    frames.map_if(f2, TypeFilter<CONTENT_BODY>());
 }
 
 void Message::encodeContent(framing::Buffer& buffer) const
 {
     //encode the payload of each content frame
     EncodeBody f2(buffer);
-    frames.map_if(f2, TypeFilter(CONTENT_BODY));
+    frames.map_if(f2, TypeFilter<CONTENT_BODY>());
 }
 
 uint32_t Message::encodedSize() const
@@ -110,7 +110,7 @@
 {
     //add up the size for all method and header frames in the frameset
     SumFrameSize sum;
-    frames.map_if(sum, TypeFilter(METHOD_BODY, HEADER_BODY));
+    frames.map_if(sum, TypeFilter2<METHOD_BODY, HEADER_BODY>());
     return sum.getSize();
 }
 
@@ -137,7 +137,7 @@
     } else {
         //adjust header flags
         MarkLastSegment f;
-        frames.map_if(f, TypeFilter(HEADER_BODY));    
+        frames.map_if(f, TypeFilter<HEADER_BODY>());    
     }
     //mark content loaded
     loaded = true;
@@ -152,7 +152,7 @@
         store->stage(*this);
     }
     //remove any content frames from the frameset
-    frames.remove(TypeFilter(CONTENT_BODY));
+    frames.remove(TypeFilter<CONTENT_BODY>());
     setContentReleased();
 }
 
@@ -183,17 +183,17 @@
 
     } else {
         Count c;
-        frames.map_if(c, TypeFilter(CONTENT_BODY));
+        frames.map_if(c, TypeFilter<CONTENT_BODY>());
 
         SendContent f(out, maxFrameSize, c.getCount());
-        frames.map_if(f, TypeFilter(CONTENT_BODY));
+        frames.map_if(f, TypeFilter<CONTENT_BODY>());
     }
 }
 
 void Message::sendHeader(framing::FrameHandler& out, uint16_t /*maxFrameSize*/) const
 {
     Relay f(out);
-    frames.map_if(f, TypeFilter(HEADER_BODY));    
+    frames.map_if(f, TypeFilter<HEADER_BODY>());    
 }
 
 // FIXME aconway 2007-11-09: Obsolete, remove. Was used to cover over

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameSet.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameSet.cpp?rev=594647&r1=594646&r2=594647&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameSet.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/FrameSet.cpp Tue Nov 13 13:33:16 2007
@@ -64,18 +64,20 @@
 uint64_t FrameSet::getContentSize() const
 {
     SumBodySize sum;
-    map_if(sum, TypeFilter(CONTENT_BODY));
+    map_if(sum, TypeFilter<CONTENT_BODY>());
     return sum.getSize();
 }
 
-void FrameSet::getContent(std::string& out) const
-{
-    AccumulateContent accumulator(out);
-    map_if(accumulator, TypeFilter(CONTENT_BODY));
+void FrameSet::getContent(std::string& out) const {
+    out.clear();
+    out.reserve(getContentSize());
+    for(Frames::const_iterator i = parts.begin(); i != parts.end(); i++) {
+        if (i->getBody()->type() == CONTENT_BODY)
+            out += i->castBody<AMQContentBody>()->getData();
+    }
 }
 
-std::string FrameSet::getContent() const
-{
+std::string FrameSet::getContent() const {
     std::string out;
     getContent(out);
     return out;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/TypeFilter.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/TypeFilter.h?rev=594647&r1=594646&r2=594647&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/TypeFilter.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/TypeFilter.h Tue Nov 13 13:33:16 2007
@@ -1,3 +1,6 @@
+#ifndef QPID_FRAMING_TYPEFILTER_H
+#define QPID_FRAMING_TYPEFILTER_H
+
 /*
  *
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -23,30 +26,26 @@
 #include "qpid/framing/AMQFrame.h"
 #include "qpid/framing/FrameHandler.h"
 
-#ifndef _TypeFilter_
-#define _TypeFilter_
-
 namespace qpid {
 namespace framing {
 
 /**
  * Predicate that selects frames by type
  */
-class TypeFilter
-{
-    std::vector<uint8_t> types;
-public:
-    TypeFilter(uint8_t type) { add(type); }
-    TypeFilter(uint8_t type1, uint8_t type2) { add(type1); add(type2); }
-    void add(uint8_t type) { types.push_back(type); }
-    bool operator()(const AMQFrame& f) const 
-    { 
-        return find(types.begin(), types.end(), f.getBody()->type()) != types.end(); 
-    } 
+template <uint8_t Type>
+struct TypeFilter {
+    bool operator()(const AMQFrame& f) const {
+        return f.getBody()->type() == Type;
+    }
 };
 
-}
-}
+template <uint8_t T1, uint8_t T2>
+struct TypeFilter2 {
+    bool operator()(const AMQFrame& f) const {
+        return f.getBody()->type() == T1 || f.getBody()->type() == T2;
+    }
+};
 
+}} // namespace qpid::framing
 
-#endif
+#endif  /*!QPID_FRAMING_TYPEFILTER_H*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/frame_functors.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/frame_functors.h?rev=594647&r1=594646&r2=594647&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/frame_functors.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/frame_functors.h Tue Nov 13 13:33:16 2007
@@ -74,14 +74,6 @@
     void operator()(const AMQFrame& f) { f.getBody()->encode(buffer); }
 };
 
-class AccumulateContent
-{
-    std::string& content;
-public:
-    AccumulateContent(std::string& c) : content(c) {}
-    void operator()(const AMQFrame& f) { content += f.castBody<AMQContentBody>()->getData();
}
-};
-
 /**
  * Sends a copy of the frame its applied to to the specified handler
  */



Mime
View raw message