core

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package core provides core API interfaces/classes.

Index

Constants

View Source
const (
	// MemberAttributeOperationTypePut indicates an attribute being put.
	MemberAttributeOperationTypePut int32 = 1

	// MemberAttributeOperationTypeRemove indicates an attribute being removed.
	MemberAttributeOperationTypeRemove int32 = 2
)
View Source
const (
	// LifecycleStateStarting is fired when the client is starting.
	LifecycleStateStarting = "STARTING"

	// LifecycleStateStarted is fired when the client start is completed.
	LifecycleStateStarted = "STARTED"

	// LifecycleStateConnected is fired when the client is connected to a member.
	LifecycleStateConnected = "CONNECTED"

	// LifecycleStateDisconnected is fired when the client disconnected from a member.
	LifecycleStateDisconnected = "DISCONNECTED"

	// LifecycleStateShuttingDown is fired when the client is shutting down.
	LifecycleStateShuttingDown = "SHUTTING_DOWN"

	// LifecycleStateShutdown is fired when the client shutdown is completed.
	LifecycleStateShutdown = "SHUTDOWN"
)
View Source
const (
	// OverflowPolicyOverwrite is the policy where the oldest item is overwritten even if it is not old enough to retire.
	// Using this policy you are sacrificing the time-to-live in favor of being able to write.
	//
	// Example: if there is a time-to-live of 30 seconds, the buffer is full and the oldest item in the ring has been placed a
	// second ago, then there are 29 seconds remaining for that item. Using this policy you are going to overwrite no matter
	// what.
	OverflowPolicyOverwrite policy = 0

	// OverflowPolicyFail is the policy where the call will fail immediately and the oldest item will not be overwritten
	// before it is old enough to retire. So this policy sacrifices the ability to write in favor of time-to-live.
	//
	// The advantage of fail is that the caller can decide what to do since it doesn't trap the thread due to backoff.
	//
	// Example: if there is a time-to-live of 30 seconds, the buffer is full and the oldest item in the ring has been placed a
	// second ago, then there are 29 seconds remaining for that item. Using this policy you are not going to overwrite that
	// item for the next 29 seconds.
	OverflowPolicyFail policy = 1
)

Variables

View Source
var MemberSelectors = &selectors{
	&dataMemberSelector{},
}

MemberSelectors is a utility variable to get MemberSelector instances.

Functions

This section is empty.

Types

type AbstractMapEvent

type AbstractMapEvent interface {
	// Name returns the name of the map for this event.
	Name() string

	// Member returns the member that fired this event.
	Member() Member

	// EventType returns the type of entry event.
	EventType() int32

	// String returns a string representation of this event.
	String() string
}

AbstractMapEvent is base for a map event.

type Address

type Address interface {
	fmt.Stringer
	// Host returns host of the member.
	Host() string

	// Port returns the port of the member.
	Port() int
}

Address represents an address of a member in the cluster.

type Cluster

type Cluster interface {
	// AddMembershipListener registers the given listener to listen to membership updates.
	// AddMembershipListener returns uuid which will be used to remove the listener.
	// There is no check for duplicate registrations, so if you register the listener twice,
	// it will get events twice.
	// The given listener should implement MemberAddedListener or MemberRemovedListener interfaces or both.
	// If the given listener does not implement any of these, it will not have any effect.
	AddMembershipListener(listener interface{}) string

	// RemoveMembershipListener removes the listener with the given registrationID.
	// RemoveMembershipListener returns true if successfully removed, false otherwise.
	// If the same MembershipListener is registered multiple times,
	// it needs to be removed multiple times.
	RemoveMembershipListener(registrationID string) bool

	// GetMembers returns a slice of current members in the cluster. The returned slice is
	// a copy of current members.
	GetMembers() []Member
}

Cluster is a cluster service for Hazelcast clients. It provides access to the members in the cluster and one can register for changes in the cluster members. All the methods on the Cluster are thread-safe.

type DistributedObject

type DistributedObject interface {
	// Destroy destroys this object cluster-wide.
	// Destroy clears and releases all resources for this object.
	Destroy() (bool, error)

	// Name returns the unique name for this DistributedObject.
	Name() string

	// PartitionKey returns the key of partition this DistributedObject is assigned to. The returned value only has meaning
	// for a non partitioned data structure like an IAtomicLong. For a partitioned data structure like an Map
	// the returned value will not be nil, but otherwise undefined.
	PartitionKey() string

	// ServiceName returns the service name for this object.
	ServiceName() string
}

DistributedObject is the base interface for all distributed objects.

type EntryAddedListener

type EntryAddedListener interface {
	// EntryAdded is invoked upon addition of an entry.
	EntryAdded(event EntryEvent)
}

EntryAddedListener is invoked upon addition of an entry.

type EntryEvent

type EntryEvent interface {
	// AbstractMapEvent is base for a map event.
	AbstractMapEvent

	// Key returns the key of the entry event.
	Key() interface{}

	// Value returns the value of the entry event.
	Value() interface{}

	// OldValue returns the old value of the entry event.
	OldValue() interface{}

	// MergingValue returns the incoming merging value of the entry event.
	MergingValue() interface{}
}

EntryEvent is map entry event.

type EntryEvictedListener

type EntryEvictedListener interface {
	// EntryEvicted is invoked upon eviction of an entry.
	EntryEvicted(event EntryEvent)
}

EntryEvictedListener is invoked upon eviction of an entry.

type EntryExpiredListener

type EntryExpiredListener interface {
	// EntryExpired is invoked upon expiration of an entry.
	EntryExpired(event EntryEvent)
}

EntryExpiredListener which is notified after removal of an entry due to the expiration-based-eviction.

type EntryLoadedListener added in v0.6.0

type EntryLoadedListener interface {
	// EntryLoaded invoked upon map loading of an entry.
	EntryLoaded(event EntryEvent)
}

EntryLoadedListener invoked upon map loading of an entry.

type EntryMergedListener

type EntryMergedListener interface {
	// EntryMerged is invoked after WAN replicated entry is merged.
	EntryMerged(event EntryEvent)
}

EntryMergedListener is invoked after WAN replicated entry is merged.

type EntryRemovedListener

type EntryRemovedListener interface {
	// EntryRemoved invoked upon removal of an entry.
	EntryRemoved(event EntryEvent)
}

EntryRemovedListener invoked upon removal of an entry.

type EntryUpdatedListener

type EntryUpdatedListener interface {
	// EntryUpdated is invoked upon update of an entry.
	EntryUpdated(event EntryEvent)
}

EntryUpdatedListener is invoked upon update of an entry.

type EntryView

type EntryView interface {
	// Key returns the key of the entry.
	Key() interface{}

	// Value returns the value of the entry.
	Value() interface{}

	// Cost returns the cost in bytes of the entry.
	Cost() int64

	// CreationTime returns the creation time of the entry.
	CreationTime() time.Time

	// ExpirationTime returns the expiration time of the entry.
	ExpirationTime() time.Time

	// Hits returns the number of hits of the entry.
	Hits() int64

	// LastAccessTime returns the last access time for the entry.
	LastAccessTime() time.Time

	// LastStoredTime returns the last store time for the value.
	LastStoredTime() time.Time

	// LastUpdateTime returns the last time the value was updated.
	LastUpdateTime() time.Time

	// Version returns the version of the entry.
	Version() int64

	// EvictionCriteriaNumber returns the criteria number for eviction.
	EvictionCriteriaNumber() int64

	// TTL returns the last set time to live second.
	TTL() time.Duration
}

EntryView represents a readonly view of a map entry.

type FlakeIDGenerator

type FlakeIDGenerator interface {

	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// NewID generates and returns a cluster-wide unique ID.
	//
	// This method goes to a random member and gets a batch of IDs, which will then be returned locally
	// for limited time. The pre-fetch size and the validity can be configured, see FlakeIDGeneratorConfig.
	//
	// Values returned from this method may not be strictly ordered.
	//
	// NewID returns a new cluster-wide unique ID.
	// NewID returns a 'HazelcastError' if node ID for all members in the cluster is out of valid range.
	// See Node ID overflow note above.
	// NewID returns 'HazelcastUnsupportedOperationError' if the cluster version is below 3.10.
	NewID() (id int64, err error)
}

FlakeIDGenerator is a cluster-wide unique ID generator. Generated IDs are 'int64' primitive values and are k-ordered (roughly ordered). IDs are in the range from `0` to `math.MaxInt64`.

The IDs contain timestamp component and a node ID component, which is assigned when the member joins the cluster. This allows the IDs to be ordered and unique without any coordination between members, which makes the generator safe even in split-brain scenario.

Timestamp component is in milliseconds since 1.1.2018, 0:00 UTC and has 41 bits. This caps the useful lifespan of the generator to little less than 70 years (until ~2088). The sequence component is 6 bits. If more than 64 IDs are requested in single millisecond, IDs will gracefully overflow to the next millisecond and uniqueness is guaranteed in this case. The implementation does not allow overflowing by more than 15 seconds, if IDs are requested at higher rate, the call will block. Note, however, that clients are able to generate even faster because each call goes to a different (random) member and the 64 IDs/ms limit is for single member.

Note: Node ID overflow It is possible to generate IDs on any member or client as long as there is at least one member with join version smaller than 2^16 in the cluster. The remedy is to restart the cluster: nodeId will be assigned from zero again. Uniqueness after the restart will be preserved thanks to the timestamp component.

FlakeIDGenerator requires Hazelcast 3.10.

type HazelcastAuthenticationError

type HazelcastAuthenticationError struct {
	*HazelcastErrorType
}

HazelcastAuthenticationError is returned when there is an Authentication failure, e.g., credentials from client is not valid.

func NewHazelcastAuthenticationError

func NewHazelcastAuthenticationError(message string, cause error) *HazelcastAuthenticationError

NewHazelcastAuthenticationError returns a HazelcastAuthenticationError.

type HazelcastCertificateError

type HazelcastCertificateError struct {
	*HazelcastErrorType
}

HazelcastCertificateError is returned when there is an error in certificates.

func NewHazelcastCertificateError

func NewHazelcastCertificateError(message string, cause error) *HazelcastCertificateError

NewHazelcastCertificateError returns a HazelcastCertificateError.

type HazelcastClientNotActiveError

type HazelcastClientNotActiveError struct {
	*HazelcastErrorType
}

HazelcastClientNotActiveError is returned when Hazelcast client is not active during an invocation.

func NewHazelcastClientNotActiveError

func NewHazelcastClientNotActiveError(message string, cause error) *HazelcastClientNotActiveError

