begin_unit|revision:0.9.5;language:Java;cregit-version:0.0.1
begin_comment
comment|/*  * Licensed to the Apache Software Foundation (ASF) under one or more  * contributor license agreements.  See the NOTICE file distributed with  * this work for additional information regarding copyright ownership.  * The ASF licenses this file to You under the Apache License, Version 2.0  * (the "License"); you may not use this file except in compliance with  * the License.  You may obtain a copy of the License at  *  *      http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  *  */
end_comment

begin_package
package|package
name|org
operator|.
name|apache
operator|.
name|jackrabbit
operator|.
name|oak
operator|.
name|segment
operator|.
name|file
package|;
end_package

begin_import
import|import static
name|java
operator|.
name|util
operator|.
name|concurrent
operator|.
name|TimeUnit
operator|.
name|NANOSECONDS
import|;
end_import

begin_import
import|import
name|java
operator|.
name|io
operator|.
name|File
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|jackrabbit
operator|.
name|oak
operator|.
name|segment
operator|.
name|spi
operator|.
name|monitor
operator|.
name|IOMonitorAdapter
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|jackrabbit
operator|.
name|oak
operator|.
name|stats
operator|.
name|MeterStats
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|jackrabbit
operator|.
name|oak
operator|.
name|stats
operator|.
name|StatisticsProvider
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|jackrabbit
operator|.
name|oak
operator|.
name|stats
operator|.
name|StatsOptions
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|jackrabbit
operator|.
name|oak
operator|.
name|stats
operator|.
name|TimerStats
import|;
end_import

begin_import
import|import
name|org
operator|.
name|jetbrains
operator|.
name|annotations
operator|.
name|NotNull
import|;
end_import

begin_comment
comment|/**  * This {@code IOMonitor} implementations registers the following monitoring endpoints  * with the Metrics library if available:  *<ul>  *<li>{@link #OAK_SEGMENT_SEGMENT_READ_BYTES}:  *          a meter metrics for the number of bytes read from tar files</li>  *<li>{@link #OAK_SEGMENT_SEGMENT_WRITE_BYTES}:  *          a meter metrics for the number of bytes written to tar files</li>  *<li>{@link #OAK_SEGMENT_SEGMENT_READ_TIME}:  *          a timer metrics for the time spent reading from tar files</li>  *<li>{@link #OAK_SEGMENT_SEGMENT_WRITE_TIME}:  *          a timer metrics for the time spent writing to tar files</li>  *</ul>  */
end_comment

begin_class
specifier|public
class|class
name|MetricsIOMonitor
extends|extends
name|IOMonitorAdapter
block|{
specifier|public
specifier|static
specifier|final
name|String
name|OAK_SEGMENT_SEGMENT_READ_BYTES
init|=
literal|"oak.segment.segment-read-bytes"
decl_stmt|;
specifier|public
specifier|static
specifier|final
name|String
name|OAK_SEGMENT_SEGMENT_WRITE_BYTES
init|=
literal|"oak.segment.segment-write-bytes"
decl_stmt|;
specifier|public
specifier|static
specifier|final
name|String
name|OAK_SEGMENT_SEGMENT_READ_TIME
init|=
literal|"oak.segment.segment-read-time"
decl_stmt|;
specifier|public
specifier|static
specifier|final
name|String
name|OAK_SEGMENT_SEGMENT_WRITE_TIME
init|=
literal|"oak.segment.segment-write-time"
decl_stmt|;
specifier|private
specifier|final
name|MeterStats
name|segmentReadBytes
decl_stmt|;
specifier|private
specifier|final
name|MeterStats
name|segmentWriteBytes
decl_stmt|;
specifier|private
specifier|final
name|TimerStats
name|segmentReadTime
decl_stmt|;
specifier|private
specifier|final
name|TimerStats
name|segmentWriteTime
decl_stmt|;
specifier|public
name|MetricsIOMonitor
parameter_list|(
annotation|@
name|NotNull
name|StatisticsProvider
name|statisticsProvider
parameter_list|)
block|{
name|segmentReadBytes
operator|=
name|statisticsProvider
operator|.
name|getMeter
argument_list|(
name|OAK_SEGMENT_SEGMENT_READ_BYTES
argument_list|,
name|StatsOptions
operator|.
name|METRICS_ONLY
argument_list|)
expr_stmt|;
name|segmentWriteBytes
operator|=
name|statisticsProvider
operator|.
name|getMeter
argument_list|(
name|OAK_SEGMENT_SEGMENT_WRITE_BYTES
argument_list|,
name|StatsOptions
operator|.
name|METRICS_ONLY
argument_list|)
expr_stmt|;
name|segmentReadTime
operator|=
name|statisticsProvider
operator|.
name|getTimer
argument_list|(
name|OAK_SEGMENT_SEGMENT_READ_TIME
argument_list|,
name|StatsOptions
operator|.
name|METRICS_ONLY
argument_list|)
expr_stmt|;
name|segmentWriteTime
operator|=
name|statisticsProvider
operator|.
name|getTimer
argument_list|(
name|OAK_SEGMENT_SEGMENT_WRITE_TIME
argument_list|,
name|StatsOptions
operator|.
name|METRICS_ONLY
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Override
specifier|public
name|void
name|afterSegmentRead
parameter_list|(
name|File
name|file
parameter_list|,
name|long
name|msb
parameter_list|,
name|long
name|lsb
parameter_list|,
name|int
name|length
parameter_list|,
name|long
name|elapsed
parameter_list|)
block|{
name|segmentReadBytes
operator|.
name|mark
argument_list|(
name|length
argument_list|)
expr_stmt|;
name|segmentReadTime
operator|.
name|update
argument_list|(
name|elapsed
argument_list|,
name|NANOSECONDS
argument_list|)
expr_stmt|;
block|}
annotation|@
name|Override
specifier|public
name|void
name|afterSegmentWrite
parameter_list|(
name|File
name|file
parameter_list|,
name|long
name|msb
parameter_list|,
name|long
name|lsb
parameter_list|,
name|int
name|length
parameter_list|,
name|long
name|elapsed
parameter_list|)
block|{
name|segmentWriteBytes
operator|.
name|mark
argument_list|(
name|length
argument_list|)
expr_stmt|;
name|segmentWriteTime
operator|.
name|update
argument_list|(
name|elapsed
argument_list|,
name|NANOSECONDS
argument_list|)
expr_stmt|;
block|}
block|}
end_class

end_unit

