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 slowCleanupTime; 024 protected TimeStatisticImpl slowWriteTime; 025 protected TimeStatisticImpl slowReadTime; 026 027 protected TimeStatisticImpl writeTime; 028 protected TimeStatisticImpl readTime; 029 030 public PersistenceAdapterStatistics() { 031 slowCleanupTime = new TimeStatisticImpl("slowCleanupTime", "Slow time to cleanup data in the PersistentAdapter."); 032 slowWriteTime = new TimeStatisticImpl("slowWriteTime", "Slow time to write data to the PersistentAdapter."); 033 slowReadTime = new TimeStatisticImpl("slowReadTime", "Slow time to read data from the PersistentAdapter."); 034 addStatistic("slowCleanupTime", slowCleanupTime); 035 addStatistic("slowWriteTime", slowWriteTime); 036 addStatistic("slowReadTime", slowReadTime); 037 038 writeTime = new TimeStatisticImpl("writeTime", "Time to write data to the PersistentAdapter."); 039 readTime = new TimeStatisticImpl("readTime", "Time to read data from the PersistentAdapter."); 040 addStatistic("writeTime", writeTime); 041 addStatistic("readTime", readTime); 042 } 043 044 public void addSlowCleanupTime(final long time) { 045 slowCleanupTime.addTime(time); 046 } 047 048 public void addSlowWriteTime(final long time) { 049 slowWriteTime.addTime(time); 050 } 051 052 public void addSlowReadTime(final long time) { 053 slowReadTime.addTime(time); 054 } 055 056 public void addWriteTime(final long time) { 057 writeTime.addTime(time); 058 } 059 060 public void addReadTime(final long time) { 061 readTime.addTime(time); 062 } 063 064 @Override 065 public void setEnabled(boolean enabled) { 066 super.setEnabled(enabled); 067 slowCleanupTime.setEnabled(enabled); 068 slowWriteTime.setEnabled(enabled); 069 slowReadTime.setEnabled(enabled); 070 writeTime.setEnabled(enabled); 071 readTime.setEnabled(enabled); 072 } 073 074 public TimeStatisticImpl getSlowCleanupTime() { 075 return slowCleanupTime; 076 } 077 078 public TimeStatisticImpl getSlowWriteTime() { 079 return slowWriteTime; 080 } 081 082 public TimeStatisticImpl getSlowReadTime() { return slowReadTime; } 083 084 085 public TimeStatisticImpl getWriteTime() { 086 return writeTime; 087 } 088 089 public TimeStatisticImpl getReadTime() { return readTime; } 090 091 @Override 092 public void reset() { 093 if (isDoReset()) { 094 writeTime.reset(); 095 readTime.reset(); 096 slowCleanupTime.reset(); 097 slowWriteTime.reset(); 098 slowReadTime.reset(); 099 } 100 } 101 102 public void setParent(PersistenceAdapterStatistics parent) { 103 if (parent != null) { 104 writeTime.setParent(parent.writeTime); 105 readTime.setParent(parent.readTime); 106 slowCleanupTime.setParent(parent.slowCleanupTime); 107 slowWriteTime.setParent(parent.slowWriteTime); 108 slowReadTime.setParent(parent.slowReadTime); 109 } else { 110 writeTime.setParent(null); 111 readTime.setParent(null); 112 slowCleanupTime.setParent(null); 113 slowWriteTime.setParent(null); 114 slowReadTime.setParent(null); 115 } 116 117 } 118}