forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_operation_executor.go
49 lines (44 loc) · 1.47 KB
/
server_operation_executor.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
package ravendb
type ServerOperationExecutor struct {
requestExecutor *ClusterRequestExecutor
}
func NewServerOperationExecutor(store *DocumentStore) *ServerOperationExecutor {
res := &ServerOperationExecutor{}
urls := store.GetUrls()
cert := store.Certificate
trustStore := store.TrustStore
conv := store.GetConventions()
if conv.IsDisableTopologyUpdates() {
res.requestExecutor = ClusterRequestExecutorCreateForSingleNode(urls[0], cert, trustStore, conv)
} else {
res.requestExecutor = ClusterRequestExecutorCreate(urls, cert, trustStore, conv)
}
fn := func(store *DocumentStore) {
res.requestExecutor.Close()
}
store.AddAfterCloseListener(fn)
return res
}
func (e *ServerOperationExecutor) Send(operation IServerOperation) error {
command, err := operation.GetCommand(e.requestExecutor.GetConventions())
if err != nil {
return err
}
return e.requestExecutor.ExecuteCommand(command, nil)
}
func (e *ServerOperationExecutor) SendAsync(operation IServerOperation) (*Operation, error) {
requestExecutor := e.requestExecutor
command, err := operation.GetCommand(requestExecutor.GetConventions())
if err != nil {
return nil, err
}
if err = requestExecutor.ExecuteCommand(command, nil); err != nil {
return nil, err
}
result := getCommandOperationIDResult(command)
return NewServerWideOperation(requestExecutor, requestExecutor.GetConventions(), result.OperationID), nil
}
func (e *ServerOperationExecutor) Close() {
e.requestExecutor.Close()
e.requestExecutor = nil
}