NewActiveReplicator returns a bidirectional active replicator for the given config.
(ctx context.Context, config *ActiveReplicatorConfig)
| 34 | |
| 35 | // NewActiveReplicator returns a bidirectional active replicator for the given config. |
| 36 | func NewActiveReplicator(ctx context.Context, config *ActiveReplicatorConfig) (*ActiveReplicator, error) { |
| 37 | ar := &ActiveReplicator{ |
| 38 | ID: config.ID, |
| 39 | config: config, |
| 40 | } |
| 41 | |
| 42 | if pushReplication := config.Direction == ActiveReplicatorTypePush || config.Direction == ActiveReplicatorTypePushAndPull; pushReplication { |
| 43 | var err error |
| 44 | ar.Push, err = NewPushReplicator(ctx, config) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | if ar.config.onComplete != nil { |
| 49 | ar.Push.onReplicatorComplete = ar._onReplicationComplete |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if pullReplication := config.Direction == ActiveReplicatorTypePull || config.Direction == ActiveReplicatorTypePushAndPull; pullReplication { |
| 54 | var err error |
| 55 | ar.Pull, err = NewPullReplicator(ctx, config) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | if ar.config.onComplete != nil { |
| 60 | ar.Pull.onReplicatorComplete = ar._onReplicationComplete |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | base.InfofCtx(ctx, base.KeyReplicate, "Created active replicator ID:%s", config.ID) |
| 65 | return ar, nil |
| 66 | } |
| 67 | |
| 68 | func (ar *ActiveReplicator) Start(ctx context.Context) error { |
| 69 |