Merge "Change PTL informatin in INFO"
[bottlenecks.git] / utils / dispatcher / base.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 # liangqi1@huawei.com matthew.lijun@huawei.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import abc
11 import six
12
13 import utils.dispatcher.func as func
14
15
16 @six.add_metaclass(abc.ABCMeta)
17 class Base(object):
18
19     def __init__(self, conf):
20         self.conf = conf
21
22     @staticmethod
23     def get_cls(dispatcher_type):
24         '''Return class of specified type.'''
25         for dispatcher in func.itersubclasses(Base):
26             if dispatcher_type == dispatcher.__dispatcher_type__:
27                 return dispatcher
28         raise RuntimeError("No such dispatcher_type %s" % dispatcher_type)
29
30     @staticmethod
31     def get(config):
32         """Returns instance of a dispatcher for dispatcher type.
33         """
34         return Base.get_cls(config["type"])(config)
35
36     @abc.abstractmethod
37     def record_result_data(self, data):
38         """Recording result data interface."""
39
40     @abc.abstractmethod
41     def flush_result_data(self):
42         """Flush result data into permanent storage media interface."""