NewHazelcastClientNotActiveError returns a HazelcastClientNotActiveError.

type HazelcastClientServiceNotFoundError

type HazelcastClientServiceNotFoundError struct {
	*HazelcastErrorType
}

HazelcastClientServiceNotFoundError indicates that a requested client service doesn't exist.

func NewHazelcastClientServiceNotFoundError

func NewHazelcastClientServiceNotFoundError(message string, cause error) *HazelcastClientServiceNotFoundError

NewHazelcastClientServiceNotFoundError returns a HazelcastClientServiceNotFoundError.

type HazelcastConsistencyLostError

type HazelcastConsistencyLostError struct {
	*HazelcastErrorType
}

HazelcastConsistencyLostError is an error that indicates that the consistency guarantees provided by some service has been lost. The exact guarantees depend on the service.

func NewHazelcastConsistencyLostError

func NewHazelcastConsistencyLostError(message string, cause error) *HazelcastConsistencyLostError

NewHazelcastConsistencyLostError returns a HazelcastConsistencyLostError.

type HazelcastEOFError

type HazelcastEOFError struct {
	*HazelcastErrorType
}

HazelcastEOFError is returned when an EOF error occurs.

func NewHazelcastEOFError

func NewHazelcastEOFError(message string, cause error) *HazelcastEOFError

NewHazelcastEOFError returns a HazelcastEOFError.

type HazelcastError

type HazelcastError interface {
	// Error returns the error message.
	Error() string

	// Cause returns the cause of error.
	Cause() error

	// ServerError returns error info from server side.
	ServerError() ServerError
}

HazelcastError is the general error interface.

type HazelcastErrorType

type HazelcastErrorType struct {
	// contains filtered or unexported fields
}

HazelcastErrorType is the general error struct.

func NewHazelcastErrorType

func NewHazelcastErrorType(message string, cause error) *HazelcastErrorType

NewHazelcastErrorType returns a HazelcastErrorType.

func (*HazelcastErrorType) Cause

func (e *HazelcastErrorType) Cause() error

Cause returns the cause error.

func (*HazelcastErrorType) Error

func (e *HazelcastErrorType) Error() string

Error returns the error message.

func (*HazelcastErrorType) ServerError

func (e *HazelcastErrorType) ServerError() ServerError

ServerError returns error info from server side. It checks if the cause implements ServerError and if it doesnt it return nil.

type HazelcastIOError

type HazelcastIOError struct {
	*HazelcastErrorType
}

HazelcastIOError is returned when an IO error occurs.

func NewHazelcastIOError

func NewHazelcastIOError(message string, cause error) *HazelcastIOError

NewHazelcastIOError returns a HazelcastIOError.

type HazelcastIllegalArgumentError

type HazelcastIllegalArgumentError struct {
	*HazelcastErrorType
}

HazelcastIllegalArgumentError is returned when a method has been passed an illegal or inappropriate argument.

func NewHazelcastIllegalArgumentError

func NewHazelcastIllegalArgumentError(message string, cause error) *HazelcastIllegalArgumentError

NewHazelcastIllegalArgumentError returns a HazelcastIllegalArgumentError.

type HazelcastIllegalStateError

type HazelcastIllegalStateError struct {
	*HazelcastErrorType
}

HazelcastIllegalStateError is returned when a method has been invoked at an illegal or inappropriate time.

func NewHazelcastIllegalStateError

func NewHazelcastIllegalStateError(message string, cause error) *HazelcastIllegalStateError

NewHazelcastIllegalStateError returns a HazelcastIllegalStateError.

type HazelcastInstanceNotActiveError

type HazelcastInstanceNotActiveError struct {
	*HazelcastErrorType
}

HazelcastInstanceNotActiveError is returned when HazelcastInstance is not active during an invocation.

func NewHazelcastInstanceNotActiveError

func NewHazelcastInstanceNotActiveError(message string, cause error) *HazelcastInstanceNotActiveError

NewHazelcastInstanceNotActiveError returns a HazelcastInstanceNotActiveError.

type HazelcastJSONValue

type HazelcastJSONValue struct {
	// contains filtered or unexported fields
}

HazelcastJSONValue is a wrapper for JSON formatted strings. It is preferred to store HazelcastJSONValue instead of string/[]byte for JSON. Users can run predicates/aggregations and use indexes on the attributes of the underlying JSON objects.

HazelcastJSONValue is queried using Hazelcast's querying language.

HazelcastJSONValue keeps given string as it is. Strings are not checked for being valid. Ill-formatted JSON strings may cause false positive or false negative results in queries.

func CreateHazelcastJSONValue

func CreateHazelcastJSONValue(object interface{}) (*HazelcastJSONValue, error)

CreateHazelcastJSONValue returns *HazelcastJSONValue constructed from the provided object if nil, channel, complex or function values are given, method returns error

func CreateHazelcastJSONValueFromString

func CreateHazelcastJSONValueFromString(jsonString string) *HazelcastJSONValue

CreateHazelcastJSONValueFromString returns *HazelcastJSONValue initialized with the given string

func (*HazelcastJSONValue) ToString

func (h *HazelcastJSONValue) ToString() string

ToString returns unaltered string that was used to create this object.

func (*HazelcastJSONValue) Unmarshal

func (h *HazelcastJSONValue) Unmarshal(v interface{}) error

Unmarshal converts HazelcastJSONValue into given v object Returns error if JSON is not valid

type HazelcastNilPointerError

type HazelcastNilPointerError struct {
	*HazelcastErrorType
}

HazelcastNilPointerError is returned when a nil argument has been passed to a method.

func NewHazelcastNilPointerError

func NewHazelcastNilPointerError(message string, cause error) *HazelcastNilPointerError

NewHazelcastNilPointerError returns a HazelcastNilPointerError.

type HazelcastNoDataMemberInClusterError

type HazelcastNoDataMemberInClusterError struct {
	*HazelcastErrorType
}

HazelcastNoDataMemberInClusterError is returned when there is no data member in the cluster to assign partitions.

func NewHazelcastNoDataMemberInClusterError

func NewHazelcastNoDataMemberInClusterError(message string, cause error) *HazelcastNoDataMemberInClusterError

NewHazelcastNoDataMemberInClusterError returns a HazelcastNoDataMemberInClusterError.

type HazelcastOperationTimeoutError

type HazelcastOperationTimeoutError struct {
	*HazelcastErrorType
}

HazelcastOperationTimeoutError is returned when an operation times out.

func NewHazelcastOperationTimeoutError

func NewHazelcastOperationTimeoutError(message string, cause error) *HazelcastOperationTimeoutError

NewHazelcastOperationTimeoutError returns a HazelcastOperationTimeoutError.

type HazelcastSerializationError

type HazelcastSerializationError struct {
	*HazelcastErrorType
}

HazelcastSerializationError is returned when an error occurs while serializing/deserializing objects.

func NewHazelcastSerializationError

func NewHazelcastSerializationError(message string, cause error) *HazelcastSerializationError

NewHazelcastSerializationError returns a HazelcastSerializationError.

type HazelcastTargetDisconnectedError

type HazelcastTargetDisconnectedError struct {
	*HazelcastErrorType
}

HazelcastTargetDisconnectedError indicates that an operation is about to be sent to a non existing machine.

func NewHazelcastTargetDisconnectedError

func NewHazelcastTargetDisconnectedError(message string, cause error) *HazelcastTargetDisconnectedError

NewHazelcastTargetDisconnectedError returns a HazelcastTargetDisconnectedError.

type HazelcastTargetNotMemberError

type HazelcastTargetNotMemberError struct {
	*HazelcastErrorType
}

HazelcastTargetNotMemberError indicates operation is send to a machine that isn't member of the cluster.

func NewHazelcastTargetNotMemberError

func NewHazelcastTargetNotMemberError(message string, cause error) *HazelcastTargetNotMemberError

NewHazelcastTargetNotMemberError returns a HazelcastTargetNotMemberError.

type HazelcastTopicOverflowError

type HazelcastTopicOverflowError struct {
	*HazelcastErrorType
}

HazelcastTopicOverflowError is returned when a publisher wants to write to a topic, but there is not sufficient storage to deal with the event. This is returned only when reliable topic is used.

func NewHazelcastTopicOverflowError

func NewHazelcastTopicOverflowError(message string, cause error) *HazelcastTopicOverflowError

NewHazelcastTopicOverflowError return a HazelcastTopicOverflowError.

type HazelcastUnsupportedOperationError

type HazelcastUnsupportedOperationError struct {
	*HazelcastErrorType
}

HazelcastUnsupportedOperationError is returned to indicate that the requested operation is not supported.

func NewHazelcastUnsupportedOperationError

func NewHazelcastUnsupportedOperationError(message string, cause error) *HazelcastUnsupportedOperationError

NewHazelcastUnsupportedOperationError returns a HazelcastUnsupportedOperationError.

type ItemAddedListener

type ItemAddedListener interface {
	ItemAdded(event ItemEvent)
}

ItemAddedListener is invoked when an item is added.

type ItemEvent

type ItemEvent interface {
	// Name returns the name of List, Set or Queue.
	Name() string

	// Item returns the item of the event.
	Item() interface{}

	// EventType returns 1 if an item is added, 2 if an item is removed.
	EventType() int32

	// Member is the member that sent the event.
	Member() Member
}

ItemEvent is List, Set and Queue events common contract.

type ItemRemovedListener

type ItemRemovedListener interface {
	ItemRemoved(event ItemEvent)
}

ItemRemovedListener is invoked when an item is removed.

type LifecycleListener

type LifecycleListener interface {
	// LifecycleStateChanged is called when instance's state changes. No blocking calls should be made in this method.
	LifecycleStateChanged(string)
}

LifecycleListener is a listener object for listening to lifecycle events of the Hazelcast instance.

type LifecycleService

type LifecycleService interface {
	// AddLifecycleListener adds a listener object to listen for lifecycle events.
	// AddLifecycleListener returns the registrationID.
	AddLifecycleListener(listener interface{}) string

	// RemoveLifecycleListener removes lifecycle listener with the given registrationID.
	// RemoveLifecycleListener returns true if the listener is removed successfully, false otherwise.
	RemoveLifecycleListener(registrationID string) bool

	// IsRunning checks whether or not the client is running.
	IsRunning() bool
}

LifecycleService allows you to shutdown, terminate, and listen to lifecycle events on HazelcastInstance.

type List

