percounter

package module
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MPL-2.0 Imports: 15 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

percounter

an amateur-ish persistent distributed G-Counter (grow-only counter)

see tests for usage:

initially created to be used in mermaidlive

Documentation

Index

Constants

View Source
const GCounterNetworkMessage = "g-counter.network.message"
View Source
const MyIPKey = "my_ip"
View Source
const MyTcpPortKey = "my_tcp_port"
View Source
const PeerHelloNetworkMessage = "peer.hello.network.message"
View Source
const PeerOhaiNetworkMessage = "peer.ohai.network.message"

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncGCounter

type AsyncGCounter struct {
	phony.Inbox
	// contains filtered or unexported fields
}

func NewAsyncGCounter

func NewAsyncGCounter(identity string) *AsyncGCounter

func NewAsyncGCounterWithSink

func NewAsyncGCounterWithSink(identity string, sink GCounterStateSink) *AsyncGCounter

func NewAsyncGCounterWithSinkFromState

func NewAsyncGCounterWithSinkFromState(identity string, state GCounterState, sink GCounterStateSink) *AsyncGCounter

func (*AsyncGCounter) GetState

func (c *AsyncGCounter) GetState() GCounterState

func (*AsyncGCounter) Increment

func (c *AsyncGCounter) Increment()

func (*AsyncGCounter) MergeWith

func (c *AsyncGCounter) MergeWith(other GCounterStateSource)

func (*AsyncGCounter) Value

func (c *AsyncGCounter) Value() int64

type ClusterObserver added in v0.0.12

type ClusterObserver interface {
	AfterMessageSent(peer string, msg []byte)
	AfterMessageReceived(peer string, msg []byte)
}

type CountEvent added in v0.0.6

type CountEvent struct {
	Name  string
	Count int64
}

type CounterObserver added in v0.0.3

type CounterObserver interface {
	OnNewCount(ev CountEvent)
}

type EmergencyPersistence added in v0.0.12

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

func GlobalEmergencyPersistence added in v0.0.12

func GlobalEmergencyPersistence() *EmergencyPersistence

func (*EmergencyPersistence) AddForPersistence added in v0.0.12

func (s *EmergencyPersistence) AddForPersistence(p Persistent)

func (*EmergencyPersistence) Init added in v0.0.12

func (s *EmergencyPersistence) Init()

func (*EmergencyPersistence) PersistAndExitOnSignal added in v0.0.12

func (s *EmergencyPersistence) PersistAndExitOnSignal()

type GCounter

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

func NewGCounter

func NewGCounter(identity string) *GCounter

func NewGCounterFromState

func NewGCounterFromState(identity string, state GCounterState) *GCounter

func (*GCounter) GetState

func (c *GCounter) GetState() GCounterState

func (*GCounter) Increment

func (c *GCounter) Increment()

func (*GCounter) MergeWith

func (c *GCounter) MergeWith(other GCounterStateSource)

func (*GCounter) Value

func (c *GCounter) Value() int64

type GCounterState

type GCounterState struct {
	Name  string           `json:"name"`
	Peers map[string]int64 `json:"peers"`
}

func NewGcounterState

func NewGcounterState() GCounterState

func NewNamedGcounterState added in v0.0.5

func NewNamedGcounterState(name string) GCounterState

func (GCounterState) Copy added in v0.0.7

func (s GCounterState) Copy() GCounterState

type GCounterStateSink

type GCounterStateSink interface {
	SetState(s GCounterState)
}

type GCounterStateSource

type GCounterStateSource interface {
	GetState() GCounterState
}

type Incrementable added in v0.0.2

type Incrementable interface {
	Increment()
}

type NetworkedGCounterState added in v0.0.12

type NetworkedGCounterState struct {
	Type       string                 `json:"type"`
	SourcePeer string                 `json:"source_peer"`
	Name       string                 `json:"name"`
	Peers      map[string]int64       `json:"peers"`
	Metadata   map[string]interface{} `json:"metadata"`
}

type Persistent added in v0.0.12

type Persistent interface {
	PersistSync()
}

type PersistentGCounter

type PersistentGCounter struct {
	phony.Inbox
	// contains filtered or unexported fields
}

func NewPersistentGCounter

func NewPersistentGCounter(identity, filename string) *PersistentGCounter

func NewPersistentGCounterWithSink

func NewPersistentGCounterWithSink(identity, filename string, sink GCounterStateSink) *PersistentGCounter

func NewPersistentGCounterWithSinkAndObserver added in v0.0.3

func NewPersistentGCounterWithSinkAndObserver(identity, filename string, sink GCounterStateSink, observer CounterObserver) *PersistentGCounter

func (*PersistentGCounter) GetState

func (c *PersistentGCounter) GetState() GCounterState

func (*PersistentGCounter) Increment

func (c *PersistentGCounter) Increment()

func (*PersistentGCounter) IncrementFromActor added in v0.0.7

func (c *PersistentGCounter) IncrementFromActor(anotherActor phony.Actor)

func (*PersistentGCounter) MergeWith

func (c *PersistentGCounter) MergeWith(other GCounterStateSource)

func (*PersistentGCounter) PersistSync

func (c *PersistentGCounter) PersistSync()

func (*PersistentGCounter) Value

func (c *PersistentGCounter) Value() int64

type QueryableCounter added in v0.0.2

type QueryableCounter interface {
	Incrementable
	ValueSource
}

type ValueSource

type ValueSource interface {
	Value() int64
}

type ZmqMultiGcounter added in v0.0.5

