001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016 017package com.echothree.util.server.persistence; 018 019import org.slf4j.Logger; 020import org.slf4j.LoggerFactory; 021 022public class SessionEntityCacheStatistics { 023 024 protected final Logger log = LoggerFactory.getLogger(this.getClass()); 025 026 public long readOnlyUpgradedToReadWrite; 027 public long putReadOnlyEntity; 028 public long putReadWriteEntityToParent; 029 public long putReadWriteEntity; 030 public long gotEntityFromReadWrite; 031 public long gotEntityFromReadOnly; 032 public long gotEntityFromParent; 033 public long entityNotGotten; 034 public long finalReadWriteCount; 035 public long finalReadOnlyCount; 036 037 public long getCacheHits() { 038 return gotEntityFromReadWrite + gotEntityFromReadOnly + gotEntityFromParent; 039 } 040 041 public long getCacheAttempts() { 042 return getCacheHits() + entityNotGotten; 043 } 044 045 public void Add(SessionEntityCacheStatistics sessionEntityCacheStatistics) { 046 this.readOnlyUpgradedToReadWrite += sessionEntityCacheStatistics.readOnlyUpgradedToReadWrite; 047 this.putReadOnlyEntity += sessionEntityCacheStatistics.putReadOnlyEntity; 048 this.putReadWriteEntityToParent += sessionEntityCacheStatistics.putReadWriteEntityToParent; 049 this.putReadWriteEntity += sessionEntityCacheStatistics.putReadWriteEntity; 050 this.gotEntityFromReadWrite += sessionEntityCacheStatistics.gotEntityFromReadWrite; 051 this.gotEntityFromReadOnly += sessionEntityCacheStatistics.gotEntityFromReadOnly; 052 this.gotEntityFromParent += sessionEntityCacheStatistics.gotEntityFromParent; 053 this.entityNotGotten += sessionEntityCacheStatistics.entityNotGotten; 054 this.finalReadWriteCount += sessionEntityCacheStatistics.finalReadWriteCount; 055 this.finalReadOnlyCount += sessionEntityCacheStatistics.finalReadOnlyCount; 056 } 057 058 public void dumpStats() { 059 log.info("ReadOnlyUpgradedToReadWrite = " + readOnlyUpgradedToReadWrite); 060 log.info("PutReadOnlyEntity = " + putReadOnlyEntity); 061 log.info("PutReadWriteEntityToParent = " + putReadWriteEntityToParent); 062 log.info("PutReadWriteEntity = " + putReadWriteEntity); 063 log.info("GotEntityFromReadWrite = " + gotEntityFromReadWrite); 064 log.info("GotEntityFromReadOnly = " + gotEntityFromReadOnly); 065 log.info("GotEntityFromParent = " + gotEntityFromParent); 066 log.info("EntityNotGotten = " + entityNotGotten); 067 log.info("CacheHits = " + getCacheHits()); 068 log.info("CacheAttempts = " + getCacheAttempts()); 069 log.info("FinalReadWriteCount = " + finalReadWriteCount); 070 log.info("FinalReadOnlyCount = " + finalReadOnlyCount); 071 } 072 073}