InstanceDataDefine.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.register;
P
pengys5 已提交
20

P
pengys5 已提交
21 22
import org.skywalking.apm.collector.core.stream.operate.CoverOperation;
import org.skywalking.apm.collector.core.stream.operate.NonOperation;
P
pengys5 已提交
23
import org.skywalking.apm.collector.remote.grpc.proto.RemoteData;
P
pengys5 已提交
24 25 26
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 已提交
27 28 29 30 31 32 33

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

    @Override protected int initialCapacity() {
P
pengys5 已提交
34
        return 7;
P
pengys5 已提交
35 36 37
    }

    @Override protected void attributeDefine() {
38
        addAttribute(0, new Attribute(InstanceTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
P
pengys5 已提交
39
        addAttribute(1, new Attribute(InstanceTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new CoverOperation()));
40
        addAttribute(2, new Attribute(InstanceTable.COLUMN_AGENT_UUID, AttributeType.STRING, new CoverOperation()));
P
pengys5 已提交
41 42
        addAttribute(3, new Attribute(InstanceTable.COLUMN_REGISTER_TIME, AttributeType.LONG, new CoverOperation()));
        addAttribute(4, new Attribute(InstanceTable.COLUMN_INSTANCE_ID, AttributeType.INTEGER, new CoverOperation()));
P
pengys5 已提交
43
        addAttribute(5, new Attribute(InstanceTable.COLUMN_HEARTBEAT_TIME, AttributeType.LONG, new CoverOperation()));
P
pengys5 已提交
44
        addAttribute(6, new Attribute(InstanceTable.COLUMN_OS_INFO, AttributeType.STRING, new CoverOperation()));
P
pengys5 已提交
45 46 47 48 49 50 51 52
    }

    @Override public Object deserialize(RemoteData remoteData) {
        String id = remoteData.getDataStrings(0);
        int applicationId = remoteData.getDataIntegers(0);
        String agentUUID = remoteData.getDataStrings(1);
        int instanceId = remoteData.getDataIntegers(1);
        long registerTime = remoteData.getDataLongs(0);
53
        long heartBeatTime = remoteData.getDataLongs(1);
P
pengys5 已提交
54 55
        String osInfo = remoteData.getDataStrings(2);
        return new Instance(id, applicationId, agentUUID, registerTime, instanceId, heartBeatTime, osInfo);
P
pengys5 已提交
56 57 58 59 60 61 62 63
    }

    @Override public RemoteData serialize(Object object) {
        Instance instance = (Instance)object;
        RemoteData.Builder builder = RemoteData.newBuilder();
        builder.addDataStrings(instance.getId());
        builder.addDataIntegers(instance.getApplicationId());
        builder.addDataStrings(instance.getAgentUUID());
P
pengys5 已提交
64
        builder.addDataIntegers(instance.getInstanceId());
P
pengys5 已提交
65
        builder.addDataLongs(instance.getRegisterTime());
66
        builder.addDataLongs(instance.getHeartBeatTime());
P
pengys5 已提交
67
        builder.addDataStrings(instance.getOsInfo());
P
pengys5 已提交
68 69 70 71
        return builder.build();
    }

    public static class Instance {
72 73 74 75 76
        private String id;
        private int applicationId;
        private String agentUUID;
        private long registerTime;
        private int instanceId;
77
        private long heartBeatTime;
P
pengys5 已提交
78
        private String osInfo;
P
pengys5 已提交
79

80
        public Instance(String id, int applicationId, String agentUUID, long registerTime, int instanceId,
P
pengys5 已提交
81 82
            long heartBeatTime,
            String osInfo) {
P
pengys5 已提交
83 84 85 86 87
            this.id = id;
            this.applicationId = applicationId;
            this.agentUUID = agentUUID;
            this.registerTime = registerTime;
            this.instanceId = instanceId;
88
            this.heartBeatTime = heartBeatTime;
P
pengys5 已提交
89 90 91 92
            this.osInfo = osInfo;
        }

        public Instance() {
P
pengys5 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        }

        public String getId() {
            return id;
        }

        public int getApplicationId() {
            return applicationId;
        }

        public String getAgentUUID() {
            return agentUUID;
        }

        public long getRegisterTime() {
            return registerTime;
        }

        public int getInstanceId() {
            return instanceId;
        }
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

        public void setId(String id) {
            this.id = id;
        }

        public void setApplicationId(int applicationId) {
            this.applicationId = applicationId;
        }

        public void setAgentUUID(String agentUUID) {
            this.agentUUID = agentUUID;
        }

        public void setRegisterTime(long registerTime) {
            this.registerTime = registerTime;
        }

        public void setInstanceId(int instanceId) {
            this.instanceId = instanceId;
        }
134 135 136 137 138 139 140 141

        public long getHeartBeatTime() {
            return heartBeatTime;
        }

        public void setHeartBeatTime(long heartBeatTime) {
            this.heartBeatTime = heartBeatTime;
        }
P
pengys5 已提交
142 143 144 145 146 147 148 149

        public String getOsInfo() {
            return osInfo;
        }

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