def encode_request(name):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.update_frame_length()
    return client_message
Пример #2
0
 def handle_read(self):
     self.input_buffer += self.recv(BUFFER_SIZE)
     self.logger.debug("Read %d bytes", len(self.input_buffer))
     # split frames
     while len(self.input_buffer) > 0:
         self.logger.debug("Reading the message")
         complete = self.read_from()
         if not complete:
             self.logger.debug("message is not complete")
             break
         self._message_handler(self.message)
         self.message = ClientMessage(buff="")
Пример #3
0
 def __init__(self, address, message_handler):
     asyncore.dispatcher.__init__(self)
     self._address = (address.host, address.port)
     self.logger = logging.getLogger("Connection{%s:%d}" % self._address)
     self._message_handler = message_handler
     self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
     self.endpoint = None
     self.connect(self._address)
     self._write_queue = Queue()
     self._write_queue.put("CB2")
     self.input_buffer = ""
     self.message = ClientMessage(buff="")
def encode_request(name, values):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, values))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(len(values))
    for values_item in values:
        client_message.append_data(values_item)
    client_message.update_frame_length()
    return client_message
def encode_request(name, uuid, callable, address):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, uuid, callable, address))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_str(uuid)
    client_message.append_data(callable)
    AddressCodec.encode(client_message, address)
    client_message.update_frame_length()
    return client_message
RESPONSE_TYPE = 106
RETRYABLE = True


def calculate_size(name, from, to):
    """ Calculates the request payload size"""
    data_size = 0
    data_size += calculate_size_str(name)
    data_size += INT_SIZE_IN_BYTES
    data_size += INT_SIZE_IN_BYTES
    return data_size


def encode_request(name, from, to):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, from, to))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(from)
    client_message.append_int(to)
    client_message.update_frame_length()
    return client_message


def decode_response(client_message):
    """ Decode response from client message"""
    parameters = dict(response=None)
    response_size = client_message.read_int()
    response = []
    for response_index in xrange(0, response_size):
def encode_request(uuid, partition_id, interrupt):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(uuid, partition_id, interrupt))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(uuid)
    client_message.append_int(partition_id)
    client_message.append_bool(interrupt)
    client_message.update_frame_length()
    return client_message
Пример #8
0
def encode_request(transaction_id, thread_id):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(transaction_id, thread_id))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(transaction_id)
    client_message.append_long(thread_id)
    client_message.update_frame_length()
    return client_message
Пример #9
0
def encode_request(username, password, uuid, owner_uuid, is_owner_connection, client_type, serialization_version):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(username, password, uuid, owner_uuid, is_owner_connection, client_type, serialization_version))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(username)
    client_message.append_str(password)
    client_message.append_bool(uuid is None)
    if uuid is not None:
        client_message.append_str(uuid)
    client_message.append_bool(owner_uuid is None)
    if owner_uuid is not None:
        client_message.append_str(owner_uuid)
    client_message.append_bool(is_owner_connection)
    client_message.append_str(client_type)
    client_message.append_byte(serialization_version)
    client_message.update_frame_length()
    return client_message
def encode_request(transaction_id, thread_id):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(transaction_id, thread_id))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(transaction_id)
    client_message.append_long(thread_id)
    client_message.update_frame_length()
    return client_message
def encode_request(name, entries):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, entries))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(len(entries))
    for key, value in entries.iteritems():
        client_message.append_data(key)
        client_message.append_data(val)
    client_message.update_frame_length()
    return client_message
def encode_request(name, entries):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, entries))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(len(entries))
    for key, value in six.iteritems(entries):
        client_message.append_data(key)
        client_message.append_data(value)
    client_message.update_frame_length()
    return client_message
def encode_request(name, replica_timestamps, target_replica):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, replica_timestamps, target_replica))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(len(replica_timestamps))
    for replica_timestamps_item in replica_timestamps:
        key = replica_timestamps_item[0]
        val = replica_timestamps_item[1]
        client_message.append_str(key)
        client_message.append_long(val)

    AddressCodec.encode(client_message, target_replica)
    client_message.update_frame_length()
    return client_message
Пример #14
0
def encode_request(name, new_value):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, new_value))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_bool(new_value is None)
    if new_value is not None:
        client_message.append_data(new_value)
    client_message.update_frame_length()
    return client_message
Пример #15
0
def encode_request(name, key, local_only):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, key, local_only))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_data(key)
    client_message.append_bool(local_only)
    client_message.update_frame_length()
    return client_message
Пример #16
0
def encode_request(name, key, value, thread_id, ttl):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, key, value, thread_id, ttl))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_data(key)
    client_message.append_data(value)
    client_message.append_long(thread_id)
    client_message.append_long(ttl)
    client_message.update_frame_length()
    return client_message
