# Path: pypipeline/core/Source.py
# class Source:
#     def __init__(self, plumber, params):
#         self.plumber = plumber
#         self.chain = None
#         self.params = params
# 
#     def start(self):
#         raise NotImplementedError("Sources should implement their start method")
# 
#     def stop(self):
#         raise NotImplementedError("Sources should implement their stop method")
# 
# Path: pypipeline/core/Exchange.py
# class Exchange:
#     def __init__(self):
#         self.id = uuid.uuid4()
#         self.in_msg = None
#         self.out_msg = None
#         self.properties = {}
# 
#     def __str__(self):
#         return "Id: " + str(self.id) + "\nProperties: " + str(self.properties) + "\nIn Msg:\n" + str(self.in_msg) + "\nOut Msg:\n" + str(self.out_msg)
# 
# Path: pypipeline/core/Message.py
# class Message:
#     def __init__(self):
#         self.headers = {}
#         self.body = None
# 
#     def __str__(self):
#         return "\tHeaders: " + str(self.headers) + "\n\tBody: " + str(self.body)


from pypipeline.core.Source import Source
from pypipeline.core.Exchange import Exchange
from pypipeline.core.Message import Message
import threading
import time


class Timer(Source):
    def __init__(self, plumber, params):
        super().__init__(plumber, params)
        self.period = float(params["period"])
        self.thread = None

    def start(self):
        self.thread = TimerThread(self, self.plumber)
        self.thread.start()

    def stop(self):
        self.thread.stop()


class TimerThread(threading.Thread):
    def __init__(self, source, plumber):
        super().__init__()
        self.stopped = False
        self.source = source
        self.period = source.period

# Path: pypipeline/core/Source.py
# class Source:
#     def __init__(self, plumber, params):
#         self.plumber = plumber
#         self.chain = None
#         self.params = params
# 
#     def start(self):
#         raise NotImplementedError("Sources should implement their start method")
# 
#     def stop(self):
#         raise NotImplementedError("Sources should implement their stop method")
# 
# Path: pypipeline/core/Exchange.py
# class Exchange:
#     def __init__(self):
#         self.id = uuid.uuid4()
#         self.in_msg = None
#         self.out_msg = None
#         self.properties = {}
# 
#     def __str__(self):
#         return "Id: " + str(self.id) + "\nProperties: " + str(self.properties) + "\nIn Msg:\n" + str(self.in_msg) + "\nOut Msg:\n" + str(self.out_msg)
# 
# Path: pypipeline/core/Message.py
# class Message:
#     def __init__(self):
#         self.headers = {}
#         self.body = None
# 
#     def __str__(self):
#         return "\tHeaders: " + str(self.headers) + "\n\tBody: " + str(self.body)


# Path: pypipeline/components/source/Timer.py
from pypipeline.core.Source import Source
from pypipeline.core.Exchange import Exchange
from pypipeline.core.Message import Message
import threading
import time



class Timer(Source):
    def __init__(self, plumber, params):
        super().__init__(plumber, params)
        self.period = float(params["period"])
        self.thread = None

    def start(self):
        self.thread = TimerThread(self, self.plumber)
        self.thread.start()

    def stop(self):
        self.thread.stop()


class TimerThread(threading.Thread):
    def __init__(self, source, plumber):
        super().__init__()
        self.stopped = False
        self.source = source
        self.period = source.period

        self.plumber = plumber