activemq-cpp-3.8.2
MemoryUsage.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _ACTIVEMQ_UTIL_MEMORYUSAGE_H_
19 #define _ACTIVEMQ_UTIL_MEMORYUSAGE_H_
20 
21 #include <activemq/util/Config.h>
22 #include <activemq/util/Usage.h>
24 
25 namespace activemq {
26 namespace util {
27 
28  class AMQCPP_API MemoryUsage : public Usage {
29  private:
30 
31  // The physical limit of memory usage this object allows.
32  unsigned long long limit;
33 
34  // Amount of memory currently used in.
35  unsigned long long usage;
36 
37  // Mutex to lock usage and wait on.
38  mutable decaf::util::concurrent::Mutex mutex;
39 
40  public:
41 
45  MemoryUsage();
46 
51  MemoryUsage(unsigned long long limit);
52 
53  virtual ~MemoryUsage();
54 
58  virtual void waitForSpace();
59 
65  virtual void waitForSpace(unsigned int timeout);
66 
72  virtual void enqueueUsage(unsigned long long value) {
73  waitForSpace();
74  increaseUsage(value);
75  }
76 
81  virtual void increaseUsage(unsigned long long value);
82 
87  virtual void decreaseUsage(unsigned long long value);
88 
92  virtual bool isFull() const;
93 
98  unsigned long long getUsage() const {
99  return usage;
100  }
101 
106  void setUsage(unsigned long long usage) {
107  this->usage = usage;
108  }
109 
114  unsigned long long getLimit() const {
115  return limit;
116  }
117 
122  void setLimit(unsigned long long limit) {
123  this->limit = limit;
124  }
125 
126  };
127 
128 }}
129 
130 #endif /*_ACTIVEMQ_UTIL_MEMORYUSAGE_H_*/
unsigned long long getUsage() const
Gets the current usage amount.
Definition: MemoryUsage.h:98
Mutex object that offers recursive support on all platforms as well as providing the ability to use t...
Definition: Mutex.h:39
Definition: Usage.h:26
#define AMQCPP_API
Definition: Config.h:30
unsigned long long getLimit() const
Gets the current limit amount.
Definition: MemoryUsage.h:114
Definition: MemoryUsage.h:28
virtual void enqueueUsage(unsigned long long value)
Tries to increase the usage by value amount but blocks if this object is currently full...
Definition: MemoryUsage.h:72
void setLimit(unsigned long long limit)
Sets the current limit amount.
Definition: MemoryUsage.h:122
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: CachedConsumer.h:24
void setUsage(unsigned long long usage)
Sets the current usage amount.
Definition: MemoryUsage.h:106