activemq-cpp-3.4.0

src/main/activemq/util/MemoryUsage.h

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef _ACTIVEMQ_UTIL_MEMORYUSAGE_H_
00019 #define _ACTIVEMQ_UTIL_MEMORYUSAGE_H_
00020 
00021 #include <activemq/util/Config.h>
00022 #include <activemq/util/Usage.h>
00023 #include <decaf/util/concurrent/Mutex.h>
00024 
00025 namespace activemq {
00026 namespace util {
00027 
00028     class AMQCPP_API MemoryUsage : public Usage {
00029     private:
00030 
00031         // The physical limit of memory usage this object allows.
00032         unsigned long long limit;
00033 
00034         // Amount of memory currently used in.
00035         unsigned long long usage;
00036 
00037         // Mutex to lock usage and wait on.
00038         mutable decaf::util::concurrent::Mutex mutex;
00039 
00040     public:
00041 
00045         MemoryUsage();
00046 
00051         MemoryUsage( unsigned long long limit );
00052 
00053         virtual ~MemoryUsage();
00054 
00058         virtual void waitForSpace();
00059 
00065         virtual void waitForSpace( unsigned int timeout );
00066 
00072         virtual void enqueueUsage( unsigned long long value ) {
00073             waitForSpace();
00074             increaseUsage(value);
00075         }
00076 
00081         virtual void increaseUsage( unsigned long long value );
00082 
00087         virtual void decreaseUsage( unsigned long long value );
00088 
00092         virtual bool isFull() const;
00093 
00098         unsigned long long getUsage() const {
00099             return usage;
00100         }
00101 
00106         void setUsage( unsigned long long usage ) {
00107             this->usage = usage;
00108         }
00109 
00114         unsigned long long getLimit() const {
00115             return limit;
00116         }
00117 
00122         void setLimit( unsigned long long limit ) {
00123             this->limit = limit;
00124         }
00125 
00126     };
00127 
00128 }}
00129 
00130 #endif /*_ACTIVEMQ_UTIL_MEMORYUSAGE_H_*/