AnalysisRegisterModuleProvider.java 4.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 *
 */

19
package org.apache.skywalking.apm.collector.analysis.register.provider;
20

21
import org.apache.skywalking.apm.collector.analysis.register.define.AnalysisRegisterModule;
22 23 24
import org.apache.skywalking.apm.collector.analysis.register.define.service.*;
import org.apache.skywalking.apm.collector.analysis.register.provider.register.*;
import org.apache.skywalking.apm.collector.analysis.register.provider.service.*;
P
peng-yongsheng 已提交
25 26 27
import org.apache.skywalking.apm.collector.analysis.worker.model.base.WorkerCreateListener;
import org.apache.skywalking.apm.collector.analysis.worker.timer.PersistenceTimer;
import org.apache.skywalking.apm.collector.cache.CacheModule;
28
import org.apache.skywalking.apm.collector.core.module.*;
P
peng-yongsheng 已提交
29
import org.apache.skywalking.apm.collector.remote.RemoteModule;
30
import org.apache.skywalking.apm.collector.remote.service.RemoteDataRegisterService;
P
peng-yongsheng 已提交
31
import org.apache.skywalking.apm.collector.storage.StorageModule;
32
import org.apache.skywalking.apm.collector.storage.table.register.*;
33 34 35 36

/**
 * @author peng-yongsheng
 */
37
public class AnalysisRegisterModuleProvider extends ModuleProvider {
38 39

    public static final String NAME = "default";
40 41 42 43 44 45
    private final AnalysisRegisterModuleConfig config;

    public AnalysisRegisterModuleProvider() {
        super();
        this.config = new AnalysisRegisterModuleConfig();
    }
46 47 48 49 50

    @Override public String name() {
        return NAME;
    }

51
    @Override public Class<? extends ModuleDefine> module() {
52
        return AnalysisRegisterModule.class;
53 54
    }

55 56 57 58 59
    @Override public ModuleConfig createConfigBeanIfAbsent() {
        return config;
    }

    @Override public void prepare() throws ServiceNotProvidedException {
60 61 62
        this.registerServiceImplementation(IApplicationIDService.class, new ApplicationIDService(getManager()));
        this.registerServiceImplementation(IInstanceIDService.class, new InstanceIDService(getManager()));
        this.registerServiceImplementation(IServiceNameService.class, new ServiceNameService(getManager()));
63
        this.registerServiceImplementation(INetworkAddressIDService.class, new NetworkAddressIDService(getManager()));
64 65
    }

66
    @Override public void start() {
P
peng-yongsheng 已提交
67
        WorkerCreateListener workerCreateListener = new WorkerCreateListener();
68

P
peng-yongsheng 已提交
69
        graphCreate(workerCreateListener);
70

71 72
        registerRemoteData();

彭勇升 pengys 已提交
73
        PersistenceTimer.INSTANCE.start(getManager(), workerCreateListener.getPersistenceWorkers());
74 75
    }

76
    @Override public void notifyAfterCompleted() {
77 78 79
    }

    @Override public String[] requiredModules() {
P
peng-yongsheng 已提交
80 81 82 83
        return new String[] {StorageModule.NAME, RemoteModule.NAME, CacheModule.NAME};
    }

    private void graphCreate(WorkerCreateListener workerCreateListener) {
84 85 86 87
        new ApplicationRegisterGraph(getManager(), workerCreateListener).create();
        new InstanceRegisterGraph(getManager(), workerCreateListener).create();
        new ServiceNameRegisterGraph(getManager(), workerCreateListener).create();
        new NetworkAddressRegisterGraph(getManager(), workerCreateListener).create();
88
    }
89 90 91 92 93 94 95 96

    private void registerRemoteData() {
        RemoteDataRegisterService remoteDataRegisterService = getManager().find(RemoteModule.NAME).getService(RemoteDataRegisterService.class);
        remoteDataRegisterService.register(Application.class, new Application.InstanceCreator());
        remoteDataRegisterService.register(Instance.class, new Instance.InstanceCreator());
        remoteDataRegisterService.register(NetworkAddress.class, new NetworkAddress.InstanceCreator());
        remoteDataRegisterService.register(ServiceName.class, new ServiceName.InstanceCreator());
    }
97
}