You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rm_handler_facade.go 1.6 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package rm
  2. import (
  3. "context"
  4. "sync"
  5. )
  6. import (
  7. "github.com/seata/seata-go/pkg/common/model"
  8. "github.com/seata/seata-go/pkg/protocol"
  9. )
  10. var (
  11. onceRMHandlerFacade = &sync.Once{}
  12. rmHandler *RMHandlerFacade
  13. )
  14. type RMHandlerFacade struct {
  15. rmHandlerMap sync.Map
  16. }
  17. func GetRMHandlerFacadeInstance() *RMHandlerFacade {
  18. if rmHandler == nil {
  19. onceRMFacade.Do(func() {
  20. rmHandler = &RMHandlerFacade{}
  21. })
  22. }
  23. return rmHandler
  24. }
  25. // Handle branch commit response.
  26. func (h *RMHandlerFacade) HandleBranchCommitRequest(ctx context.Context, request protocol.BranchCommitRequest) (*protocol.BranchCommitResponse, error) {
  27. return h.getRMHandler(request.BranchType).HandleBranchCommitRequest(ctx, request)
  28. }
  29. // Handle branch rollback response.
  30. // TODO
  31. func (h *RMHandlerFacade) HandleBranchRollbackRequest(ctx context.Context, request protocol.BranchRollbackRequest) (*protocol.BranchRollbackResponse, error) {
  32. return h.getRMHandler(request.BranchType).HandleBranchRollbackRequest(ctx, request)
  33. }
  34. // Handle delete undo log .
  35. // TODO
  36. func (h *RMHandlerFacade) HandleUndoLogDeleteRequest(ctx context.Context, request protocol.UndoLogDeleteRequest) error {
  37. return h.getRMHandler(request.BranchType).HandleUndoLogDeleteRequest(ctx, request)
  38. }
  39. func (h *RMHandlerFacade) RegisteRMHandler(handler *CommonRMHandler) {
  40. if handler == nil {
  41. return
  42. }
  43. h.rmHandlerMap.Store(handler.GetBranchType(), handler)
  44. }
  45. func (h *RMHandlerFacade) getRMHandler(branchType model.BranchType) *CommonRMHandler {
  46. if handler, ok := h.rmHandlerMap.Load(branchType); ok {
  47. return handler.(*CommonRMHandler)
  48. }
  49. return nil
  50. }

Go Implementation For Seata