完整部署快照
This commit is contained in:
20
ixformer_sdk/core/dispatcher.py
Normal file
20
ixformer_sdk/core/dispatcher.py
Normal file
@@ -0,0 +1,20 @@
|
||||
class Dispatcher(object):
|
||||
"""
|
||||
create object by dispatcher to reuse object.
|
||||
"""
|
||||
|
||||
_dispatcher = dict()
|
||||
|
||||
@classmethod
|
||||
def dispatcher(cls, *args, **kwargs):
|
||||
key = cls.dispatcher_key(*args, **kwargs)
|
||||
obj = cls._dispatcher.get(key, None)
|
||||
if obj is None:
|
||||
obj = cls(*args, **kwargs)
|
||||
cls._dispatcher[key] = obj
|
||||
|
||||
return obj
|
||||
|
||||
@classmethod
|
||||
def dispatcher_key(cls, *args, **kwargs):
|
||||
raise NotImplementedError()
|
||||
Reference in New Issue
Block a user