Пример #17
0
def encode_request(name, txn_id, thread_id, predicate):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, txn_id, thread_id, predicate))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_str(txn_id)
    client_message.append_long(thread_id)
    client_message.append_data(predicate)
    client_message.update_frame_length()
    return client_message
Пример #18
0
def encode_request(name, attribute, ordered):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, attribute, ordered))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_str(attribute)
    client_message.append_bool(ordered)
    client_message.update_frame_length()
    return client_message
def encode_request(name, include_value, listener_flags, local_only):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, include_value, listener_flags, local_only))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_bool(include_value)
    client_message.append_int(listener_flags)
    client_message.append_bool(local_only)
    client_message.update_frame_length()
    return client_message
Пример #20
0
class Connection(asyncore.dispatcher):
    def __init__(self, address, message_handler):
        asyncore.dispatcher.__init__(self)
        self._address = (address.host, address.port)
        self.logger = logging.getLogger("Connection{%s:%d}" % self._address)
        self._message_handler = message_handler
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.endpoint = None
        self.connect(self._address)
        self._write_queue = Queue()
        self._write_queue.put("CB2")
        self.input_buffer = ""
        self.message = ClientMessage(buff="")

    def handle_connect(self):
        self.logger.debug("Connected to %s", self._address)

    def handle_read(self):
        self.input_buffer += self.recv(BUFFER_SIZE)
        self.logger.debug("Read %d bytes", len(self.input_buffer))
        # split frames
        while len(self.input_buffer) > 0:
            self.logger.debug("Reading the message")
            complete = self.read_from()
            if not complete:
                self.logger.debug("message is not complete")
                break
            self._message_handler(self.message)
            self.message = ClientMessage(buff="")

    def read_from(self):
        if len(self.input_buffer) < INT_SIZE_IN_BYTES:
            self.logger.debug("Frame size couldn't be read")
            return False
        self.message.buffer += self.input_buffer[0:INT_SIZE_IN_BYTES]
        self.input_buffer = self.input_buffer[INT_SIZE_IN_BYTES:]
        while len(self.input_buffer) > 0 and not self.message_complete():
            to_read = self.message.get_frame_length() - len(self.message.buffer)
            self.logger.debug("Data to be read %s ,  buffer size : %s ", to_read, len(self.input_buffer))
            if to_read > len(self.input_buffer):
                self.message.buffer += self.input_buffer
                self.input_buffer = ""
                return False
            else:
                self.message.buffer += self.input_buffer[:to_read]
                self.input_buffer = self.input_buffer[to_read:]
                return True

    def message_complete(self):
        return len(self.message.buffer) == self.message.get_frame_length()

    def handle_write(self):
        self._initiate_send()

    def handle_close(self):
        self.logger.debug("handle_close")
        self.close()

    def writable(self):
        return not self._write_queue.empty()

    def _initiate_send(self):
        try:
            item = self._write_queue.get_nowait()
        except Empty:
            return
        sent = self.send(item)
        self.logger.debug("Written " + str(sent) + " bytes")
        # TODO: check if everything was sent

    def send_message(self, message):
        message.add_flag(BEGIN_END_FLAG)
        self._write_queue.put(message.buffer)
        self._initiate_send()
def encode_request(name, service_name, target):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, service_name, target))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_str(service_name)
    AddressCodec.encode(client_message, target)
    client_message.update_frame_length()
    return client_message
Пример #22
0
def encode_request(name, value_list):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, value_list))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(len(value_list))
    for value_list_item in value_list:
        client_message.append_data(value_list_item)
    client_message.update_frame_length()
    return client_message
Пример #23
0
def encode_request(name, start_sequence, min_count, max_count, filter):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, start_sequence, min_count, max_count, filter))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_long(start_sequence)
    client_message.append_int(min_count)
    client_message.append_int(max_count)
    client_message.append_bool(filter is None)
    if filter is not None:
        client_message.append_data(filter)
    client_message.update_frame_length()
    return client_message
def encode_request(name, expected, updated):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, expected, updated))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_bool(expected is None)
    if expected is not None:
        client_message.append_data(expected)
    client_message.append_bool(updated is None)
    if updated is not None:
        client_message.append_data(updated)
    client_message.update_frame_length()
    return client_message
Пример #25
0
def encode_request(name, key, thread_id, lease, timeout):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, key, thread_id, lease, timeout))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_data(key)
    client_message.append_long(thread_id)
    client_message.append_long(lease)
    client_message.append_long(timeout)
    client_message.update_frame_length()
    return client_message