type List interface {

	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// Add appends the specified element to the end of this list.
	// Add returns true if the list has changed as a result of this operation, false otherwise.
	Add(element interface{}) (changed bool, err error)

	// AddAt inserts the specified element at the specified index.
	// AddAt shifts the subsequent elements to the right.
	AddAt(index int32, element interface{}) (err error)

	// AddAll appends all elements in the specified slice to the end of this list.
	// AddAll returns true if the list has changed as a result of this operation, false otherwise.
	AddAll(elements []interface{}) (changed bool, err error)

	// AddAllAt inserts all elements in the specified slice at specified index, keeping the order of the slice.
	// AddAllAt shifts the subsequent elements to the right.
	// AddAllAt returns true if the list has changed as a result of this operation, false otherwise.
	AddAllAt(index int32, elements []interface{}) (changed bool, err error)

	// AddItemListener adds an item listener for this list.
	// Listener will be invoked whenever an item is added to or removed from this list.
	// To receive an event, listener should implement a corresponding interface for that event
	// such as ItemAddedListener, ItemRemovedListener.
	// AddItemListener returns registrationID of the listener.
	AddItemListener(listener interface{}, includeValue bool) (registrationID string, err error)

	// Clear clears this list.
	Clear() (err error)

	// Contains checks if the list contains the given element.
	// Contains returns true if the list contains the element, false otherwise.
	Contains(element interface{}) (found bool, err error)

	// ContainsAll checks if the list contains all of the given elements.
	// ContainsAll returns true if the list contains all of the elements, otherwise false.
	ContainsAll(elements []interface{}) (foundAll bool, err error)

	// Get retrieves the element at given index.
	Get(index int32) (element interface{}, err error)

	// IndexOf returns the position of first occurrence of the given element in this list.
	IndexOf(element interface{}) (index int32, err error)

	// IsEmpty return true if the list is empty, false otherwise.
	IsEmpty() (empty bool, err error)

	// LastIndexOf returns the position of the last occurrence of the given element in this list.
	LastIndexOf(element interface{}) (index int32, err error)

	// Remove removes the given element from this list.
	// Remove returns true if the list has changed as a result of this operation, false otherwise.
	Remove(element interface{}) (changed bool, err error)

	// RemoveAt removes the element at the given index.
	// RemoveAt returns the removed element.
	RemoveAt(index int32) (previousElement interface{}, err error)

	// RemoveAll removes the given elements from the list.
	// RemoveAll returns true if the list has changed as a result of this operation, false otherwise.
	RemoveAll(elements []interface{}) (changed bool, err error)

	// RemoveItemListener removes the item listener with the given registrationID.
	// RemoveItemListener returns true if the listener is removed, false otherwise.
	RemoveItemListener(registrationID string) (removed bool, err error)

	// RetainAll removes all elements from this list except the ones contained in the given slice.
	// RetainAll returns true if the list has changed as a result of this operation, false otherwise.
	RetainAll(elements []interface{}) (changed bool, err error)

	// Set replaces the element at the specified index in this list with the specified element.
	// Set returns the previousElement from the list.
	Set(index int32, element interface{}) (previousElement interface{}, err error)

	// Size returns the number of elements in this list.
	Size() (size int32, err error)

	// SubList returns a view of this list that contains elements between index numbers
	// from start (inclusive) to end (exclusive).
	SubList(start int32, end int32) (elements []interface{}, err error)

	// ToSlice returns a slice that contains all elements of this list in proper sequence.
	ToSlice() (elements []interface{}, err error)
}

List is a concurrent, distributed, ordered collection. The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.

The Hazelcast List is not a partitioned data-structure. So all the content of the List is stored in a single machine (and in the backup). So the List will not scale by adding more members in the cluster.

type LoadBalancer

type LoadBalancer interface {
	// Init initializes LoadBalancer with the given cluster.
	// The given cluster is used to select members.
	Init(cluster Cluster)

	// Next returns the next member to route to.
	// It returns nil if no member is available.
	Next() Member
}

LoadBalancer allows you to send operations to one of a number of endpoints(Members). It is up to the implementation to use different load balancing policies.

If client is configured with smart routing, only the operations that are not key based will be routed to the endpoint returned by the LoadBalancer. If the client is not smart routing, LoadBalancer will not be used.

type Map

