Example #1
0
from hazelcast.exception import HazelcastSerializationError
from hazelcast.util import enum
from hazelcast import six

FieldType = enum(
        PORTABLE=0,
        BYTE=1,
        BOOLEAN=2,
        CHAR=3,
        SHORT=4,
        INT=5,
        LONG=6,
        FLOAT=7,
        DOUBLE=8,
        UTF=9,
        PORTABLE_ARRAY=10,
        BYTE_ARRAY=11,
        BOOLEAN_ARRAY=12,
        CHAR_ARRAY=13,
        SHORT_ARRAY=14,
        INT_ARRAY=15,
        LONG_ARRAY=16,
        FLOAT_ARRAY=17,
        DOUBLE_ARRAY=18,
        UTF_ARRAY=19
)


class FieldDefinition(object):
    def __init__(self, index, field_name, field_type, version, factory_id=0, class_id=0):
        self.index = index
from hazelcast.exception import HazelcastSerializationError
from hazelcast.util import enum

FieldType = enum(
        PORTABLE=0,
        BYTE=1,
        BOOLEAN=2,
        CHAR=3,
        SHORT=4,
        INT=5,
        LONG=6,
        FLOAT=7,
        DOUBLE=8,
        UTF=9,
        PORTABLE_ARRAY=10,
        BYTE_ARRAY=11,
        BOOLEAN_ARRAY=12,
        CHAR_ARRAY=13,
        SHORT_ARRAY=14,
        INT_ARRAY=15,
        LONG_ARRAY=16,
        FLOAT_ARRAY=17,
        DOUBLE_ARRAY=18,
        UTF_ARRAY=19
)


class FieldDefinition(object):
    def __init__(self, index, field_name, field_type, factory_id=0, class_id=0):
        self.index = index
        self.field_name = field_name
        self.transaction = transaction
        self._invocation_service = context.invocation_service
        serialization_service = context.serialization_service
        self._to_object = serialization_service.to_object
        self._to_data = serialization_service.to_data

    def _invoke(self, request, response_handler=_no_op_response_handler):
        invocation = Invocation(request, connection=self.transaction.connection, response_handler=response_handler)
        self._invocation_service.invoke(invocation)
        return invocation.future

    def __repr__(self):
        return '%s(name="%s")' % (type(self).__name__, self.name)


ItemEventType = enum(added=1, removed=2)
EntryEventType = enum(added=1, removed=2, updated=4, evicted=8, expired=16, evict_all=32, clear_all=64, merged=128,
                      invalidation=256, loaded=512)


class ItemEvent(object):
    """
    Map Item event.
    """
    def __init__(self, name, item_data, event_type, member, to_object):
        self.name = name
        self._item_data = item_data
        self.event_type = event_type
        self.member = member
        self._to_object = to_object
Default password of connected Hazelcast cluster
"""

PROPERTY_HEARTBEAT_INTERVAL = "hazelcast.client.heartbeat.interval"
"""
Configuration property for heartbeat interval in milliseconds. Client will send heartbeat to server by this value of interval
unless other requests send to server
"""

PROPERTY_HEARTBEAT_TIMEOUT = "hazelcast.client.heartbeat.timeout"
"""
Configuration property for heartbeat timeout in milliseconds. If client cannot see any activity on a connection for this timeout
value it will shutdown the connection
"""

INTEGER_TYPE = enum(VAR=0, BYTE=1, SHORT=2, INT=3, LONG=4, BIG_INT=5)
"""
Integer type options that can be used by serialization service.

* VAR : variable size integer (this option can be problematic on static type clients like java or .NET)
* BYTE: Python int will be interpreted as a single byte int
* SHORT: Python int will be interpreted as a double byte int
* INT: Python int will be interpreted as a four byte int
* LONG: Python int will be interpreted as an eight byte int
* BIG_INT: Python int will be interpreted as Java BigInteger. This option can handle python long values with "bit_length > 64"

"""

EVICTION_POLICY = enum(NONE=0, LRU=1, LFU=2, RANDOM=3)
"""
Near Cache eviction policy options
Example #5
0
"""
Hazelcast Client Configuration module contains configuration classes and various constants required to create a ClientConfig.

"""
import logging
import os
import re

from hazelcast.serialization.api import StreamSerializer
from hazelcast.util import validate_type, validate_serializer, enum, TimeUnit, check_not_none