def encode_request(credentials, uuid, owner_uuid, is_owner_connection, client_type, serialization_version):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(
            credentials, uuid, owner_uuid, is_owner_connection, client_type, serialization_version
        )
    )
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_data(credentials)
    client_message.append_bool(uuid is None)
    if uuid is not None:
        client_message.append_str(uuid)
    client_message.append_bool(owner_uuid is None)
    if owner_uuid is not None:
        client_message.append_str(owner_uuid)
    client_message.append_bool(is_owner_connection)
    client_message.append_str(client_type)
    client_message.append_byte(serialization_version)
    client_message.update_frame_length()
    return client_message
Пример #27
0
def encode_request(name, include_value, listener_flags, local_only):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, include_value, listener_flags, local_only))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_bool(include_value)
    client_message.append_int(listener_flags)
    client_message.append_bool(local_only)
    client_message.update_frame_length()
    return client_message
def encode_request(name, txn_id, thread_id, item, timeout):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, txn_id, thread_id, item, timeout))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_str(txn_id)
    client_message.append_long(thread_id)
    client_message.append_data(item)
    client_message.append_long(timeout)
    client_message.update_frame_length()
    return client_message
Пример #29
0
def encode_request(name, service_name):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, service_name))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_str(service_name)
    client_message.update_frame_length()
    return client_message
def encode_request(map_name, cache_name, predicate, batch_size, buffer_size, delay_seconds, populate, coalesce):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(map_name, cache_name, predicate, batch_size, buffer_size, delay_seconds, populate, coalesce))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(map_name)
    client_message.append_str(cache_name)
    client_message.append_data(predicate)
    client_message.append_int(batch_size)
    client_message.append_int(buffer_size)
    client_message.append_long(delay_seconds)
    client_message.append_bool(populate)
    client_message.append_bool(coalesce)
    client_message.update_frame_length()
    return client_message
Пример #31
0
def encode_request(name, overflow_policy, value):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, overflow_policy, value))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(overflow_policy)
    client_message.append_data(value)
    client_message.update_frame_length()
    return client_message
def encode_request(name, job_id, predicate, mapper, combiner_factory, reducer_factory, key_value_source, chunk_size, keys, topology_changed_strategy):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, job_id, predicate, mapper, combiner_factory, reducer_factory, key_value_source, chunk_size, keys, topology_changed_strategy))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_str(job_id)
    client_message.append_bool(predicate is None)
    if predicate is not None:
        client_message.append_data(predicate)
    client_message.append_data(mapper)
    client_message.append_bool(combiner_factory is None)
    if combiner_factory is not None:
        client_message.append_data(combiner_factory)
    client_message.append_bool(reducer_factory is None)
    if reducer_factory is not None:
        client_message.append_data(reducer_factory)
    client_message.append_data(key_value_source)
    client_message.append_int(chunk_size)
    client_message.append_bool(keys is None)
    if keys is not None:
        client_message.append_int(len(keys))
        for keys_item in keys:
            client_message.append_data(keys_item)
    client_message.append_bool(topology_changed_strategy is None)
    if topology_changed_strategy is not None:
        client_message.append_str(topology_changed_strategy)
    client_message.update_frame_length()
    return client_message
Пример #33
0
def encode_request(uuid, partition_id, interrupt):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(uuid, partition_id, interrupt))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(uuid)
    client_message.append_int(partition_id)
    client_message.append_bool(interrupt)
    client_message.update_frame_length()
    return client_message
Пример #34
0
def encode_request(name, keys, replace_existing_values):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, keys, replace_existing_values))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_int(len(keys))
    for keys_item in keys:
        client_message.append_data(keys_item)
    client_message.append_bool(replace_existing_values)
    client_message.update_frame_length()
    return client_message
def encode_request(name, start_sequence, min_count, max_count, filter):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, start_sequence, min_count, max_count, filter))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_long(start_sequence)
    client_message.append_int(min_count)
    client_message.append_int(max_count)
    client_message.append_bool(filter is None)
    if filter is not None:
        client_message.append_data(filter)
    client_message.update_frame_length()
    return client_message
def encode_request(name, key, predicate, local_only):
    """ Encode request into client_message"""
    client_message = ClientMessage(payload_size=calculate_size(name, key, predicate, local_only))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_data(key)
    client_message.append_data(predicate)
    client_message.append_bool(local_only)
    client_message.update_frame_length()
    return client_message
def encode_request(name, uuid, callable, partition_id):
    """ Encode request into client_message"""
    client_message = ClientMessage(
        payload_size=calculate_size(name, uuid, callable, partition_id))
    client_message.set_message_type(REQUEST_TYPE)
    client_message.set_retryable(RETRYABLE)
    client_message.append_str(name)
    client_message.append_str(uuid)
    client_message.append_data(callable)
    client_message.append_int(partition_id)
    client_message.update_frame_length()
    return client_message