type Map interface {
	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// Put returns the value with the specified key in this map.
	// If the map previously contained a mapping for
	// the key, the old value is replaced by the specified value.
	// Put returns a clone of the previous value, not the original (identically equal) value previously put
	// into the map.
	// Put returns nil if there was no mapping for the key.
	Put(key interface{}, value interface{}) (oldValue interface{}, err error)

	// Get returns the value for the specified key, or nil if this map does not contain this key.
	// Warning:
	// Get returns a clone of original value, modifying the returned value does not change the actual value in
	// the map. One should put modified value back to make changes visible to all nodes.
	//	value,_ = map.Get(key)
	//	value.updateSomeProperty()
	//	map.Put(key,value)
	Get(key interface{}) (value interface{}, err error)

	// Remove removes the mapping for a key from this map if it is present. The map will not contain a mapping for the
	// specified key once the call returns.
	// If you don't need the previously mapped value for the removed key, prefer to use
	// delete and avoid the cost of serialization and network transfer.
	// It returns a clone of the previous value, not the original (identically equal) value
	// previously put into the map.
	// Remove returns the previous value associated with key, or nil if there was no mapping for the key.
	Remove(key interface{}) (value interface{}, err error)

	// RemoveIfSame removes the entry for a key only if it is currently mapped to a given value.
	// RemoveIfSame returns true if the value was removed.
	// This is equivalent to:
	//	if ok,_ := mp.ContainsKey(key) ; ok {
	//		if mp.Get(key) == value {
	//			mp.Remove(key)
	//			return true
	//		}
	//	}
	//	return false
	// except that the action is performed atomically.
	RemoveIfSame(key interface{}, value interface{}) (ok bool, err error)

	// RemoveAll removes all entries which match with the supplied predicate.
	// If this map has index, matching entries will be found via index search,
	// otherwise they will be found by full-scan.
	// Note that calling this method also removes all entries from caller's Near Cache.
	RemoveAll(predicate interface{}) (err error)

	// Size returns the number of entries in this map.
	Size() (size int32, err error)

	// Aggregate applies the aggregation logic on all map entries and returns the result.
	// Fast-Aggregations are the successor of the Map-Reduce Aggregators.
	// They are equivalent to the Map-Reduce Aggregators in most of the use-cases, but instead of running on the Map-Reduce
	// engine they run on the Query infrastructure. Their performance is tens to hundreds times better due to the fact
	// that they run in parallel for each partition and are highly optimized for speed and low memory consumption.
	// The given aggregator must be serializable via hazelcast serialization and have a counterpart on server side.
	// Aggregate returns the result of the given aggregator.
	Aggregate(aggregator interface{}) (result interface{}, err error)

	// AggregateWithPredicate applies the aggregation logic on map entries filtered with the Predicated and returns the result
	//
	// Fast-Aggregations are the successor of the Map-Reduce Aggregators.
	// They are equivalent to the Map-Reduce Aggregators in most of the use-cases, but instead of running on the Map-Reduce
	// engine they run on the Query infrastructure. Their performance is tens to hundreds times better due to the fact
	// that they run in parallel for each partition and are highly optimized for speed and low memory consumption.
	// The given aggregator must be serializable via hazelcast serialization and have a counterpart on server side.
	// The given predicate must be serializable via hazelcast serialization and have a counterpart on server side.
	// AggregateWithPredicate returns the result of the given aggregator.
	AggregateWithPredicate(aggregator interface{}, predicate interface{}) (result interface{}, err error)

	// ContainsKey determines whether this map contains an entry with the key.
	// ContainsKey returns true if this map contains an entry for the specified key.
	ContainsKey(key interface{}) (found bool, err error)

	// ContainsValue determines whether this map contains one or more keys for the specified value.
	// ContainsValue  returns true if this map contains an entry for the specified value.
	ContainsValue(value interface{}) (found bool, err error)

	// Clear clears the map and deletes the items from the backing map store.
	Clear() (err error)

	// Delete removes the mapping for a key from this map if it is present (optional operation).
	// Unlike Remove(), this operation does not return the removed value, which avoids the serialization cost of
	// the returned value. If the removed value will not be used, a delete operation is preferred over a remove
	// operation for better performance.
	// The map will not contain a mapping for the specified key once the call returns.
	// Warning:
	// This method breaks the contract of EntryListener. When an entry is removed by Delete(), it fires an EntryEvent
	// with a nil oldValue. Also, a listener with predicate will have nil values, so only the keys can be queried
	// via predicate.
	Delete(key interface{}) (err error)

	// IsEmpty returns true if this map contains no key-value mappings.
	IsEmpty() (empty bool, err error)

	// AddIndex Adds an index to this map for the specified entries so
	// that queries can run faster.
	//
	// Let's say your map values are Employee struct which implements identifiedDataSerializable.
	//	type Employee struct {
	//		age int32
	//		name string
	//		active bool
	//		// other fields
	//	}
	//	// methods
	// If you are querying your values mostly based on age and active then
	// you should consider indexing these fields.
	//	mp, _ := client.GetMap("employee")
	//	mp.AddIndex("age", true);        // ordered, since we have ranged queries for this field
	//	mp.AddIndex("active", false);    // not ordered, because boolean field cannot have range
	//
	// You should make sure to add the indexes before adding
	// entries to this map.
	//
	// Indexing is executed in parallel on each partition by operation threads on server side. The Map
	// is not blocked during this operation.
	//
	// The time taken in is proportional to the size of the Map and the number of members.
	//
	// Until the index finishes being created, any searches for the attribute will use a full Map scan,
	// thus avoiding using a partially built index and returning incorrect results.
	AddIndex(attribute string, ordered bool) (err error)

	// Evict evicts the specified key from this map.
	// Evict returns true if the key is evicted, false otherwise.
	Evict(key interface{}) (evicted bool, err error)

	// EvictAll evicts all keys from this map except the locked ones.
	// The EvictAll event is fired for any registered listeners for MapEvicted.
	EvictAll() (err error)

	// Flush flushes all the local dirty entries.
	// Please note that this method has effect only if write-behind
	// persistence mode is configured. If the persistence mode is
	// write-through calling this method has no practical effect, but an
	// operation is executed on all partitions wasting resources.
	Flush() (err error)

	// ForceUnlock releases the lock for the specified key regardless of the lock owner.
	// It always successfully unlocks the key, never blocks, and returns immediately.
	ForceUnlock(key interface{}) (err error)

	// Lock acquires the lock for the specified key infinitely.
	// If the lock is not available, the current thread becomes disabled for thread scheduling purposes and lies
	// dormant until the lock has been acquired.
	// You get a lock whether the value is present in the map or not. Other threads (possibly on other systems) would
	// block on their invoke of Lock() until the non-existent key is unlocked. If the lock holder introduces the key to
	// the map, the Put() operation is not blocked. If a thread not holding a lock on the non-existent key tries to
	// introduce the key while a lock exists on the non-existent key, the Put() operation blocks until it is unlocked.
	// Scope of the lock is this map only. Acquired lock is only for the key in this map.
	// Locks are re-entrant; so, if the key is locked N times, it should be unlocked N times before another thread can
	// acquire it.
	Lock(key interface{}) (err error)

	// LockWithLeaseTime acquires the lock for the specified key for the specified lease time.
	// After lease time, the lock will be released.
	// If the lock is not available, then
	// the current thread becomes disabled for thread scheduling
	// purposes and lies dormant until the lock has been acquired.
	// Scope of the lock is this map only.
	// Acquired lock is only for the key in this map.
	// Locks are re-entrant, so if the key is locked N times then
	// it should be unlocked N times before another thread can acquire it.
	LockWithLeaseTime(key interface{}, lease time.Duration) (err error)

	// Unlock releases the lock for the specified key. It never blocks and returns immediately.
	// If the current thread is the holder of this lock,
	// then the hold count is decremented. If the hold count is zero, then the lock is released.
	Unlock(key interface{}) (err error)

	// IsLocked checks the lock for the specified key.
	// If the lock is acquired, it returns true. Otherwise, it returns false.
	IsLocked(key interface{}) (locked bool, err error)

	// Replace replaces the entry for a key only if it is currently mapped to some value.
	// This is equivalent to:
	//	if ok,_ := mp.ContainsKey(key) ; ok {
	//		return mp.Put(key,value)
	//	}else{
	//		return nil
	//  }
	// except that the action is performed atomically.
	// Warning:
	// Replace returns a clone of the previous value, not the original (identically equal) value previously put
	// into the map.
	Replace(key interface{}, value interface{}) (oldValue interface{}, err error)

	// ReplaceIfSame replaces the entry for a key only if it is currently mapped to a given value.
	// This is equivalent to:
	//	if ok,_ := mp.ContainsKey(key) ; ok {
	//		if mp.Get(key) == oldValue {
	//			mp.Put(key,value)
	//			return true
	//		}
	//	}
	//	return false
	// except that the action is performed atomically.
	//
	// This method may return false even if the operation succeeds.
	// Background: If the partition owner for given key goes down after successful value replace,
	// but before the executing node retrieved the invocation result response, then the operation is retried.
	// The invocation retry fails because the value is already updated and the result of such replace call
	// returns false. Hazelcast doesn't guarantee exactly once invocation.
	// ReplaceIfSame returns true if the value was replaced.
	ReplaceIfSame(key interface{}, oldValue interface{}, newValue interface{}) (replaced bool, err error)

	// Set puts an entry into this map without returning the old value
	// (which is more efficient than Put()).
	// Set breaks the contract of EntryListener.
	// When an entry is updated by Set(), it fires an EntryEvent with a nil oldValue.
	// If you have previously set a TTL for the key, the TTL remains unchanged and the entry will
	// expire when the initial TTL has elapsed.
	Set(key interface{}, value interface{}) (err error)

	// SetWithTTl puts an entry into this map with a given TTL (time to live) value,
	// without returning the old value (which is more efficient than Put()).
	// The entry will expire and get evicted after the TTL. If the TTL is 0,
	// then the entry lives forever. If the TTL is negative, then the TTL
	// from the map configuration will be used (default: forever).
	// For example:
	// 	mp.SetWithTTL("testingKey1", "testingValue1", 5 * time. Second)
	// will expire and get evicted after 5 seconds whereas
	//  mp.SetWithTTL("testingKey1", "testingValue1", 5 * time. Millisecond)
	// will expire and get evicted after 5 milliseconds.
	SetWithTTL(key interface{}, value interface{}, ttl time.Duration) (err error)

	// PutIfAbsent associates the specified key with the given value
	// if it is not already associated.
	// This is equivalent to:
	//	if ok,_ := mp.ContainsKey(key) ; !ok {
	//		return mp.Put(key,value)
	//	}else{
	//		return mp.Get(key)
	//  }
	// except that the action is performed atomically.
	// Warning:
	// PutIfAbsent returns a clone of the previous value,
	// not the original (identically equal) value previously put
	// into the map.
	// PutIfAbsent returns the old value of the key.
	PutIfAbsent(key interface{}, value interface{}) (oldValue interface{}, err error)

	// PutAll copies all of the mappings from the specified map to this map. No atomicity guarantees are
	// given. In the case of a failure, some of the key-value tuples may get written, while others are not.
	PutAll(entries map[interface{}]interface{}) (err error)

	// Project applies the projection logic on all map entries and returns the result.
	// The given projection must be serializable via hazelcast serialization and have a counterpart on server side.
	// Project returns the result of the given projection.
	Project(projection interface{}) (result []interface{}, err error)

	// ProjectWithPredicate applies the projection logic on map entries filtered with the predicate and returns the result.
	// The given projection must be serializable via hazelcast serialization and have a counterpart on server side.
	// The given predicate must be serializable via hazelcast serialization and have a counterpart on server side.
	// ProjectWithPredicate returns the result of the given predicate and projection.
	ProjectWithPredicate(projection interface{}, predicate interface{}) (result []interface{}, err error)

	// KeySet returns a slice clone of the keys contained in this map.
	// Warning:
	// The slice is NOT backed by the map, so changes to the map are NOT reflected in the slice, and vice-versa.
	KeySet() (keySet []interface{}, err error)

	// KeySetWithPredicate queries the map based on the specified predicate and
	// returns the keys of matching entries.
	// Specified predicate runs on all members in parallel.
	// The slice is NOT backed by the map, so changes to the map are NOT reflected in the slice, and vice-versa.
	KeySetWithPredicate(predicate interface{}) (keySet []interface{}, err error)

	// Values returns a slice clone of the values contained in this map.
	// The slice is NOT backed by the map, so changes to the map are NOT reflected in the slice, and vice-versa.
	Values() (values []interface{}, err error)

	// ValuesWithPredicate queries the map based on the specified predicate and returns the values of matching entries.
	// Specified predicate runs on all members in parallel.
	// The slice is NOT backed by the map, so changes to the map are NOT reflected in the slice, and vice-versa.
	ValuesWithPredicate(predicate interface{}) (values []interface{}, err error)

	// EntrySet returns a slice of Pairs clone of the mappings contained in this map.
	// The slice is NOT backed by the map, so changes to the map are NOT reflected in the slice, and vice-versa.
	EntrySet() (resultPairs []Pair, err error)

	// EntrySetWithPredicate queries the map based on the specified predicate and returns the matching entries.
	// Specified predicate runs on all members in parallel.
	// The slice is NOT backed by the map, so changes to the map are NOT reflected in the slice, and vice-versa.
	EntrySetWithPredicate(predicate interface{}) (resultPairs []Pair, err error)

	// TryLock tries to acquire the lock for the specified key.
	// If the lock is not available then the current thread
	// does not wait and returns false immediately.
	// TryLock returns true if lock is acquired, false otherwise.
	TryLock(key interface{}) (locked bool, err error)

	// TryLockWithTimeout tries to acquire the lock for the specified key.
	// If the lock is not available, then
	// the current thread becomes disabled for thread scheduling
	// purposes and lies dormant until one of two things happens:
	//	the lock is acquired by the current thread, or
	//	the specified waiting time elapses.
	// TryLockWithTimeout returns true if lock is acquired, false otherwise.
	TryLockWithTimeout(key interface{}, timeout time.Duration) (locked bool, err error)

	// TryLockWithTimeoutAndLease tries to acquire the lock for the specified key for the specified lease time.
	// After lease time, the lock will be released.
	// If the lock is not available, then
	// the current thread becomes disabled for thread scheduling
	// purposes and lies dormant until one of two things happens:
	//	the lock is acquired by the current thread, or
	//	the specified waiting time elapses.
	// TryLockWithTimeoutAndLease returns true if lock is acquired, false otherwise.
	TryLockWithTimeoutAndLease(key interface{}, timeout time.Duration, lease time.Duration) (locked bool, err error)

	// TryPut tries to put the given key and value into this map and returns immediately.
	// TryPut returns true if the put is successful, false otherwise.
	TryPut(key interface{}, value interface{}) (ok bool, err error)

	// TryPutWithTimeout tries to put the given key and value into this map within a specified
	// timeout value. If this method returns false, it means that
	// the caller thread could not acquire the lock for the key within the
	// timeout duration, thus the put operation is not successful.
	TryPutWithTimeout(key interface{}, value interface{}, timeout time.Duration) (ok bool, err error)

	// TryRemove tries to remove the entry with the given key from this map
	// within the specified timeout value. If the key is already locked by another
	// thread and/or member, then this operation will wait the timeout
	// amount for acquiring the lock.
	// TryRemove returns true if the remove is successful, false otherwise.
	TryRemove(key interface{}, timeout time.Duration) (ok bool, err error)

	// GetAll returns the entries for the given keys.
	// The returned map is NOT backed by the original map,
	// so changes to the original map are NOT reflected in the returned map, and vice-versa.
	GetAll(keys []interface{}) (entryMap map[interface{}]interface{}, err error)

	// GetEntryView returns the EntryView for the specified key.
	// GetEntryView returns a clone of original mapping, modifying the returned value does not change
	// the actual value in the map. One should put modified value back to make changes visible to all nodes.
	GetEntryView(key interface{}) (entryView EntryView, err error)

	// PutTransient operates same as Put(), but
	// the entry will expire and get evicted after the TTL. If the TTL is 0,
	// then the entry lives forever. If the TTL is negative, then the TTL
	// from the configuration will be used (default: forever).
	PutTransient(key interface{}, value interface{}, ttl time.Duration) (err error)

	// AddEntryListener adds a continuous entry listener for this map.
	// To receive an event, listener should implement a corresponding interface for that event.
	// Supported listeners for Map:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * EntryUpdatedListener
	//  * EntryEvictedListener
	//  * EntryMergedListener
	//  * EntryExpiredListener
	//  * MapEvictedListener
	//  * MapClearedListener
	// AddEntryListener returns uuid which is used as a key to remove the listener.
	AddEntryListener(listener interface{}, includeValue bool) (registrationID string, err error)

	// AddEntryListenerWithPredicate adds a continuous entry listener for this map filtered with the given predicate.
	// Supported listeners for Map:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * EntryUpdatedListener
	//  * EntryEvictedListener
	//  * EntryMergedListener
	//  * EntryExpiredListener
	//  * MapEvictedListener
	//  * MapClearedListener
	// AddEntryListenerWithPredicate returns uuid which is used as a key to remove the listener.
	AddEntryListenerWithPredicate(listener interface{}, predicate interface{}, includeValue bool) (registrationID string, err error)

	// AddEntryListenerToKey adds a continuous entry listener for this map filtered with the given key.
	// Supported listeners for Map:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * EntryUpdatedListener
	//  * EntryEvictedListener
	//  * EntryMergedListener
	//  * EntryExpiredListener
	//  * MapEvictedListener
	//  * MapClearedListener
	// AddEntryListenerToKey returns uuid which is used as a key to remove the listener.
	AddEntryListenerToKey(listener interface{}, key interface{}, includeValue bool) (registrationID string, err error)

	// AddEntryListenerToKeyWithPredicate adds a continuous entry listener for this map filtered with the given key and predicate.
	// Supported listeners for Map:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * EntryUpdatedListener
	//  * EntryEvictedListener
	//  * EntryMergedListener
	//  * EntryExpiredListener
	//  * MapEvictedListener
	//  * MapClearedListener
	// AddEntryListenerToKeyWithPredicate returns uuid which is used as a key to remove the listener.
	AddEntryListenerToKeyWithPredicate(listener interface{}, predicate interface{}, key interface{}, includeValue bool) (
		registrationID string, err error)

	// RemoveEntryListener removes the specified entry listener with the given registrationID.
	// RemoveEntryListener returns silently if there is no such listener added before.
	// RemoveEntryListener true if registration is removed, false otherwise.
	RemoveEntryListener(registrationID string) (removed bool, err error)

	// ExecuteOnKey applies the user defined EntryProcessor to the entry mapped by the key.
	// ExecuteOnKey returns the result of EntryProcessor's process method.
	// Entry_processor should be a stateful serializable struct which represents the EntryProcessor defined
	// on the server side.
	// This struct must have a serializable EntryProcessor counter part registered on server side with the actual
	// org.hazelcast.map.EntryProcessor implementation.
	ExecuteOnKey(key interface{}, entryProcessor interface{}) (result interface{}, err error)

	// ExecuteOnKeys applies the user defined EntryProcessor to the entries mapped by the slice of keys.
	// Returns the results mapped by each key in the slice.
	// Entry_processor should be a stateful serializable struct which represents the EntryProcessor defined
	// on the server side.
	// This struct must have a serializable EntryProcessor counter part registered on server side with the actual
	// org.hazelcast.map.EntryProcessor implementation.
	ExecuteOnKeys(keys []interface{}, entryProcessor interface{}) (keyToResultPairs []Pair, err error)

	// ExecuteOnEntries applies the user defined EntryProcessor to all the entries in the map.
	// Returns the results mapped by each key in the map.
	// Entry_processor should be a stateful serializable struct which represents the EntryProcessor defined
	// on the server side.
	// This struct must have a serializable EntryProcessor counter part registered on server side with the actual
	// org.hazelcast.map.EntryProcessor implementation.
	ExecuteOnEntries(entryProcessor interface{}) (keyToResultPairs []Pair, err error)

	// ExecuteOnEntriesWithPredicate applies the user defined EntryProcessor to entries in the map which satisfies
	// the predicate.
	// Returns the results mapped by each key in the map.
	// Entry_processor should be a stateful serializable struct which represents the EntryProcessor defined
	// on the server side.
	// This struct must have a serializable EntryProcessor counter part registered on server side with the actual
	// org.hazelcast.map.EntryProcessor implementation.
	ExecuteOnEntriesWithPredicate(entryProcessor interface{}, predicate interface{}) (keyToResultPairs []Pair, err error)
}