type ZmqMultiGcounter struct {
	phony.Inbox
	// contains filtered or unexported fields
}

func NewObservableZmqMultiGcounter added in v0.0.5

func NewObservableZmqMultiGcounter(identity, dirname, bindAddr string, observer CounterObserver) *ZmqMultiGcounter

func NewObservableZmqMultiGcounterInCluster added in v0.0.7

func NewObservableZmqMultiGcounterInCluster(identity, dirname string, cluster zmqcluster.Cluster, observer CounterObserver) *ZmqMultiGcounter

func NewZmqMultiGcounter added in v0.0.5

func NewZmqMultiGcounter(identity, dirname, bindAddr string) *ZmqMultiGcounter

func NewZmqMultiGcounterInCluster added in v0.0.7

func NewZmqMultiGcounterInCluster(identity, dirname string, cluster zmqcluster.Cluster) *ZmqMultiGcounter

func (*ZmqMultiGcounter) GetCounter added in v0.0.5

func (c *ZmqMultiGcounter) GetCounter(name string) *PersistentGCounter

func (*ZmqMultiGcounter) Increment added in v0.0.5

func (z *ZmqMultiGcounter) Increment(name string)

func (*ZmqMultiGcounter) LoadAllSync added in v0.0.11

func (z *ZmqMultiGcounter) LoadAllSync() error

func (*ZmqMultiGcounter) MergeWith added in v0.0.5

func (c *ZmqMultiGcounter) MergeWith(other GCounterStateSource)

func (*ZmqMultiGcounter) OnMessage added in v0.0.7

func (z *ZmqMultiGcounter) OnMessage(identity []byte, message []byte)

func (*ZmqMultiGcounter) OnMessageSent added in v0.0.26

func (z *ZmqMultiGcounter) OnMessageSent(peer string, message []byte)

func (*ZmqMultiGcounter) OnNewPeerConnected added in v0.0.7

func (z *ZmqMultiGcounter) OnNewPeerConnected(c zmqcluster.Cluster, peer string)

func (*ZmqMultiGcounter) PersistOneSync added in v0.0.5

func (c *ZmqMultiGcounter) PersistOneSync(name string)

func (*ZmqMultiGcounter) PersistSync added in v0.0.5

func (c *ZmqMultiGcounter) PersistSync()

func (*ZmqMultiGcounter) SetClusterObserver added in v0.0.12

func (z *ZmqMultiGcounter) SetClusterObserver(o ClusterObserver)

func (*ZmqMultiGcounter) SetState added in v0.0.5

func (z *ZmqMultiGcounter) SetState(s GCounterState)

callback once the inner counter state is changed

func (*ZmqMultiGcounter) ShouldPersistOnSignal added in v0.0.14

func (z *ZmqMultiGcounter) ShouldPersistOnSignal()

func (*ZmqMultiGcounter) Start added in v0.0.5

func (z *ZmqMultiGcounter) Start() error

func (*ZmqMultiGcounter) Stop added in v0.0.5

func (z *ZmqMultiGcounter) Stop()

func (*ZmqMultiGcounter) UpdatePeers added in v0.0.5

func (z *ZmqMultiGcounter) UpdatePeers(peers []string)

func (*ZmqMultiGcounter) Value added in v0.0.5

func (c *ZmqMultiGcounter) Value(name string) int64

type ZmqSingleGcounter

type ZmqSingleGcounter struct {
	phony.Inbox
	// contains filtered or unexported fields
}

func NewObservableZmqSingleGcounter added in v0.0.4

func NewObservableZmqSingleGcounter(identity, filename, bindAddr string, observer CounterObserver) *ZmqSingleGcounter

func NewZmqSingleGcounter

func NewZmqSingleGcounter(identity, filename, bindAddr string) *ZmqSingleGcounter

func NewZmqSingleGcounterInCluster added in v0.0.7

func NewZmqSingleGcounterInCluster(identity, filename string, cluster zmqcluster.Cluster) *ZmqSingleGcounter

func (*ZmqSingleGcounter) Increment

func (z *ZmqSingleGcounter) Increment()

func (*ZmqSingleGcounter) MergeWith

func (c *ZmqSingleGcounter) MergeWith(other GCounterStateSource)

func (*ZmqSingleGcounter) OnMessage added in v0.0.7

func (z *ZmqSingleGcounter) OnMessage(_ []byte, message []byte)

func (*ZmqSingleGcounter) OnMessageSent added in v0.0.26

func (z *ZmqSingleGcounter) OnMessageSent(peer string, message []byte)

func (*ZmqSingleGcounter) OnNewPeerConnected added in v0.0.7

func (z *ZmqSingleGcounter) OnNewPeerConnected(c zmqcluster.Cluster, peer string)

func (*ZmqSingleGcounter) PersistSync

func (c *ZmqSingleGcounter) PersistSync()

func (*ZmqSingleGcounter) SetState

func (z *ZmqSingleGcounter) SetState(s GCounterState)

callback once the inner counter state is changed

func (*ZmqSingleGcounter) Start

func (z *ZmqSingleGcounter) Start() error

func (*ZmqSingleGcounter) Stop

func (z *ZmqSingleGcounter) Stop()

func (*ZmqSingleGcounter) UpdatePeers

func (z *ZmqSingleGcounter) UpdatePeers(peers []string)

func (*ZmqSingleGcounter) Value

func (c *ZmqSingleGcounter) Value() int64

Directories

Path Synopsis
cmd
signals_demo command

Jump to

Keyboard shortcuts

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