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 */ 017package org.apache.activemq.store; 018 019import org.apache.activemq.management.StatsImpl; 020import org.apache.activemq.management.TimeStatisticImpl; 021 022public class PersistenceAdapterStatistics extends StatsImpl { 023 protected TimeStatisticImpl writeTime; 024 protected TimeStatisticImpl readTime; 025 026 public PersistenceAdapterStatistics() { 027 writeTime = new TimeStatisticImpl("writeTime", "Time to write data to the PersistentAdapter."); 028 readTime = new TimeStatisticImpl("readTime", "Time to read data from the PersistentAdapter."); 029 addStatistic("writeTime", writeTime); 030 addStatistic("readTime", readTime); 031 } 032 033 public void addWriteTime(final long time) { 034 writeTime.addTime(time); 035 } 036 037 public void addReadTime(final long time) { 038 readTime.addTime(time); 039 } 040 041 @Override 042 public void setEnabled(boolean enabled) { 043 super.setEnabled(enabled); 044 writeTime.setEnabled(enabled); 045 readTime.setEnabled(enabled); 046 } 047 048 public TimeStatisticImpl getWriteTime() { 049 return writeTime; 050 } 051 052 public TimeStatisticImpl getReadTime() { return readTime; } 053 054 @Override 055 public void reset() { 056 if (isDoReset()) { 057 writeTime.reset(); 058 readTime.reset(); 059 } 060 } 061 062 public void setParent(PersistenceAdapterStatistics parent) { 063 if (parent != null) { 064 writeTime.setParent(parent.writeTime); 065 readTime.setParent(parent.readTime); 066 } else { 067 writeTime.setParent(null); 068 readTime.setParent(null); 069 } 070 071 } 072}