NodeComponentDataDefine.java 5.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright 2017, OpenSkywalking Organization All rights reserved.
 *
 * Licensed 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.
 *
 * Project repository: https://github.com/OpenSkywalking/skywalking
 */

P
pengys5 已提交
19
package org.skywalking.apm.collector.storage.define.node;
P
pengys5 已提交
20

P
pengys5 已提交
21 22 23 24
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.core.stream.Transform;
import org.skywalking.apm.collector.core.stream.operate.CoverOperation;
import org.skywalking.apm.collector.core.stream.operate.NonOperation;
P
pengys5 已提交
25 26 27 28
import org.skywalking.apm.collector.remote.grpc.proto.RemoteData;
import org.skywalking.apm.collector.storage.define.Attribute;
import org.skywalking.apm.collector.storage.define.AttributeType;
import org.skywalking.apm.collector.storage.define.DataDefine;
P
pengys5 已提交
29 30 31 32 33 34 35

/**
 * @author pengys5
 */
public class NodeComponentDataDefine extends DataDefine {

    @Override protected int initialCapacity() {
P
pengys5 已提交
36
        return 6;
P
pengys5 已提交
37 38 39 40
    }

    @Override protected void attributeDefine() {
        addAttribute(0, new Attribute(NodeComponentTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
P
pengys5 已提交
41 42 43 44 45
        addAttribute(1, new Attribute(NodeComponentTable.COLUMN_COMPONENT_ID, AttributeType.INTEGER, new CoverOperation()));
        addAttribute(2, new Attribute(NodeComponentTable.COLUMN_COMPONENT_NAME, AttributeType.STRING, new CoverOperation()));
        addAttribute(3, new Attribute(NodeComponentTable.COLUMN_PEER_ID, AttributeType.INTEGER, new CoverOperation()));
        addAttribute(4, new Attribute(NodeComponentTable.COLUMN_PEER, AttributeType.STRING, new CoverOperation()));
        addAttribute(5, new Attribute(NodeComponentTable.COLUMN_TIME_BUCKET, AttributeType.LONG, new CoverOperation()));
P
pengys5 已提交
46 47 48
    }

    @Override public Object deserialize(RemoteData remoteData) {
49 50 51 52 53 54 55
        Data data = build(remoteData.getDataStrings(0));
        data.setDataInteger(0, remoteData.getDataIntegers(0));
        data.setDataString(1, remoteData.getDataStrings(1));
        data.setDataInteger(1, remoteData.getDataIntegers(1));
        data.setDataString(2, remoteData.getDataStrings(2));
        data.setDataLong(0, remoteData.getDataLongs(0));
        return data;
P
pengys5 已提交
56 57 58
    }

    @Override public RemoteData serialize(Object object) {
59 60 61 62 63 64 65 66 67
        Data data = (Data)object;
        RemoteData.Builder builder = RemoteData.newBuilder();
        builder.addDataStrings(data.getDataString(0));
        builder.addDataIntegers(data.getDataInteger(0));
        builder.addDataStrings(data.getDataString(1));
        builder.addDataIntegers(data.getDataInteger(1));
        builder.addDataStrings(data.getDataString(2));
        builder.addDataLongs(data.getDataLong(0));
        return builder.build();
P
pengys5 已提交
68 69
    }

70
    public static class NodeComponent implements Transform<NodeComponent> {
P
pengys5 已提交
71
        private String id;
P
pengys5 已提交
72 73 74 75
        private Integer componentId;
        private String componentName;
        private Integer peerId;
        private String peer;
76
        private long timeBucket;
P
pengys5 已提交
77 78 79 80

        public NodeComponent() {
        }

81
        @Override public Data toData() {
P
pengys5 已提交
82 83 84
            NodeComponentDataDefine define = new NodeComponentDataDefine();
            Data data = define.build(id);
            data.setDataString(0, this.id);
P
pengys5 已提交
85 86 87 88
            data.setDataInteger(0, this.componentId);
            data.setDataString(1, this.componentName);
            data.setDataInteger(1, this.peerId);
            data.setDataString(2, this.peer);
89
            data.setDataLong(0, this.timeBucket);
P
pengys5 已提交
90 91 92
            return data;
        }

93 94
        @Override public NodeComponent toSelf(Data data) {
            this.id = data.getDataString(0);
P
pengys5 已提交
95 96 97 98
            this.componentId = data.getDataInteger(0);
            this.componentName = data.getDataString(1);
            this.peerId = data.getDataInteger(1);
            this.peer = data.getDataString(2);
99
            this.timeBucket = data.getDataLong(0);
100 101 102
            return this;
        }

P
pengys5 已提交
103 104 105 106
        public String getId() {
            return id;
        }

107 108
        public long getTimeBucket() {
            return timeBucket;
109 110
        }

111 112
        public void setId(String id) {
            this.id = id;
P
pengys5 已提交
113 114
        }

115 116
        public void setTimeBucket(long timeBucket) {
            this.timeBucket = timeBucket;
P
pengys5 已提交
117
        }
P
pengys5 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

        public Integer getComponentId() {
            return componentId;
        }

        public void setComponentId(Integer componentId) {
            this.componentId = componentId;
        }

        public String getComponentName() {
            return componentName;
        }

        public void setComponentName(String componentName) {
            this.componentName = componentName;
        }

        public Integer getPeerId() {
            return peerId;
        }

        public void setPeerId(Integer peerId) {
            this.peerId = peerId;
        }

        public String getPeer() {
            return peer;
        }

        public void setPeer(String peer) {
            this.peer = peer;
        }
P
pengys5 已提交
150 151
    }
}