-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.go
56 lines (49 loc) · 2.02 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Code generated by atomix-go-framework. DO NOT EDIT.
package set
import (
"context"
set "github.com/atomix/atomix-api/go/atomix/primitive/set"
"github.com/atomix/atomix-go-framework/pkg/atomix/logging"
"github.com/atomix/atomix-go-framework/pkg/atomix/storage/protocol/gossip"
"github.com/atomix/atomix-go-framework/pkg/atomix/time"
)
var log = logging.GetLogger("atomix", "protocol", "gossip", "set")
const ServiceType gossip.ServiceType = "Set"
// RegisterService registers the service on the given node
func RegisterService(node *gossip.Node) {
node.RegisterService(ServiceType, func(ctx context.Context, serviceID gossip.ServiceId, partition *gossip.Partition, clock time.Clock, replicas int) (gossip.Service, error) {
protocol, err := newGossipProtocol(serviceID, partition, clock, replicas)
if err != nil {
return nil, err
}
service, err := newService(protocol)
if err != nil {
return nil, err
}
engine := newGossipEngine(protocol)
go engine.start()
return service, nil
})
}
var newService func(protocol GossipProtocol) (Service, error)
func registerService(f func(protocol GossipProtocol) (Service, error)) {
newService = f
}
type Service interface {
gossip.Service
Protocol() GossipProtocol
// Size gets the number of elements in the set
Size(context.Context, *set.SizeRequest) (*set.SizeResponse, error)
// Contains returns whether the set contains a value
Contains(context.Context, *set.ContainsRequest) (*set.ContainsResponse, error)
// Add adds a value to the set
Add(context.Context, *set.AddRequest) (*set.AddResponse, error)
// Remove removes a value from the set
Remove(context.Context, *set.RemoveRequest) (*set.RemoveResponse, error)
// Clear removes all values from the set
Clear(context.Context, *set.ClearRequest) (*set.ClearResponse, error)
// Events listens for set change events
Events(context.Context, *set.EventsRequest, chan<- set.EventsResponse) error
// Elements lists all elements in the set
Elements(context.Context, *set.ElementsRequest, chan<- set.ElementsResponse) error
}