ServiceEntryDataDefine.java 5.9 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.service;
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;
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 ServiceEntryDataDefine extends DataDefine {

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

    @Override protected void attributeDefine() {
        addAttribute(0, new Attribute(ServiceEntryTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
41
        addAttribute(1, new Attribute(ServiceEntryTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new CoverOperation()));
42
        addAttribute(2, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, AttributeType.INTEGER, new CoverOperation()));
43
        addAttribute(3, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, AttributeType.STRING, new CoverOperation()));
44 45
        addAttribute(4, new Attribute(ServiceEntryTable.COLUMN_REGISTER_TIME, AttributeType.LONG, new NonOperation()));
        addAttribute(5, new Attribute(ServiceEntryTable.COLUMN_NEWEST_TIME, 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.setDataInteger(1, remoteData.getDataIntegers(1));
        data.setDataString(1, remoteData.getDataStrings(1));
        data.setDataLong(0, remoteData.getDataLongs(0));
        data.setDataLong(1, remoteData.getDataLongs(1));
        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.addDataIntegers(data.getDataInteger(1));
        builder.addDataStrings(data.getDataString(1));
        builder.addDataLongs(data.getDataLong(0));
        builder.addDataLongs(data.getDataLong(1));
        return builder.build();
P
pengys5 已提交
68 69 70 71 72
    }

    public static class ServiceEntry implements Transform<ServiceEntry> {
        private String id;
        private int applicationId;
73 74
        private int entryServiceId;
        private String entryServiceName;
75 76
        private long registerTime;
        private long newestTime;
P
pengys5 已提交
77

78
        public ServiceEntry(String id, int applicationId, int entryServiceId, String entryServiceName,
79 80
            long registerTime,
            long newestTime) {
P
pengys5 已提交
81 82
            this.id = id;
            this.applicationId = applicationId;
83 84
            this.entryServiceId = entryServiceId;
            this.entryServiceName = entryServiceName;
85 86
            this.registerTime = registerTime;
            this.newestTime = newestTime;
P
pengys5 已提交
87 88 89 90 91 92 93 94 95 96
        }

        public ServiceEntry() {
        }

        @Override public Data toData() {
            ServiceEntryDataDefine define = new ServiceEntryDataDefine();
            Data data = define.build(id);
            data.setDataString(0, this.id);
            data.setDataInteger(0, this.applicationId);
97 98
            data.setDataInteger(1, this.entryServiceId);
            data.setDataString(1, this.entryServiceName);
99 100
            data.setDataLong(0, this.registerTime);
            data.setDataLong(1, this.newestTime);
P
pengys5 已提交
101 102 103 104 105 106
            return data;
        }

        @Override public ServiceEntry toSelf(Data data) {
            this.id = data.getDataString(0);
            this.applicationId = data.getDataInteger(0);
107 108
            this.entryServiceId = data.getDataInteger(1);
            this.entryServiceName = data.getDataString(1);
109 110
            this.registerTime = data.getDataLong(0);
            this.newestTime = data.getDataLong(1);
P
pengys5 已提交
111 112 113 114 115 116 117
            return this;
        }

        public String getId() {
            return id;
        }

118 119 120 121 122 123
        public void setId(String id) {
            this.id = id;
        }

        public int getEntryServiceId() {
            return entryServiceId;
P
pengys5 已提交
124 125
        }

126 127
        public void setEntryServiceId(int entryServiceId) {
            this.entryServiceId = entryServiceId;
P
pengys5 已提交
128 129
        }

130 131 132 133 134 135
        public String getEntryServiceName() {
            return entryServiceName;
        }

        public void setEntryServiceName(String entryServiceName) {
            this.entryServiceName = entryServiceName;
P
pengys5 已提交
136 137 138 139 140 141 142 143 144
        }

        public int getApplicationId() {
            return applicationId;
        }

        public void setApplicationId(int applicationId) {
            this.applicationId = applicationId;
        }
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

        public long getRegisterTime() {
            return registerTime;
        }

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

        public long getNewestTime() {
            return newestTime;
        }

        public void setNewestTime(long newestTime) {
            this.newestTime = newestTime;
        }
P
pengys5 已提交
161 162
    }
}