001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.activemq.usage;
018
019 import org.apache.activemq.store.kahadb.plist.PListStore;
020
021
022 /**
023 * Used to keep track of how much of something is being used so that a
024 * productive working set usage can be controlled. Main use case is manage
025 * memory usage.
026 *
027 * @org.apache.xbean.XBean
028 *
029 */
030 public class TempUsage extends Usage<TempUsage> {
031
032 private PListStore store;
033
034 public TempUsage() {
035 super(null, null, 1.0f);
036 }
037
038 public TempUsage(String name, PListStore store) {
039 super(null, name, 1.0f);
040 this.store = store;
041 }
042
043 public TempUsage(TempUsage parent, String name) {
044 super(parent, name, 1.0f);
045 this.store = parent.store;
046 }
047
048 @Override
049 protected long retrieveUsage() {
050 if (store == null) {
051 return 0;
052 }
053 return store.size();
054 }
055
056 public PListStore getStore() {
057 return store;
058 }
059
060 public void setStore(PListStore store) {
061 this.store = store;
062 onLimitChange();
063 }
064 }