-
Notifications
You must be signed in to change notification settings - Fork 7
/
service.go
49 lines (42 loc) · 1.66 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
// Code generated by atomix-go-framework. DO NOT EDIT.
package counter
import (
"context"
counter "github.com/atomix/atomix-api/go/atomix/primitive/counter"
"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", "counter")
const ServiceType gossip.ServiceType = "Counter"
// 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) (gossip.Service, error) {
protocol, err := newGossipProtocol(serviceID, partition, clock)
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
// Set sets the counter value
Set(context.Context, *counter.SetRequest) (*counter.SetResponse, error)
// Get gets the current counter value
Get(context.Context, *counter.GetRequest) (*counter.GetResponse, error)
// Increment increments the counter value
Increment(context.Context, *counter.IncrementRequest) (*counter.IncrementResponse, error)
// Decrement decrements the counter value
Decrement(context.Context, *counter.DecrementRequest) (*counter.DecrementResponse, error)
}