hitcounter

package
v0.0.0-...-38a89e1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2015 License: MIT Imports: 6 Imported by: 4

Documentation

Overview

Package hitcounter augments the message-server with a store to track hits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockedValue

type BlockedValue struct {
	Since float64
	Value interface{}
}

BlockedValue is a value that is blocked by the system.

type Clock

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

Clock represents an integer clock that starts at 0.

func NewClock

func NewClock() *Clock

NewClock returns an initialized and started *Clock.

func (*Clock) GetTime

func (c *Clock) GetTime() int32

GetTime returns the number of seconds that have passed since intiialization.

type Direction

type Direction struct {
	Store       *store.ShardMap
	Name        string
	CleanUpTime float64
	MaxHits     float64
	WindowSize  float64
}

Direction is a tracked resource. See package config for definition of its member variables.

func (*Direction) BlockedValues

func (d *Direction) BlockedValues() []BlockedValue

Returns the list of all values in the map that have IsBlocked == true.

func (*Direction) Hit

func (d *Direction) Hit(clock int32, val interface{}) bool

Hit registers a used value.

type HitCounter

type HitCounter struct {
	Clock      *Clock
	Count      *RunningCount
	Directions map[string]*Direction
	Logger     *logger.Logger
}

HitCounter is a server that tracks several directions.

func NewHitCounter

func NewHitCounter(directions []Direction, l *logger.Logger) *HitCounter

NewHitCounter returns an initialized *HitCounter.

func (*HitCounter) HandleRequest

func (h *HitCounter) HandleRequest(direction string, value interface{}) bool

type RunningCount

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

RunningCount is a counter where every increment is temporary. After the duration has passed, the counter decrements.

func NewRunningCount

func NewRunningCount(Granularity int, Duration time.Duration) *RunningCount

NewRunningCount returns an initialized *RunningCount.

func (*RunningCount) Count

func (r *RunningCount) Count() uint64

Count returns the current count.

func (*RunningCount) Inc

func (r *RunningCount) Inc()

Inc increments the count by 1. This increment will expire after the RunningCount's duration.

Jump to

Keyboard shortcuts

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