INTEGER_TYPE = enum(VAR=0, BYTE=1, SHORT=2, INT=3, LONG=4, BIG_INT=5)
"""
Integer type options that can be used by serialization service.

* VAR : variable size integer (this option can be problematic on static type clients like java or .NET)
* BYTE: Python int will be interpreted as a single byte int
* SHORT: Python int will be interpreted as a double byte int
* INT: Python int will be interpreted as a four byte int
* LONG: Python int will be interpreted as an eight byte int
* BIG_INT: Python int will be interpreted as Java BigInteger. This option can handle python long values with "bit_length > 64"
"""

EVICTION_POLICY = enum(NONE=0, LRU=1, LFU=2, RANDOM=3)
"""
Near Cache eviction policy options

* NONE : No eviction
* LRU : Least Recently Used items will be evicted
* LFU : Least frequently Used items will be evicted
* RANDOM : Items will be evicted randomly
import logging
import uuid

from hazelcast import six
from hazelcast.util import create_git_info, enum

LifecycleState = enum(
    STARTING="STARTING",
    STARTED="STARTED",
    SHUTTING_DOWN="SHUTTING_DOWN",
    SHUTDOWN="SHUTDOWN",
    CONNECTED="CONNECTED",
    DISCONNECTED="DISCONNECTED",
)


class LifecycleService(object):
    """
    Lifecycle service for the Hazelcast client. Allows to determine
    state of the client and add or remove lifecycle listeners.
    """
    def __init__(self, internal_lifecycle_service):
        self._service = internal_lifecycle_service

    def is_running(self):
        """
        Checks whether or not the instance is running.

        :return: ``True``, if the client is active and running, ``False`` otherwise.
        :rtype: bool
        """
Example #7
0
        self.name = name

    def __repr__(self):
        return "DistributedObjectInfo(serviceName=%s, name=%s)" % (
            self.service_name, self.name)

    def __hash__(self):
        return hash((self.name, self.service_name))

    def __eq__(self, other):
        if isinstance(other, DistributedObjectInfo):
            return self.name == other.name and self.service_name == other.service_name
        return False


DistributedObjectEventType = enum(CREATED="CREATED", DESTROYED="DESTROYED")
"""
Type of the distributed object event.

* CREATED : DistributedObject is created.
* DESTROYED: DistributedObject is destroyed. 
"""


class DistributedObjectEvent(object):
    """
    Distributed Object Event
    """
    def __init__(self, name, service_name, event_type, source):
        self.name = name
        self.service_name = service_name
import os

from hazelcast.serialization.api import StreamSerializer
from hazelcast.util import validate_type, validate_serializer, enum, TimeUnit

DEFAULT_GROUP_NAME = "dev"
"""
Default group name of the connected Hazelcast cluster
"""

DEFAULT_GROUP_PASSWORD = "******"
"""
Default password of connected Hazelcast cluster
"""

INTEGER_TYPE = enum(VAR=0, BYTE=1, SHORT=2, INT=3, LONG=4, BIG_INT=5)
"""
Integer type options that can be used by serialization service.

* VAR : variable size integer (this option can be problematic on static type clients like java or .NET)
* BYTE: Python int will be interpreted as a single byte int
* SHORT: Python int will be interpreted as a double byte int
* INT: Python int will be interpreted as a four byte int
* LONG: Python int will be interpreted as an eight byte int
* BIG_INT: Python int will be interpreted as Java BigInteger. This option can handle python long values with "bit_length > 64"

"""

EVICTION_POLICY = enum(NONE=0, LRU=1, LFU=2, RANDOM=3)
"""
Near Cache eviction policy options
Default password of connected Hazelcast cluster
"""

PROPERTY_HEARTBEAT_INTERVAL = "hazelcast.client.heartbeat.interval"
"""
Configuration property for heartbeat interval in milliseconds. Client will send heartbeat to server by this value of interval
unless other requests send to server
"""

PROPERTY_HEARTBEAT_TIMEOUT = "hazelcast.client.heartbeat.timeout"
"""
Configuration property for heartbeat timeout in milliseconds. If client cannot see any activity on a connection for this timeout
value it will shutdown the connection
"""

INTEGER_TYPE = enum(VAR=0, BYTE=1, SHORT=2, INT=3, LONG=4, BIG_INT=5)
"""
Integer type options that can be used by serialization service.

* VAR : variable size integer (this option can be problematic on static type clients like java or .NET)
* BYTE: Python int will be interpreted as a single byte int
* SHORT: Python int will be interpreted as a double byte int
* INT: Python int will be interpreted as a four byte int
* LONG: Python int will be interpreted as an eight byte int
* BIG_INT: Python int will be interpreted as Java BigInteger. This option can handle python long values with "bit_length > 64"