Map is concurrent, distributed, observable and queryable. This map is sync (blocking). Blocking calls return the value of the call and block the execution until the return value is calculated. It does not allow nil to be used as a key or value.

type MapClearedListener

type MapClearedListener interface {
	// MapCleared is invoked when all entries are removed
	// by Map.Clear method.
	MapCleared(event MapEvent)
}

MapClearedListener is invoked when all entries are removed by Map.Clear method.

type MapEvent

type MapEvent interface {
	// AbstractMapEvent is base for a map event.
	AbstractMapEvent

	// NumberOfAffectedEntries returns the number of affected
	// entries by this event.
	NumberOfAffectedEntries() int32
}

MapEvent is map events common contract.

type MapEvictedListener

type MapEvictedListener interface {
	// MapEvicted is invoked when all entries are evicted
	// by Map.EvictAll method.
	MapEvicted(event MapEvent)
}

MapEvictedListener is invoked when all entries are evicted by Map.EvictAll method.

type Member

type Member interface {
	fmt.Stringer
	// Address returns the address of this member.
	Address() Address

	// UUID returns the uuid of this member.
	UUID() string

	// IsLiteMember returns true if this member is a lite member.
	IsLiteMember() bool

	// Attributes returns configured attributes for this member.
	Attributes() map[string]string
}

Member represents a member in the cluster with its address, uuid, lite member status and attributes.

type MemberAddedListener

type MemberAddedListener interface {
	// MemberAdded is invoked when a new member is added to the cluster.
	MemberAdded(member Member)
}

MemberAddedListener is invoked when a new member is added to the cluster.

type MemberAttributeChangedListener

type MemberAttributeChangedListener interface {
	// MemberAttributeChanged is invoked when attribute of a member has changed.
	MemberAttributeChanged(event MemberAttributeEvent)
}

MemberAttributeChangedListener is invoked when attribute of a member has changed.

type MemberAttributeEvent

type MemberAttributeEvent interface {
	// OperationType returns the type of member attribute change for this MemberAttributeEvent
	OperationType() int32

	// Key returns the key for this MemberAttributeEvent.
	Key() string

	// Value returns the value for this MemberAttributeEvent
	Value() string

	// Member returns the member for this MemberAttributeEvent.
	Member() Member
}

MemberAttributeEvent is an event for member attribute changes.

type MemberRemovedListener

type MemberRemovedListener interface {
	// MemberRemoved is invoked when an existing member leaves the cluster.
	MemberRemoved(member Member)
}

MemberRemovedListener is invoked when an existing member leaves the cluster.

type MemberSelector

type MemberSelector interface {
	// Select decides if the given member will be part of an operation or not.
	// Select returns true if the member should take part in the operation, false otherwise.
	Select(member Member) (selected bool)
}

MemberSelector is an interface for implementations selecting members that are capable of executing a special kind of task. The Select method is called for every available member in the cluster and it is up to the implementation to decide if the member is going to be used or not.

type Message

type Message interface {
	// MessageObject returns the published message.
	MessageObject() interface{}

	// PublishTime returns the time in milliseconds when the message is published.
	PublishTime() time.Time

	// PublishMember returns the member that published the message.
	// The member can be nil if:
	//    - The message was sent by a client and not a member.
	//    - The member, that sent the message, left the cluster before the message was processed.
	PublishingMember() Member
}

Message is a message for Topic.

type MessageListener

type MessageListener interface {
	// OnMessage is invoked when a message is received for the added topic. Note that topic guarantees message ordering.
	// Therefore there is only one thread invoking OnMessage.
	OnMessage(message Message) error
}

MessageListener is a listener for Topic. Provided that a MessageListener is not registered twice, a MessageListener will never be called concurrently. So there is no need to provide thread-safety on internal state in the MessageListener. Also there is no need to enforce safe publication, the Topic is responsible for the memory consistency effects. In other words, there is no need to make internal fields of the MessageListener volatile or access them using synchronized blocks.

type MultiMap

