AbstractWorker.java 2.3 KB
Newer Older
P
peng-yongsheng 已提交
1
/*
wu-sheng's avatar
wu-sheng 已提交
2 3 4 5 6 7
 * 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
P
peng-yongsheng 已提交
8 9 10 11 12 13 14 15 16 17 18
 *
 *     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.worker.model.base;
P
peng-yongsheng 已提交
20

P
peng-yongsheng 已提交
21
import org.apache.skywalking.apm.collector.core.data.EndOfBatchQueueMessage;
22 23 24
import org.apache.skywalking.apm.collector.core.graph.Next;
import org.apache.skywalking.apm.collector.core.graph.NodeProcessor;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
P
peng-yongsheng 已提交
25 26 27 28 29 30
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author peng-yongsheng
 */
P
peng-yongsheng 已提交
31
public abstract class AbstractWorker<INPUT extends EndOfBatchQueueMessage, OUTPUT extends EndOfBatchQueueMessage> implements NodeProcessor<INPUT, OUTPUT> {
P
peng-yongsheng 已提交
32 33 34

    private final Logger logger = LoggerFactory.getLogger(AbstractWorker.class);

P
peng-yongsheng 已提交
35
    private final ModuleManager moduleManager;
36

P
peng-yongsheng 已提交
37 38
    public AbstractWorker(ModuleManager moduleManager) {
        this.moduleManager = moduleManager;
39 40
    }

P
peng-yongsheng 已提交
41 42
    public final ModuleManager getModuleManager() {
        return moduleManager;
43 44
    }

45 46
    private Next<OUTPUT> next;

P
peng-yongsheng 已提交
47 48 49 50 51 52
    /**
     * The data process logic in this method.
     *
     * @param message Cast the message object to a expect subclass.
     * @throws WorkerException Don't handle the exception, throw it.
     */
53
    protected abstract void onWork(INPUT message) throws WorkerException;
P
peng-yongsheng 已提交
54

wu-sheng's avatar
wu-sheng 已提交
55
    @Override public final void process(INPUT input, Next<OUTPUT> next) {
56
        this.next = next;
P
peng-yongsheng 已提交
57
        try {
wu-sheng's avatar
wu-sheng 已提交
58
            onWork(input);
P
peng-yongsheng 已提交
59 60 61
        } catch (WorkerException e) {
            logger.error(e.getMessage(), e);
        }
P
peng-yongsheng 已提交
62
    }
63 64 65 66

    protected final void onNext(OUTPUT message) {
        next.execute(message);
    }
P
peng-yongsheng 已提交
67
}