import zmq

from abc import ABCMeta, abstractmethod

from ._WorkerThread import WorkerThread


class PullWorkerThread(WorkerThread):
    __meta__ = ABCMeta

    def __init__(self, context, worker_address, idle_timeout):
        super(PullWorkerThread, self).__init__(context, worker_address, idle_timeout)

    def create_socket(self, address):
        pull_socket = self.context.socket(zmq.PULL)
        pull_socket.connect(self.worker_address)
        return pull_socket

    @abstractmethod
    def do_work(self, data):
        raise NotImplementedError()

    @abstractmethod
    def dispose(self):
        raise NotImplementedError()

    def get_logger_name(self):
        return "ZeroMqThreadPool.PullWorkerThread"
