PageRenderTime 43ms CodeModel.GetById 18ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/impl/monitor/LocalExecutorOperationStatsImpl.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 108 lines | 74 code | 19 blank | 15 comment | 4 complexity | 254f94020d053f30d11ea224566fbbf6 MD5 | raw file
  1/*
  2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 *
  8 * http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS,
 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 * See the License for the specific language governing permissions and
 14 * limitations under the License.
 15 */
 16
 17package com.hazelcast.impl.monitor;
 18
 19import com.hazelcast.monitor.LocalExecutorOperationStats;
 20
 21import java.io.DataInput;
 22import java.io.DataOutput;
 23import java.io.IOException;
 24import java.util.concurrent.atomic.AtomicLong;
 25
 26public class LocalExecutorOperationStatsImpl extends LocalOperationStatsSupport implements LocalExecutorOperationStats  {
 27    private String executorName;
 28    final AtomicLong pending = new AtomicLong(0);
 29    final AtomicLong started = new AtomicLong(0);
 30    final AtomicLong startLatency = new AtomicLong(0);
 31    final AtomicLong completed = new AtomicLong(0);
 32    final AtomicLong completionTime = new AtomicLong(0);
 33    final AtomicLong minCompletionTime = new AtomicLong(Long.MAX_VALUE);
 34    final AtomicLong maxCompletionTime = new AtomicLong(Long.MIN_VALUE);
 35
 36
 37    public LocalExecutorOperationStatsImpl(String executorName) {
 38        this.executorName = executorName;
 39    }
 40
 41    public String getExecutorName() {
 42        return executorName;
 43    }
 44
 45    public long getPending() {
 46        return pending.get();
 47    }
 48
 49    public long getStarted() {
 50        return started.get();
 51    }
 52
 53    public long getStartLatency() {
 54        return startLatency.get();
 55    }
 56
 57    public long getAverageStartLatency() {
 58        if(started.get() == 0)
 59            return 0;
 60        return startLatency.get() / started.get();
 61    }
 62
 63    public long getCompleted() {
 64        return completed.get();
 65    }
 66
 67    public long getCompletionTime() {
 68        return completionTime.get();
 69    }
 70
 71    public long getMinCompletionTime() {
 72        return minCompletionTime.get();
 73    }
 74
 75    public long getAverageCompletionTime() {
 76        if(completed.get() == 0) {
 77            return 0;
 78        }
 79        return completionTime.get() / completed.get();
 80    }
 81
 82    public long getMaxCompletionTime() {
 83        return maxCompletionTime.get();
 84    }
 85
 86    public void writeDataInternal(DataOutput out) throws IOException {
 87        out.writeUTF(executorName);
 88        out.writeLong(pending.get());
 89        out.writeLong(started.get());
 90        out.writeLong(startLatency.get());
 91        out.writeLong(completed.get());
 92        out.writeLong(completionTime.get());
 93        out.writeLong(minCompletionTime.get());
 94        out.writeLong(maxCompletionTime.get());
 95    }
 96
 97    public void readDataInternal(DataInput in) throws IOException {
 98        executorName = in.readUTF();
 99        pending.set(in.readLong());
100        started.set(in.readLong());
101        startLatency.set(in.readLong());
102        completed.set(in.readLong());
103        completionTime.set(in.readLong());
104        minCompletionTime.set(in.readLong());
105        maxCompletionTime.set(in.readLong());
106    }
107
108}