Example #1
0
 def __init__(self, address, connection_closed_callback, message_callback):
     self._address = (address.host, address.port)
     self.id = self.counter.get_and_increment()
     self.logger = logging.getLogger("Connection[%s](%s:%d)" % (self.id, address.host, address.port))
     self._connection_closed_callback = connection_closed_callback
     self._builder = ClientMessageBuilder(message_callback)
     self._read_buffer = ""
     self.last_read = 0
Example #2
0
 def __init__(self, address, connection_closed_callback, message_callback):
     self._address = (address.host, address.port)
     self.id = self.counter.get_and_increment()
     self.logger = logging.getLogger("Connection[%s](%s:%d)" % (self.id, address.host, address.port))
     self._connection_closed_callback = connection_closed_callback
     self._builder = ClientMessageBuilder(message_callback)
     self._read_buffer = bytearray()
     self.last_read_in_seconds = 0
     self.last_write_in_seconds = 0
     self.start_time_in_seconds = 0
     self.server_version_str = ""
     self.server_version = 0
Example #3
0
class Connection(object):
    _closed = False
    endpoint = None
    heartbeating = True
    is_owner = False
    counter = AtomicInteger()

    def __init__(self, address, connection_closed_callback, message_callback):
        self._address = (address.host, address.port)
        self.id = self.counter.get_and_increment()
        self.logger = logging.getLogger("Connection[%s](%s:%d)" %
                                        (self.id, address.host, address.port))
        self._connection_closed_callback = connection_closed_callback
        self._builder = ClientMessageBuilder(message_callback)
        self._read_buffer = ""
        self.last_read = 0

    def live(self):
        return not self._closed

    def send_message(self, message):
        if not self.live():
            raise IOError("Connection is not live.")

        message.add_flag(BEGIN_END_FLAG)
        self.write(message.buffer)

    def receive_message(self):
        self.last_read = time.time()
        # split frames
        while len(self._read_buffer) >= INT_SIZE_IN_BYTES:
            frame_length = struct.unpack_from(FMT_LE_INT, self._read_buffer,
                                              0)[0]
            if frame_length > len(self._read_buffer):
                return
            message = ClientMessage(buffer(self._read_buffer, 0, frame_length))
            self._read_buffer = self._read_buffer[frame_length:]
            self._builder.on_message(message)

    def write(self, data):
        # must be implemented by subclass
        raise NotImplementedError

    def close(self, cause):
        raise NotImplementedError

    def __repr__(self):
        return "Connection(address=%s, id=%s)" % (self._address, self.id)
class Connection(object):
    _closed = False
    endpoint = None
    heartbeating = True
    is_owner = False
    counter = AtomicInteger()

    def __init__(self, address, connection_closed_callback, message_callback):
        self._address = (address.host, address.port)
        self.id = self.counter.get_and_increment()
        self.logger = logging.getLogger("Connection[%s](%s:%d)" % (self.id, address.host, address.port))
        self._connection_closed_callback = connection_closed_callback
        self._builder = ClientMessageBuilder(message_callback)
        self._read_buffer = ""
        self.last_read = 0

    def live(self):
        return not self._closed

    def send_message(self, message):
        if not self.live():
            raise IOError("Connection is not live.")

        message.add_flag(BEGIN_END_FLAG)
        self.write(message.buffer)

    def receive_message(self):
        self.last_read = time.time()
        # split frames
        while len(self._read_buffer) >= INT_SIZE_IN_BYTES:
            frame_length = struct.unpack_from(FMT_LE_INT, self._read_buffer, 0)[0]
            if frame_length > len(self._read_buffer):
                return
            message = ClientMessage(buffer(self._read_buffer, 0, frame_length))
            self._read_buffer = self._read_buffer[frame_length:]
            self._builder.on_message(message)

    def write(self, data):
        # must be implemented by subclass
        raise NotImplementedError

    def close(self, cause):
        raise NotImplementedError

    def __repr__(self):
        return "Connection(address=%s, id=%s)" % (self._address, self.id)
Example #5
0
    def __init__(self, connection_manager, connection_id, message_callback):
        self.remote_address = None
        self.remote_uuid = None
        self.connected_address = None
        self.local_address = None
        self.last_read_time = 0
        self.last_write_time = 0
        self.start_time = 0
        self.server_version = UNKNOWN_VERSION
        self.live = True
        self.close_reason = None

        self._connection_manager = connection_manager
        self._id = connection_id
        self._builder = ClientMessageBuilder(message_callback)
        self._reader = _Reader(self._builder)
Example #6
0
    def __init__(self,
                 connection_manager,
                 connection_id,
                 message_callback,
                 logger_extras=None):
        self.remote_address = None
        self.remote_uuid = None
        self.connected_address = None
        self.local_address = None
        self.last_read_time = 0
        self.last_write_time = 0
        self.start_time = 0
        self.server_version = UNKNOWN_VERSION
        self.live = True
        self.close_cause = None
        self.logger = logging.getLogger("HazelcastClient.Connection[%s]" %
                                        connection_id)

        self._connection_manager = connection_manager
        self._logger_extras = logger_extras
        self._id = connection_id
        self._builder = ClientMessageBuilder(message_callback)
        self._reader = _Reader(self._builder)
class Connection(object):
    """
    Connection object which stores connection related information and operations.
    """
    _closed = False
    endpoint = None
    heartbeating = True
    is_owner = False
    counter = AtomicInteger()

    def __init__(self,
                 address,
                 connection_closed_callback,
                 message_callback,
                 logger_extras=None):
        self._address = (address.host, address.port)
        self._logger_extras = logger_extras
        self.id = self.counter.get_and_increment()
        self.logger = logging.getLogger(
            "HazelcastClient.Connection[%s](%s:%d)" %
            (self.id, address.host, address.port))
        self._connection_closed_callback = connection_closed_callback
        self._builder = ClientMessageBuilder(message_callback)
        self._read_buffer = bytearray()
        self.last_read_in_seconds = 0
        self.last_write_in_seconds = 0
        self.start_time_in_seconds = 0
        self.server_version_str = ""
        self.server_version = 0

    def live(self):
        """
        Determines whether this connection is live or not.

        :return: (bool), ``true`` if the connection is live, ``false`` otherwise.
        """
        return not self._closed

    def send_message(self, message):
        """
        Sends a message to this connection.

        :param message: (Message), message to be sent to this connection.
        """
        if not self.live():
            raise IOError("Connection is not live.")

        message.add_flag(BEGIN_END_FLAG)
        self.write(message.buffer)

    def receive_message(self):
        """
        Receives a message from this connection.
        """
        # split frames
        while len(self._read_buffer) >= INT_SIZE_IN_BYTES:
            frame_length = struct.unpack_from(FMT_LE_INT, self._read_buffer,
                                              0)[0]
            if frame_length > len(self._read_buffer):
                return
            message = ClientMessage(
                memoryview(self._read_buffer)[:frame_length])
            self._read_buffer = self._read_buffer[frame_length:]
            self._builder.on_message(message)

    def write(self, data):
        """
        Writes data to this connection when sending messages.

        :param data: (Data), data to be written to connection.
        """
        # must be implemented by subclass
        raise NotImplementedError

    def close(self, cause):
        """
        Closes the connection.

        :param cause: (Exception), the cause of closing the connection.
        """
        raise NotImplementedError

    def __repr__(self):
        return "Connection(address=%s, id=%s)" % (self._address, self.id)

    def __hash__(self):
        return self.id