1 /*------------------------------------------------------------------------------
2 Name: RamQueuePlugin.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6
7 /**
8 * Class embedding messages or information to be stored on the client queues
9 * Note that all content is copied when passed to the constructors.
10 * This way this queue entry is the owner of the content (and therefore will
11 * delete it when its destructor is called).
12 *
13 * @author <a href='mailto:laghi@swissinfo.org'>Michele Laghi</a>
14 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/client.cpp.queue.html">The client.cpp.queue requirement</a>
15 */
16
17 #ifndef _UTIL_QUEUE_RAMQUEUE_H
18 #define _UTIL_QUEUE_RAMQUEUE_H
19
20 #include <util/xmlBlasterDef.h>
21 #include <util/ReferenceHolder.h>
22 #include <util/queue/I_Queue.h>
23 #include <util/queue/MsgQueueEntry.h>
24 #include <util/thread/ThreadImpl.h>
25 #include <util/I_Log.h>
26 #include <set>
27 #include <functional>
28
29 namespace org { namespace xmlBlaster { namespace util { namespace queue {
30
31 typedef std::set<EntryType, std::greater<EntryType> > StorageType;
32
33 class Dll_Export RamQueuePlugin : public I_Queue
34 {
35 protected:
36 std::string ME;
37 org::xmlBlaster::util::Global& global_;
38 org::xmlBlaster::util::I_Log& log_;
39 org::xmlBlaster::util::qos::storage::ClientQueueProperty property_;
40 StorageType storage_;
41 long numOfBytes_;
42 org::xmlBlaster::util::thread::Mutex accessMutex_;
43
44 public:
45 RamQueuePlugin(org::xmlBlaster::util::Global& global, const org::xmlBlaster::util::qos::storage::ClientQueueProperty& property);
46
47 RamQueuePlugin(const RamQueuePlugin& queue);
48
49 RamQueuePlugin& operator =(const RamQueuePlugin& queue);
50
51 virtual ~RamQueuePlugin();
52
53 /**
54 * puts a new entry into the queue.
55 * Note that this method takes the entry pointed to by the argument
56 * and puts a reference to it into the queue. This means that you can not destroy the entry before the
57 * reference to it has been removed from the queue (which normally happens on a remove or when destroying
58 * the queue.
59 */
60 void put(const MsgQueueEntry &entry);
61
62 /**
63 * Returns the entries with the highest priority in the queue. If 'maxNumOfEntries' is positive,
64 * this is the maximum number of entries to return. If maxNumOfBytes is positive, only the entries
65 * which fit into the range specified are returned. If there are no such entries, an empty std::vector is
66 * returned.
67 */
68 const std::vector<EntryType> peekWithSamePriority(long maxNumOfEntries=-1, long maxNumOfBytes=-1) const;
69
70 /**
71 * Deletes the entries specified in the std::vector in the argument list. If this std::vector is empty or if
72 * the queue is empty, zero (0) is returned, otherwise it returns the number of entries really deleted.
73 */
74 long randomRemove(const std::vector<EntryType>::const_iterator &start, const std::vector<EntryType>::const_iterator &end);
75
76 /**
77 * Access the current number of entries.
78 * @return The number of entries in the queue
79 */
80 long getNumOfEntries() const;
81
82 /**
83 * Access the configured maximum number of elements for this queue.
84 * @return The maximum number of elements in the queue
85 */
86 long getMaxNumOfEntries() const;
87
88 /**
89 * Returns the amount of bytes currently in the queue.
90 * If the implementation of this interface is not able to return the correct
91 * number of entries (for example if the implementation must make a remote
92 * call to a DB which is temporarly not available) it will return -1.
93 * @return The amount of bytes currently in the queue, returns -1 on error
94 */
95 int64_t getNumOfBytes() const;
96
97 /**
98 * Access the configured capacity (maximum bytes) for this queue.
99 * @return The maximum capacity for the queue in bytes
100 */
101 int64_t getMaxNumOfBytes() const;
102
103 /**
104 * Clears (removes all entries) this queue
105 */
106 void clear();
107
108 /**
109 * returns true if the queue is empty, false otherwise
110 */
111 bool empty() const;
112
113 /**
114 * Get the name of the plugin.
115 * @return "RAM"
116 * @enforcedBy I_Plugin
117 */
118 std::string getType() { static std::string type = "RAM"; return type; }
119
120 /**
121 * Get the version of the plugin.
122 * @return "1.0"
123 * @enforcedBy I_Plugin
124 */
125 std::string getVersion() { static std::string version = "1.0"; return version; }
126
127 void destroy() { return; }
128 };
129
130 }}}} // namespace
131
132 #endif
syntax highlighted by Code2HTML, v. 0.9.1