README.mdgit
在大型遊戲中常用分佈式,分佈式中由於遊戲邏輯會常常遊戲事務,藉助redis某些特性咱們能夠實現分佈式鎖和分佈式事務。不少redis集羣不支持redis的事務特性。
這個框架用來解決分佈式服務器下redis集羣事務失效的狀況下多線程分佈式鎖和分佈式鎖,支持獨佔鎖,共享鎖,讀寫鎖,而且支持事務提交失敗狀況下的回滾操做,讓開發者能夠有更多時間側重遊戲邏輯.github
可參考test下的entity.redis
- 生成事務緣由,GameTransactionCauseImpl裏面構造.
- 生成鎖實體,GameTransactionEntityFactoryImpl裏面構造TimeMutexEntity.
- 提交鎖實體跟事務,transactionService.commitTransaction裏面提交.
- 後去事務提交結果,根據返回值作出判斷.
可參考test下的read 能夠設置默認是否成功讀取到服務器
- 生成讀取事務緣由GameTransactionCause裏面已經構造好了.
- 生成讀取鎖實體GameTransactionEntityFactory裏面已經構造好了.
- 提交讀取鎖實體跟事務transactionService.commitTransaction裏面提交.
- 後去事務提交結果 根據返回值作出判斷.
可參考test下的lockattchment能夠設置默認是否成功讀取到多線程
- 生成事務緣由,GameTransactionCauseImpl裏面構造.
- 生成鎖實體,GameTransactionEntityFactoryImpl裏面構造.
- 生成鎖標記內容 GameTransactionEntity對象獲取GameTransactionLockInterface鎖使用setContent
- 提交鎖實體跟事務,transactionService.commitTransaction裏面提交.
- 後去事務提交結果,根據返回值作出判斷.
- 生成讀取事務緣由GameTransactionCause裏面構造.
- 生成讀取鎖實體GameTransactionEntityFactory裏面構.
- 生成鎖標記內容 GameTransactionEntity對象獲取GameTransactionLockInterface鎖使用setContent
- 提交讀取鎖實體跟事務transactionService.commitTransaction裏面提交.
- 後去事務提交結果 根據返回值作出判斷.
可參考test下的force
當鎖存在的狀況,延遲鎖佔用時間。
例子以下
1. 生成事務緣由,GameTransactionCauseImpl裏面構造.
2. 生成鎖實體,GameTransactionEntityFactoryImpl裏面構造ForceEntity.
3. 提交鎖實體跟事務,transactionService.commitTransaction裏面提交.
4. 後去事務提交結果,根據返回值作出判斷.框架
參考test下的testlock.
當鎖存在的狀況,延遲鎖佔用時間。
例子以下maven
- 生成事務緣由,GameTransactionCauseImpl裏面構造.
- 生成鎖實體,GameTransactionEntityFactoryImpl裏面構造TestTimeMutexEntity.
- 提交鎖實體跟事務,transactionService.commitTransaction裏面提交.
- 後去事務提交結果,根據返回值作出判斷.
參考test下的wait.當鎖失敗的狀況下,會嘗試每秒檢查鎖,直到設置的等待時間結束.例子以下分佈式
- 生成事務緣由,GameTransactionCauseImpl裏面構造.
- 生成鎖實體,GameTransactionEntityFactoryImpl裏面構造WaitMutexEntity.
- 提交鎖實體跟事務,transactionService.commitTransaction裏面提交.
- 後去事務提交結果,根據返回值作出判斷.
參考test下的rollback.當事務提交失敗的狀況下,根據提交進度進行rollback.例子以下spa
- 生成事務緣由,GameTransactionCauseImpl裏面構造.
- 生成鎖實體,GameTransactionEntityFactoryImpl裏面構造RollbackMutexEntity.
- 提交鎖實體跟事務,transactionService.commitTransaction裏面提交.
- 後去事務提交結果,根據返回值作出判斷.
代碼最後經過maven部署線程
- 做者qq 330258845
- QQ羣310158485