"""

EVICTION_POLICY = enum(NONE=0, LRU=1, LFU=2, RANDOM=3)
"""
Near Cache eviction policy options
Example #10
0
        sleep_time = min(sleep_time,
                         self._cluster_connect_timeout - time_passed)
        self.logger.warning(
            "Unable to get live cluster connection, retry in %ds, attempt: %d, "
            "cluster connect timeout: %ds, max backoff: %ds" %
            (sleep_time, self._attempt, self._cluster_connect_timeout,
             self._max_backoff),
            extra=self._logger_extras)
        time.sleep(sleep_time)
        self._current_backoff = min(self._current_backoff * self._multiplier,
                                    self._max_backoff)
        return True


_AuthenticationStatus = enum(AUTHENTICATED=0,
                             CREDENTIALS_FAILED=1,
                             SERIALIZATION_VERSION_MISMATCH=2,
                             NOT_ALLOWED_IN_CLUSTER=3)


class ConnectionManager(object):
    """
    ConnectionManager is responsible for managing :mod:`Connection` objects.
    """
    logger = logging.getLogger("HazelcastClient.ConnectionManager")

    def __init__(self, client, reactor, address_provider, lifecycle_service,
                 partition_service, cluster_service, invocation_service,
                 near_cache_manager, logger_extras):
        self.live = False
        self.active_connections = dict()
        self.client_uuid = uuid.uuid4()
Example #11
0
    def __init__(self, name, transaction):
        self.name = name
        self.transaction = transaction
        self._to_object = transaction.client.serialization_service.to_object
        self._to_data = transaction.client.serialization_service.to_data

    def _encode_invoke(self, codec, response_handler=default_response_handler, **kwargs):
        request = codec.encode_request(name=self.name, txn_id=self.transaction.id, thread_id=thread_id(), **kwargs)
        return self.transaction.client.invoker.invoke_on_connection(request, self.transaction.connection).continue_with(
                response_handler, codec, self._to_object)

    def __repr__(self):
        return '%s(name="%s")' % (type(self).__name__, self.name)


ItemEventType = enum(added=1, removed=2)
EntryEventType = enum(added=1, removed=2, updated=4, evicted=8, evict_all=16, clear_all=32, merged=64, expired=128, invalidation=256)


class ItemEvent(object):
    def __init__(self, name, item_data, event_type, member, to_object):
        self.name = name
        self._item_data = item_data
        self.event_type = event_type
        self.member = member
        self._to_object = to_object

    @property
    def item(self):
        return self._to_object(self._item_data)
""" Configuration module """

from hazelcast.serialization.api import StreamSerializer
from hazelcast.util import validate_type, validate_serializer, enum

DEFAULT_GROUP_NAME = "dev"
DEFAULT_GROUP_PASSWORD = "******"

PROPERTY_HEARTBEAT_INTERVAL = "hazelcast.client.heartbeat.interval"
PROPERTY_HEARTBEAT_TIMEOUT = "hazelcast.client.heartbeat.timeout"

INTEGER_TYPE = enum(VAR=0, BYTE=1, SHORT=2, INT=3, LONG=4, BIG_INT=5)

class ClientConfig(object):
    def __init__(self):
        self.properties = {}
        self.group_config = GroupConfig()
        self.network_config = ClientNetworkConfig()
        self.load_balancer = None
        self.membership_listeners = []
        self.lifecycle_listeners = []
        # self.near_cache_configs = {} TODO
        # self.reliable_topic_configs = {} TODO
        self.serialization_config = SerializationConfig()

    def get_property_or_default(self, key, default):
        try:
            return self.properties[key]
        except KeyError:
            return default
    def __init__(self, name, transaction):
        self.name = name
        self.transaction = transaction
        self._to_object = transaction.client.serializer.to_object
        self._to_data = transaction.client.serializer.to_data

    def _encode_invoke(self, codec, response_handler=default_response_handler, **kwargs):
        request = codec.encode_request(name=self.name, txn_id=self.transaction.id, thread_id=thread_id(), **kwargs)
        return self.transaction.client.invoker.invoke_on_connection(request, self.transaction.connection).continue_with(
            response_handler, codec, self._to_object)

    def __repr__(self):
        return '%s(name="%s")' % (type(self).__name__, self.name)


ItemEventType = enum(added=1, removed=2)
EntryEventType = enum(added=1,
                      removed=1 << 1,
                      updated=1 << 2,
                      evicted=1 << 3,
                      evict_all=1 << 4,
                      clear_all=1 << 5,
                      merged=1 << 6,
                      expired=1 << 7)


class ItemEvent(object):
    def __init__(self, name, item_data, event_type, member, to_object):
        self.name = name
        self._item_data = item_data
        self.event_type = event_type