type MultiMap interface {
	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// Put stores a key-value pair in the multi-map.
	// It returns true if size of the multi-map is increased, false if the multi-map
	// already contains the key-value pair.
	Put(key interface{}, value interface{}) (increased bool, err error)

	// Get returns a slice of values associated with the specified key.
	// The slice is NOT backed by the map, so changes to the map
	// are NOT reflected in the collection, and vice-versa.
	Get(key interface{}) (values []interface{}, err error)

	// Remove removes an association of the specified value with the specified key. Calling this method does not affect
	// other values associated with the same key.
	// It returns true if the value was detached from the specified key, false if it was not.
	Remove(key interface{}, value interface{}) (removed bool, err error)

	// Delete deletes all the entries with the given key.
	Delete(key interface{}) (err error)

	// RemoveAll detaches all values from the specified key.
	// It returns a slice of old values that were associated with this key prior to this method call.
	// The slice is NOT backed by the map, so changes to the map
	// are NOT reflected in the collection, and vice-versa.
	RemoveAll(key interface{}) (oldValues []interface{}, err error)

	// ContainsKey checks if this multi-map contains a specified key.
	// It returns true if this map contains the specified key, false otherwise.
	ContainsKey(key interface{}) (found bool, err error)

	// ContainsValue returns true if the specified value is associated with at least one key in this multi-map,
	// false otherwise.
	ContainsValue(value interface{}) (found bool, err error)

	// ContainsEntry returns true if this multi-map has an association between
	// the specified key and the specified value, false otherwise.
	ContainsEntry(key interface{}, value interface{}) (found bool, err error)

	// Clear removes all entries from this multi-map.
	Clear() (err error)

	// Size returns the total number of values in this multi-map.
	Size() (size int32, err error)

	// ValueCount returns the number of values associated with the specified key.
	ValueCount(key interface{}) (valueCount int32, err error)

	// Values returns a flat slice of all values stored in this multi-map.
	// The slice is NOT backed by the map, so changes to the map
	// are NOT reflected in the collection, and vice-versa.
	Values() (values []interface{}, err error)

	// KeySet returns a slice of all keys in this multi-map.
	// The slice is NOT backed by the map, so changes to the map
	// are NOT reflected in the collection, and vice-versa.
	KeySet() (keySet []interface{}, err error)

	// EntrySet returns all entries in this multi-map. If a certain key has multiple values associated with it,
	// then one pair will be returned for each value.
	// The slice is NOT backed by the map, so changes to the map
	// are NOT reflected in the collection, and vice-versa.
	EntrySet() (resultPairs []Pair, err error)

	// AddEntryListener adds an entry listener to this multi-map.
	// To receive an event, listener should implement a corresponding interface for that event.
	// Supported listeners for MultiMap:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * MapClearedListener
	// It returns registration ID for this entry listener.
	AddEntryListener(listener interface{}, includeValue bool) (registrationID string, err error)

	// AddEntryListenerToKey adds an entry listener to this multi-map.
	// Supported listeners for MultiMap:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * MapClearedListener
	// This entry listener will only be notified of updates related to this key.
	// It returns registration ID for this entry listener.
	AddEntryListenerToKey(listener interface{}, key interface{}, includeValue bool) (registrationID string, err error)

	// RemoveEntryListener removes the entry listener by the registration ID.
	RemoveEntryListener(registrationID string) (removed bool, err error)

	// Lock acquires a lock for the specified key.
	// If the lock is not available, then
	// the current thread becomes disabled for thread scheduling
	// purposes and lies dormant until the lock has been acquired.
	//
	// The scope of the lock is for this multi-map only.
	// The acquired lock is only for the key in this multi-map.
	//
	// Locks are re-entrant, so if the key is locked N times, then
	// it should be unlocked N times before another thread can acquire it.
	Lock(key interface{}) (err error)

	// LockWithLeaseTime acquires the lock for the specified key for the specified lease time.
	// After the lease time, the lock will be released.
	//
	// If the lock is not available, then
	// the current thread becomes disabled for thread scheduling
	// purposes and lies dormant until the lock has been acquired.
	//
	// Scope of the lock is for this multi-map only.
	// The acquired lock is only for the key in this multi-map.
	//
	// Locks are re-entrant, so if the key is locked N times, then
	// it should be unlocked N times before another thread can acquire it.
	LockWithLeaseTime(key interface{}, lease time.Duration) (err error)

	// IsLocked returns true if this key is locked, false otherwise.
	IsLocked(key interface{}) (locked bool, err error)

	// TryLock tries to acquire the lock for the specified key.
	// If the lock is not available, then the current thread
	// does not wait and the method returns false immediately.
	TryLock(key interface{}) (locked bool, err error)

	// TryLockWithTimeout tries to acquire the lock for the specified key.
	// If the lock is not available, then
	// the current thread becomes disabled for thread scheduling
	// purposes and lies dormant until one of two things happens:
	// the lock is acquired by the current thread, or
	// the specified waiting time elapses.
	TryLockWithTimeout(key interface{}, timeout time.Duration) (locked bool, err error)

	// Tries to acquire the lock for the specified key for the specified lease time.
	// After lease time, the lock will be released.
	//
	// If the lock is not available, then
	// the current thread becomes disabled for thread scheduling
	// purposes and lies dormant until one of two things happens:
	// the lock is acquired by the current thread, or
	// the specified waiting time elapses.
	TryLockWithTimeoutAndLease(key interface{}, timeout time.Duration, lease time.Duration) (locked bool, err error)

	// Unlock unlocks the specified key.
	// It never blocks and returns immediately.
	Unlock(key interface{}) (err error)

	// ForceUnlock forcefully unlocks the specified key, disregarding the acquisition count.
	// This in contrast to the regular unlock, which has to be called the same amount of times as
	// the lock was acquired.
	ForceUnlock(key interface{}) (err error)
}

MultiMap is a specialized map whose keys can be associated with multiple values.

type OverflowPolicy

type OverflowPolicy interface {
	Policy() policy
}

OverflowPolicy is a policy with which one can control the behavior of what should be done when an item is about to be added to the ringbuffer, but there is 0 remaining capacity.

Overflowing happens when a time-to-live is set and the oldest item in the ringbuffer (the head) is not old enough to expire.

type PNCounter

type PNCounter interface {
	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// Get returns the current value of the counter.
	// It returns HazelcastNoDataMemberInClusterError if the cluster does not contain any data members,
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	Get() (currentValue int64, err error)

	// GetAndAdd adds the given value to the current value.
	// It returns the previous value,
	// HazelcastNoDataMemberInClusterError if the cluster does not contain any data members,
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	GetAndAdd(delta int64) (previousValue int64, err error)

	// AddAndGet adds the given value to the current value.
	// It returns the updated value,
	// HazelcastNoDataMemberInClusterError if the cluster does not contain any data members,
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	AddAndGet(delta int64) (updatedValue int64, err error)

	// GetAndSubtract subtracts the given value to the current value.
	// It returns the previous value,
	// HazelcastNoDataMemberInClusterError if the cluster does not contain any data members,
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	GetAndSubtract(delta int64) (previousValue int64, err error)

	// SubtractAndGet subtracts the given value to the current value.
	// It returns the updated value,
	// HazelcastNoDataMemberInClusterError if the cluster does not contain any data members.
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	SubtractAndGet(delta int64) (updatedValue int64, err error)

	// DecrementAndGet decrements by one the current value.
	// It returns the updated value,
	// HazelcastNoDataMemberInClusterError if the cluster does not contain any data members,
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	DecrementAndGet() (updatedValue int64, err error)

	// IncrementAndGet increments by one the current value.
	// It returns the updated value,
	// HazelcastNoDataMemberInClusterError if the cluster does not contain any data members,
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	IncrementAndGet() (updatedValue int64, err error)

	// GetAndDecrement decrements by one the current value.
	// It returns the previous value,
	// HazelcastNoDataMemberInClusterError if the cluster does not contain any data members,
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	GetAndDecrement() (previousValue int64, err error)

	// GetAndIncrement increments by one the current value.
	// It returns the previous value,
	// HazelcastNoDataMemberInClusterError if the cluster does not contain any data members,
	// HazelcastUnsupportedOperationError if the cluster version is less  than 3.10,
	// HazelcastConsistencyLostError if the session guarantees have been lost.
	GetAndIncrement() (previousValue int64, err error)

	// Reset resets the observed state by this PN counter. This method may be used
	// after a method invocation has returned a HazelcastConsistencyLostError
	// to reset the proxy and to be able to start a new session.
	Reset()
}

PNCounter is PN (Positive-Negative) CRDT counter.

The counter supports adding and subtracting values as well as retrieving the current counter value. The counter guarantees that whenever two nodes have received the same set of updates, possibly in a different order, their state is identical, and any conflicting updates are merged automatically. If no new updates are made to the shared state, all nodes that can communicate will eventually have the same data.

The invocation is remote. This may lead to indeterminate state, the update may be applied but the response has not been received. In this case, the caller will be notified with a HazelcastTargetDisconnectedError.

The read and write methods provide monotonic read and RYW (read-your-write) guarantees. These guarantees are session guarantees which means that if no replica with the previously observed state is reachable, the session guarantees are lost and the method invocation will return a HazelcastConsistencyLostError. This does not mean that an update is lost. All of the updates are part of some replica and will be eventually reflected in the state of all other replicas. This error just means that you cannot observe your own writes because all replicas that contain your updates are currently unreachable. After you have received a HazelcastConsistencyLostError, you can either wait for a sufficiently up-to-date replica to become reachable in which case the session can be continued or you can reset the session by calling the Reset() method. If you have called the Reset() method, a new session is started with the next invocation to a CRDT replica.

NOTE: The CRDT state is kept entirely on non-lite (data) members. If there aren't any and the methods here are invoked, they will fail with a HazelcastNoDataMemberInClusterError.

PNCounter requires Hazelcast 3.10.

type Pair

type Pair interface {
	// Key returns key of entry.
	Key() interface{}

	// Values returns value of entry.
	Value() interface{}
}

Pair represents Map entry pair.

type Queue

type Queue interface {
	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// AddAll adds all the items. If items slice changes during this operation, behavior is unspecified.
	// AddAll returns true if the queue has changed, false otherwise.
	AddAll(items []interface{}) (changed bool, err error)

	// AddItemListener adds an item listener for this queue.
	// The listener will be invoked for any add/remove item event.
	// To receive an event, listener should implement a corresponding interface for that event
	// such as ItemAddedListener, ItemRemovedListener.
	// AddItemListener returns the registrationID of the listener.
	AddItemListener(listener interface{}, includeValue bool) (registrationID string, err error)

	// Clear removes all of the items in this queue.
	Clear() (err error)

	// Contains returns true if the given item is in this queue.
	Contains(item interface{}) (found bool, err error)

	// ContainsAll returns true if this queue contains all the given items, false otherwise.
	ContainsAll(items []interface{}) (foundAll bool, err error)

	// DrainTo removes all items in this queue and add them to the end of given slice.
	// DrainTo returns the number of moved items.
	DrainTo(slice *[]interface{}) (movedAmount int32, err error)

	// DrainToWithMaxSize removes all items in this queue and add them to the end of given slice.
	// DrainToWithMaxSize returns the number of moved items.
	DrainToWithMaxSize(slice *[]interface{}, maxElements int32) (movedAmount int32, err error)

	// IsEmpty returns true if this queue is empty, false otherwise.
	IsEmpty() (empty bool, err error)

	// Offer inserts the given item to the end of the queue if there is room.
	// If queue is full, offer operation fails.
	// Offer returns true if the item is added, false otherwise.
	Offer(item interface{}) (added bool, err error)

	// OfferWithTimeout inserts the given item to the end of the queue if there is room, otherwise
	// it waits for timeout with timeoutUnit before returning false.
	// OfferWithTimeout returns true if the item is added, false otherwise.
	OfferWithTimeout(item interface{}, timeout time.Duration) (added bool, err error)

	// Peek retrieves, but does not remove the head of this queue.
	// Peek returns the head of this queue, nil if the queue is empty.
	Peek() (item interface{}, err error)

	// Poll retrieves and removes the head of this queue.
	// Poll returns the head of this queue, nil if the queue is empty.
	Poll() (item interface{}, err error)

	// PollWithTimeout retrieves and removes the head of this queue,
	// if the queue is empty it waits timeout with timeoutUnit before returning nil.
	// PollWithTimeout returns the head of this queue, nil if the queue is empty after timeoutInMilliSeconds milliseconds.
	PollWithTimeout(timeout time.Duration) (item interface{}, err error)

	// Put inserts the item at the end of this queue.
	// Put blocks until there is available room in the queue, if necessary.
	Put(item interface{}) (err error)

	// RemainingCapacity returns the number of additional items this queue can contain.
	RemainingCapacity() (remainingCapacity int32, err error)

	// Remove removes an instance of given item from this queue.
	// Remove returns true if the item is removed, false otherwise.
	Remove(item interface{}) (removed bool, err error)

	// RemoveAll removes all items from this queue.
	// RemoveAll returns true if the queue has changed, false otherwise.
	RemoveAll(items []interface{}) (changed bool, err error)

	// RemoveItemListener removes the item listener with the given registrationID from this queue.
	// RemoveItemListener returns true if the listener is removed, false otherwise.
	RemoveItemListener(registrationID string) (removed bool, err error)

	// RetainAll removes all the items from this queue except the 'items'
	// RetainAll returns true if this queue has changed, false otherwise.
	RetainAll(items []interface{}) (changed bool, err error)

	// Size returns the number of elements in this queue.
	Size() (size int32, err error)

	// Take retrieves and removes the head of this queue. It waits to return until
	// an element becomes available if necessary.
	Take() (item interface{}, err error)

	// ToSlice returns all the items in this queue in proper sequence.
	ToSlice() (items []interface{}, err error)
}

