|
| 1 | +/* |
| 2 | + * Licensed to ElasticSearch and Shay Banon under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. ElasticSearch licenses this |
| 6 | + * file to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.index.fielddata; |
| 21 | + |
| 22 | +import org.elasticsearch.common.io.stream.StreamInput; |
| 23 | +import org.elasticsearch.common.io.stream.StreamOutput; |
| 24 | +import org.elasticsearch.common.io.stream.Streamable; |
| 25 | +import org.elasticsearch.common.unit.ByteSizeValue; |
| 26 | +import org.elasticsearch.common.xcontent.ToXContent; |
| 27 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 28 | +import org.elasticsearch.common.xcontent.XContentBuilderString; |
| 29 | + |
| 30 | +import java.io.IOException; |
| 31 | + |
| 32 | +/** |
| 33 | + */ |
| 34 | +public class FieldDataStats implements Streamable, ToXContent { |
| 35 | + |
| 36 | + long memorySize; |
| 37 | + |
| 38 | + public FieldDataStats() { |
| 39 | + |
| 40 | + } |
| 41 | + |
| 42 | + public FieldDataStats(long memorySize) { |
| 43 | + this.memorySize = memorySize; |
| 44 | + } |
| 45 | + |
| 46 | + public void add(FieldDataStats stats) { |
| 47 | + this.memorySize += stats.memorySize; |
| 48 | + } |
| 49 | + |
| 50 | + public long getMemorySizeInBytes() { |
| 51 | + return this.memorySize; |
| 52 | + } |
| 53 | + |
| 54 | + public ByteSizeValue getMemorySize() { |
| 55 | + return new ByteSizeValue(memorySize); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public void readFrom(StreamInput in) throws IOException { |
| 60 | + memorySize = in.readVLong(); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public void writeTo(StreamOutput out) throws IOException { |
| 65 | + out.writeVLong(memorySize); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
| 70 | + builder.startObject(Fields.FIELD_DATA); |
| 71 | + builder.field(Fields.MEMORY_SIZE, memorySize); |
| 72 | + builder.field(Fields.MEMORY_SIZE_IN_BYTES, getMemorySize().toString()); |
| 73 | + builder.endObject(); |
| 74 | + return builder; |
| 75 | + } |
| 76 | + |
| 77 | + static final class Fields { |
| 78 | + static final XContentBuilderString FIELD_DATA = new XContentBuilderString("field_data"); |
| 79 | + static final XContentBuilderString MEMORY_SIZE = new XContentBuilderString("memory_size"); |
| 80 | + static final XContentBuilderString MEMORY_SIZE_IN_BYTES = new XContentBuilderString("memory_size_in_bytes"); |
| 81 | + } |
| 82 | +} |
0 commit comments