Queue is a concurrent, blocking, distributed, observable queue. Queue is not a partitioned data-structure. All of the Queue content is stored in a single machine (and in the backup). Queue will not scale by adding more members in the cluster.

type RandomLoadBalancer

type RandomLoadBalancer struct {
	// contains filtered or unexported fields
}

RandomLoadBalancer is a loadbalancer that selects members randomly from the given cluster service.

func NewRandomLoadBalancer

func NewRandomLoadBalancer() *RandomLoadBalancer

NewRandomLoadBalancer creates and returns a RandomLoadBalancer.

func (*RandomLoadBalancer) Init

func (b *RandomLoadBalancer) Init(cluster Cluster)

func (*RandomLoadBalancer) Next

func (b *RandomLoadBalancer) Next() Member

type ReadResultSet

type ReadResultSet interface {
	// ReadCount returns the number of items that have been read before filtering.
	// If no filter is set, then the readCount will be the same as size. But if a filter is applied, it could be that items
	// are read, but are filtered out. So if you are trying to make another read based on the ReadResultSet then you should
	// increment the sequence by readCount and not by size. Otherwise you will be re-reading the same filtered messages.
	ReadCount() (readCount int32)

	// Get returns the item at the given index.
	Get(index int32) (item interface{}, err error)

	// Sequence returns the sequence number for the item at the given index.
	// A return value of -1 means that the information is not available.
	Sequence(index int32) (sequence int64, err error)

	// Size returns the result set size.
	Size() (size int32)
}

ReadResultSet is the result of a Ringbuffer ReadMany operation.

type ReliableMessageListener

type ReliableMessageListener interface {
	MessageListener

	// RetrieveInitialSequence retrieves the initial sequence from which this ReliableMessageListener should start.
	//
	// Return -1 if there is no initial sequence and you want to start from the next published message.
	//
	// If you intent to create a durable subscriber so you continue from where you stopped the previous
	// time, load the previous sequence and add 1. If you don't add one, then you will be receiving the
	// same message twice.
	RetrieveInitialSequence() int64
	// StoreSequence informs the ReliableMessageListener that it should store the sequence.
	// This method is called before the message is
	// processed. Can be used to make a durable subscription.
	StoreSequence(sequence int64)

	// IsLossTolerant checks if this ReliableMessageListener is able to deal with message loss.
	// Even though the reliable topic promises to
	// be reliable, it can be that a MessageListener is too slow. Eventually the message won't be available anymore.
	//
	// If the ReliableMessageListener is not loss tolerant and the topic detects that there are missing messages, it will
	// terminate the ReliableMessageListener.
	IsLossTolerant() bool

	// IsTerminal checks if the ReliableMessageListener should be terminated based on an error returned while calling
	// MessageListener.OnMessage().
	IsTerminal(err error) (bool, error)
}

ReliableMessageListener is to better integrate with the reliable topic.

If a regular MessageListener is registered on a reliable topic, the message listener works fine, but it can't do much more than listen to messages.

If a ReliableMessageListener is registered on a normal topic, only the MessageListener methods will be called.

Durable Subscription

The ReliableMessageListener allows you to control where you want to start processing a message when the listener is registered. This makes it possible to create a durable subscription by storing the sequence of the last message and using this sequenceId as the sequenceId to start from.

Error handling

The ReliableMessageListener also gives the ability to deal with errors using the IsTerminal(error) method. If a plain MessageListener is used, then it won't terminate on errors and it will keep on running. But in some cases it is better to stop running.

Global order

The ReliableMessageListener will always get all events in order (global order). It will not get duplicates and there will only be gaps if it is too slow. For more information see IsLossTolerant().

Delivery guarantees

Because the ReliableMessageListener controls which item it wants to continue from upon restart, it is very easy to provide an at-least-once or at-most-once delivery guarantee. The storeSequence is always called before a message is processed; so it can be persisted on some non-volatile storage. When the RetrieveInitialSequence returns the stored sequence, then an at-least-once delivery is implemented since the same item is now being processed twice. To implement an at-most-once delivery guarantee, add 1 to the stored sequence when the RetrieveInitialSequence is called.

type ReplicatedMap

type ReplicatedMap interface {
	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// Put associates a given value to the specified key and replicates it to the
	// cluster. If there is an old value, it will be replaced by the specified
	// one and returned from the call.
	//
	// It returns a clone of the previous value,
	// not the original (identically equal) value previously put into the map.
	Put(key interface{}, value interface{}) (oldValue interface{}, err error)

	// PutWithTTL associates a given value to the specified key and replicates it to the
	// cluster. If there is an old value, it will be replaced by the specified
	// one and returned from the call. In addition, you have to specify a ttl and its time unit
	// to define when the value is outdated and thus should be removed from the
	// replicated map.
	//
	// It returns a clone of the previous value,
	// not the original (identically equal) value previously put into the map.
	PutWithTTL(key interface{}, value interface{}, ttl time.Duration) (oldValue interface{}, err error)

	// PutAll copies all of the mappings from the specified map to this map.
	// The effect of this call is equivalent to that of calling put(k, v)
	// on this map once for each mapping from key k to value v in the specified
	// map. The behavior of this operation is undefined if the specified map is modified
	// while the operation is in progress.
	//
	// Any change in the returned map will not be reflected on server side.
	PutAll(entries map[interface{}]interface{}) (err error)

	// Get returns the value to which the specified key is mapped, or nil if this map
	// contains no mapping for the key. If this map permits nil values, then a return value of nil does not
	// necessarily indicate that the map contains no mapping for the key; it's also
	// possible that the map explicitly maps the key to nil.
	//
	// It returns a clone of the value,
	// not the original (identically equal) value put into the map.
	Get(key interface{}) (value interface{}, err error)

	// ContainsKey returns true if this map contains a mapping for the specified key.
	ContainsKey(key interface{}) (found bool, err error)

	// ContainsValue returns true if this map maps one or more keys to the specified value.
	ContainsValue(value interface{}) (found bool, err error)

	// Clear wipes data out of the replicated maps.
	// If some node fails on executing the operation, it is retried for at most
	// 5 times (on the failing nodes only).
	Clear() (err error)

	// Remove removes the mapping for a key from this map if it is present (optional operation).
	// Remove returns the value to which this map previously associated the key,
	// or nil if the map contained no mapping for the key. If this map permits nil values,
	// then a return value of nil does not necessarily indicate that the map contained
	// no mapping for the key; it's also possible that the map explicitly mapped the key to nil.
	// The map will not contain a mapping for the specified key once the call returns.
	Remove(key interface{}) (value interface{}, err error)

	// IsEmpty returns true if this map has no entries, false otherwise.
	IsEmpty() (empty bool, err error)

	// Size returns the number of key-value mappings in this map.
	Size() (size int32, err error)

	// Values returns a slice of values contained in this map.
	Values() (values []interface{}, err error)

	// KeySet returns a view of the key contained in this map.
	KeySet() (keySet []interface{}, err error)

	// EntrySet returns entries as a slice of key-value pairs.
	EntrySet() (resultPairs []Pair, err error)

	// AddEntryListener adds an entry listener for this map. The listener will be notified for all
	// map add/remove/update/evict events.
	// To receive an event, listener should implement a corresponding interface for that event.
	// Supported listeners for ReplicatedMap:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * EntryUpdatedListener
	//  * EntryEvictedListener
	//  * MapClearedListener
	// AddEntryListener returns registration id of the listener.
	AddEntryListener(listener interface{}) (registrationID string, err error)

	// AddEntryListenerWithPredicate adds a continuous entry listener for this map. The listener will be notified for
	// map add/remove/update/evict events filtered by the given predicate.
	// To receive an event, listener should implement a corresponding interface for that event.
	// Supported listeners for ReplicatedMap:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * EntryUpdatedListener
	//  * EntryEvictedListener
	//  * MapClearedListener
	// AddEntryListenerWithPredicate returns registration id of the listener.
	AddEntryListenerWithPredicate(listener interface{}, predicate interface{}) (registrationID string, err error)

	// AddEntryListenerToKey adds the specified entry listener for the specified key. The listener will be
	// notified for all add/remove/update/evict events of the specified key only.
	// To receive an event, listener should implement a corresponding interface for that event.
	// Supported listeners for ReplicatedMap:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * EntryUpdatedListener
	//  * EntryEvictedListener
	//  * MapClearedListener
	// AddEntryListenerToKey returns registration id of the listener.
	AddEntryListenerToKey(listener interface{}, key interface{}) (registrationID string, err error)

	// AddEntryListenerToKeyWithPredicate adds a continuous entry listener for this map. The listener will be notified for
	// map add/remove/update/evict events filtered by the given predicate and key.
	// To receive an event, listener should implement a corresponding interface for that event.
	// Supported listeners for ReplicatedMap:
	//  * EntryAddedListener
	//  * EntryRemovedListener
	//  * EntryUpdatedListener
	//  * EntryEvictedListener
	//  * MapClearedListener
	// AddEntryListenerToKeyWithPredicate returns registration id of the listener.
	AddEntryListenerToKeyWithPredicate(listener interface{}, predicate interface{}, key interface{}) (
		registrationID string, err error)

	// RemoveEntryListener removes the specified entry listener and returns silently if there was no such
	// listener added before.
	// It returns true if remove operation is successful, false if unsuccessful or this listener did not exist.
	RemoveEntryListener(registrationID string) (removed bool, err error)
}

ReplicatedMap is a map-like data structure with weak consistency and values locally stored on every node of the cluster.

Whenever a value is written asynchronously, the new value will be internally distributed to all existing cluster members, and eventually every node will have the new value.

When a new node joins the cluster, the new node initially will request existing values from older nodes and replicate them locally.

type Ringbuffer

type Ringbuffer interface {
	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// Capacity returns capacity of this ringbuffer.
	Capacity() (capacity int64, err error)

	// Size returns number of items in the ringbuffer.
	// If no ttl is set, the size will always be equal to capacity after the head completed the first loop around the ring.
	// This is because no items are getting retired.
	Size() (size int64, err error)

	// TailSequence returns the sequence of the tail. The tail is the side of the ringbuffer where the items are added to.
	// The initial value of the tail is -1 if the ringbuffer is not backed by a store, otherwise tail sequence will be set to
	// the sequence of the previously last stored item.
	TailSequence() (tailSequence int64, err error)

	// HeadSequence returns the head sequence. The head is the side of the ringbuffer where the oldest items are found.
	// If the ringbuffer is empty, the head will be one more than the tail.
	// The initial value of the head is 0.
	HeadSequence() (headSequence int64, err error)

	// RemainingCapacity returns the remaining capacity of the ringbuffer.
	// The returned value could be stale as soon as it is returned.
	// If ttl is not set, the remaining capacity will always be the capacity.
	RemainingCapacity() (remainingCapacity int64, err error)

	// Add adds an item to the tail of this ringbuffer. Overflow policy determines what will happen,
	// if there is no space left in this ringbuffer. If OverflowPolicyOverwrite was passed,
	// the new item will overwrite the oldest one regardless of the configured time-to-live.
	//
	// In the case when OverflowPolicyFail was specified, the add operation will keep failing until an oldest item in this
	// ringbuffer will reach its time-to-live.
	//
	// Add returns the sequence number of the added item. You can read the added item using this number.
	Add(item interface{}, overflowPolicy OverflowPolicy) (sequence int64, err error)

	// AddAll adds all items in the specified slice to the tail of this buffer. The behavior of this method is essentially
	// the same as the one of the add method.
	//
	// The method does not guarantee that the inserted items will have contiguous sequence numbers.
	AddAll(items []interface{}, overflowPolicy OverflowPolicy) (lastSequence int64, err error)

	// ReadOne reads a single item from this ringbuffer.
	// If the sequence is equal to the current tail sequence plus one,
	// this call will not return a response until an item is added.
	// If it is more than that, an error will be returned.
	//
	// Unlike queue's take, this method does not remove an item from the ringbuffer. This means that the same item
	// can be read by multiple processes.
	ReadOne(sequence int64) (item interface{}, err error)

	// ReadMany reads a batch of items from this ringbuffer.
	// If the number of available items starting at sequence is smaller than maxCount,
	// then this method will not wait for more items to arrive.
	// Instead, available items will be returned.
	//
	// If there are less items available than minCount, then this call will not return a response until
	// a necessary number of items becomes available.
	ReadMany(startSequence int64, minCount int32, maxCount int32, filter interface{}) (readResultSet ReadResultSet, err error)
}

Ringbuffer is a data-structure where the content is stored in a ring like structure. A ringbuffer has a capacity so it won't grow beyond that capacity and endanger the stability of the system. If that capacity is exceeded, than the oldest item in the ringbuffer is overwritten.

The ringbuffer has 2 always incrementing sequences:

  • tailSequence: This is the side where the youngest item is found. So the tail is the side of the ringbuffer where items are added to.
  • headSequence: This is the side where the oldest items are found. So the head is the side where items gets discarded.

The items in the ringbuffer can be found by a sequence that is in between (inclusive) the head and tail sequence. If data is read from a ringbuffer with a sequence that is smaller than the headSequence, it means that the data is not available anymore.

type RoundRobinLoadBalancer

type RoundRobinLoadBalancer struct {
	// contains filtered or unexported fields
}

RoundRobinLoadBalancer is a loadbalancer where members are used with round robin logic.

func NewRoundRobinLoadBalancer

func NewRoundRobinLoadBalancer() *RoundRobinLoadBalancer

NewRoundRobinLoadBalancer creates and returns a RoundLobinLoadBalancer.

func (*RoundRobinLoadBalancer) Init

func (rrl *RoundRobinLoadBalancer) Init(cluster Cluster)

func (*RoundRobinLoadBalancer) Next

func (rrl *RoundRobinLoadBalancer) Next() Member

type ServerError

type ServerError interface {
	// ErrorCode returns the error code.
	ErrorCode() int32

	// ClassName returns the class name where error occurred.
	ClassName() string

	// Message returns the error message.
	Message() string

	// StackTrace returns a slice of StackTraceElement.
	StackTrace() []StackTraceElement

	// CauseErrorCode returns the cause error code.
	CauseErrorCode() int32

	// CauseClassName returns the cause class name.
	CauseClassName() string
}

ServerError contains error information that occurred in the server.

type Set

type Set interface {
	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// Add adds the specified item to this set if not already present.
	// Add returns true if the item was added, false otherwise.
	Add(item interface{}) (added bool, err error)

	// AddAll adds the items to this set if not already present.
	// AddAll returns true if this set has changed, false otherwise.
	AddAll(items []interface{}) (changed bool, err error)

	// AddItemListener adds an item listener for this set.
	// To receive an event, listener should implement a corresponding interface for that event
	// such as ItemAddedListener, ItemRemovedListener.
	// AddItemListener returns the registrationID of the listener.
	AddItemListener(listener interface{}, includeValue bool) (registrationID string, err error)

	// Clear removes all of the elements from this set.
	Clear() (err error)

	// Contains returns true if the specified item is found in the set.
	Contains(item interface{}) (found bool, err error)

	// ContainsAll returns true if all of the specified items are found in the set.
	ContainsAll(items []interface{}) (foundAll bool, err error)

	// IsEmpty returns true if the set does not have any items, false otherwise.
	IsEmpty() (empty bool, err error)

	// Remove removes the given item from this set.
	// Remove returns true if the given item is removed, false otherwise.
	Remove(item interface{}) (removed bool, err error)

	// RemoveAll removes all the items from this set.
	// RemoveAll returns true if the set has changed, false otherwise.
	RemoveAll(items []interface{}) (changed bool, err error)

	// RetainAll removes all the items from the set except the ones given in the slide.
	// RetainAll returns true if the given list has changed, false otherwise.
	RetainAll(items []interface{}) (changed bool, err error)

	// Size returns the size of this set.
	Size() (size int32, err error)

	// RemoveItemListener removes the listener with the given registrationID.
	// RemoveItemListener returns true if the listener is removed, false otherwise.
	RemoveItemListener(registrationID string) (removed bool, err error)

	// ToSlice returns all the items in this set in proper sequence.
	ToSlice() (items []interface{}, err error)
}

Set is the concurrent, distributed implementation of collection that contains no duplicate elements. As implied by its name, this interface models the mathematical 'set' abstraction.

type StackTraceElement

type StackTraceElement interface {
	// DeclaringClass returns the fully qualified name of the class containing
	// the execution point represented by the stack trace element.
	DeclaringClass() string

	// MethodName returns the name of the method containing the execution point
	// represented by this stack trace element.
	MethodName() string

	// FileName returns the name of the file containing the execution point
	// represented by the stack trace element, or nil if
	// this information is unavailable.
	FileName() string

	// LineNumber returns the line number of the source line containing the
	// execution point represented by this stack trace element, or
	// a negative number if this information is unavailable. A value
	// of -2 indicates that the method containing the execution point
	// is a native method.
	LineNumber() int32
}

StackTraceElement contains stacktrace information for server side exception.

type Topic

type Topic interface {
	// DistributedObject is the base interface for all distributed objects.
	DistributedObject

	// AddMessageListener subscribes to this topic. When someone publishes a message on this topic.
	// OnMessage() function of the given messageListener is called. More than one message listener can be
	// added on one instance.
	// AddMessageListener returns registrationID of the listener.
	AddMessageListener(messageListener MessageListener) (registrationID string, err error)

	// RemoveMessageListener stops receiving messages for the listener with the given registrationID.
	// If the listener is already removed, this method does nothing.
	// RemoveMessageListener returns true if the listener with the given registrationID is removed.
	RemoveMessageListener(registrationID string) (removed bool, err error)

	// Publish publishes the message to all subscribers of this topic.
	Publish(message interface{}) (err error)
}

Topic is a distribution mechanism for publishing messages that are delivered to multiple subscribers, which is also known as a publish/subscribe (pub/sub) messaging model. Publish and subscriptions are cluster-wide. When a member subscribes for a topic, it is actually registering for messages published by any member in the cluster, including the new members joined after you added the listener.

Messages are ordered, meaning that listeners(subscribers) will process the messages in the order they are actually published.

type TopicOverloadPolicy

type TopicOverloadPolicy int

TopicOverloadPolicy is a policy to deal with an overloaded topic; so topic where there is no place to store new messages.

This policy can only be used in combination with the ReliableTopic.

The reliable topic uses a Ringbuffer to store the messages. A ringbuffer doesn't track where readers are, so therefore it has no concept of a slow consumers. This provides many advantages like high performance reads, but it also gives the ability to the reader to reread the same message multiple times in case of error.

Because a ringbuffer has a capacity and to prevent that a fast producer overwrites the messages needed by a slow consumer, a time to live time can be set on the ringbuffer in server configuration. This policy controls how the publisher is going to deal with the situation that a ringbuffer is full

and the oldest item in the ringbuffer is not old enough to get overwritten.

So keep in mind that this retention period keeps the messages in memory, even though it might be that all readers already have completed reading.

const (
	// TopicOverLoadPolicyDiscardOldest is a policy so that a message that has not expired can be overwritten.
	// No matter the retention period set, the overwrite will just overwrite the item.
	//
	// This can be a problem for slow consumers because they were promised a certain time window to process messages. But it will
	// benefit producers and fast consumers since they are able to continue. This policy sacrifices the slow producer in favor
	// of fast producers/consumers.
	TopicOverLoadPolicyDiscardOldest TopicOverloadPolicy = iota

	// TopicOverLoadPolicyDiscardNewest is a policy which discards a message that was to be published.
	TopicOverLoadPolicyDiscardNewest

	// TopicOverLoadPolicyBlock is a policy to block until there is a space in the ringbuffer.
	TopicOverLoadPolicyBlock

	// TopicOverLoadPolicyError is a policy so that the publish call fails immediately when there is no space.
	TopicOverLoadPolicyError
)

Directories

Path Synopsis
Package aggregator is a utility package to create basic aggregators.
Package aggregator is a utility package to create basic aggregators.
Package predicate is a utility package to create predicate.
Package predicate is a utility package to create predicate.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL