├── CONTRIBUTING.md ├── DEVELOPING.md ├── LICENSE ├── README.md ├── benchmark ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── wuba │ └── wlock │ └── benchmark │ ├── BatchPress.java │ ├── Data.java │ ├── EtcdDistributedLock.java │ ├── EtcdPress.java │ ├── Press.java │ ├── PressTask.java │ ├── RedLockPress.java │ ├── RedisPress.java │ ├── RedissonPress.java │ ├── StatisticsCollector.java │ ├── WlockMultiPress.java │ └── ZookeeperPress.java ├── client ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── wuba │ │ └── wlock │ │ └── client │ │ ├── InternalLockOption.java │ │ ├── LockContext.java │ │ ├── LockManager.java │ │ ├── LockOption.java │ │ ├── LockOwner.java │ │ ├── WDistributedLock.java │ │ ├── WLock.java │ │ ├── WLockClient.java │ │ ├── WReadLock.java │ │ ├── WReadWriteLock.java │ │ ├── WWriteLock.java │ │ ├── communication │ │ ├── ChannelPool.java │ │ ├── DataReceiver.java │ │ ├── LockPolicy.java │ │ ├── LockTypeEnum.java │ │ ├── NIOChannel.java │ │ ├── NIOHandler.java │ │ ├── ReadWriteLockTypeEnum.java │ │ ├── SendReqResult.java │ │ ├── Server.java │ │ ├── ServerPool.java │ │ ├── ServerPoolHandler.java │ │ ├── ServerState.java │ │ ├── WaitWindow.java │ │ ├── WatchPolicy.java │ │ ├── WindowData.java │ │ └── detect │ │ │ └── DaemonChecker.java │ │ ├── config │ │ ├── Delimiter.java │ │ ├── Factor.java │ │ ├── ParameterChecker.java │ │ ├── RegistryClientConfig.java │ │ ├── ServerConfig.java │ │ ├── Version.java │ │ └── WLockConfig.java │ │ ├── exception │ │ ├── CommunicationException.java │ │ ├── ConnectTimeoutException.java │ │ ├── OperationCanceledException.java │ │ ├── ParameterIllegalException.java │ │ ├── ProtocolException.java │ │ ├── RegistryClientRuntimeException.java │ │ └── SerializeException.java │ │ ├── helper │ │ ├── AutoResetEvent.java │ │ ├── ByteConverter.java │ │ ├── FileManager.java │ │ ├── FileUtil.java │ │ ├── HostUtil.java │ │ ├── OpaqueGenerator.java │ │ ├── PathUtil.java │ │ ├── PropertiesHelper.java │ │ ├── ProtocolHelper.java │ │ ├── ThreadPool.java │ │ └── XmlParser.java │ │ ├── listener │ │ ├── HoldLockListener.java │ │ ├── LockExpireListener.java │ │ ├── RenewListener.java │ │ └── WatchListener.java │ │ ├── lockresult │ │ ├── AcquireLockResult.java │ │ ├── GetLockResult.java │ │ └── LockResult.java │ │ ├── protocol │ │ ├── IProtocolFactory.java │ │ ├── ProtocolConst.java │ │ ├── ProtocolType.java │ │ ├── ResponseStatus.java │ │ ├── WLockProtocol.java │ │ ├── WLockRequest.java │ │ ├── WLockResponse.java │ │ └── extend │ │ │ ├── AcquireLockRequest.java │ │ │ ├── AcquireLockResponse.java │ │ │ ├── CommonWlockResponse.java │ │ │ ├── EventNotifyRequest.java │ │ │ ├── EventNotifyResponse.java │ │ │ ├── GetLockRequest.java │ │ │ ├── GetLockResponse.java │ │ │ ├── HeartbeatRequest.java │ │ │ ├── HeartbeatResponse.java │ │ │ ├── ProtocolFactoryImpl.java │ │ │ ├── RebootRequest.java │ │ │ ├── ReleaseLockRequest.java │ │ │ ├── ReleaseLockResponse.java │ │ │ ├── RenewLockRequest.java │ │ │ ├── RenewLockResponse.java │ │ │ ├── UnWatchLockRequest.java │ │ │ ├── WatchLockRequest.java │ │ │ └── WatchLockResponse.java │ │ ├── registryclient │ │ ├── communication │ │ │ ├── IFrameDecoder.java │ │ │ ├── RegistryChannelPool.java │ │ │ ├── RegistryDaemonChecker.java │ │ │ ├── RegistryDecoder.java │ │ │ ├── RegistryNIOChannel.java │ │ │ ├── RegistryNIOHandler.java │ │ │ ├── RegistryServer.java │ │ │ ├── RegistryServerPool.java │ │ │ └── WindowData.java │ │ ├── entity │ │ │ ├── ClientKeyEntity.java │ │ │ ├── DaemonCheckTask.java │ │ │ ├── GroupNode.java │ │ │ ├── Node.java │ │ │ └── NodeAddr.java │ │ ├── protocal │ │ │ ├── MessageType.java │ │ │ ├── OptionCode.java │ │ │ ├── ProtocolConstant.java │ │ │ ├── ProtocolParser.java │ │ │ ├── RegistryProtocol.java │ │ │ ├── RequestProtocolFactory.java │ │ │ ├── ResponseAck.java │ │ │ └── ResponseStatus.java │ │ ├── registrykey │ │ │ ├── RegistryKey.java │ │ │ └── RegistryKeyFactory.java │ │ └── tasks │ │ │ ├── RegistryHeartBeatTask.java │ │ │ ├── UpdateClustersTask.java │ │ │ └── VersionSendTask.java │ │ ├── service │ │ ├── HeartbeatService.java │ │ └── LockService.java │ │ ├── util │ │ ├── InetAddressUtil.java │ │ ├── SystemUtils.java │ │ ├── ThreadPoolUtil.java │ │ ├── ThreadRenameFactory.java │ │ ├── TimeUtil.java │ │ └── UniqueCodeGenerator.java │ │ └── watch │ │ ├── AcquireEvent.java │ │ ├── EventCachedHandler.java │ │ ├── EventType.java │ │ ├── NotifyEvent.java │ │ ├── WatchEvent.java │ │ ├── WatchManager.java │ │ └── WatchType.java │ └── test │ └── java │ └── com │ └── wuba │ └── wlock │ └── client │ ├── AcquireLockTest.java │ ├── ContinueTryAcquireTest.java │ ├── ProcessLockTest.java │ ├── ReadWriteLockTest.java │ ├── ReleaseLockTest.java │ └── RenewLockTest.java ├── common ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── wuba │ └── wlock │ └── common │ ├── collector │ └── protocol │ │ ├── GroupQps.java │ │ ├── KeyQps.java │ │ ├── QpsEntity.java │ │ └── ServerQps.java │ ├── entity │ ├── ClientKeyEntity.java │ ├── GroupNode.java │ ├── Node.java │ ├── NodeAddr.java │ ├── PushMessage.java │ └── VersionMessage.java │ ├── enums │ ├── ChangeNodeOperateType.java │ ├── MigrateEndState.java │ ├── MigrateExecuteResult.java │ ├── MigrateProcessEndState.java │ └── MigrateType.java │ ├── exception │ ├── ProtocolException.java │ └── ValidateException.java │ ├── registry │ └── protocol │ │ ├── MessageType.java │ │ ├── OptionCode.java │ │ ├── ProtocolConstant.java │ │ ├── ProtocolFactory.java │ │ ├── RegistryProtocol.java │ │ ├── ResponseStatus.java │ │ ├── ServerNode.java │ │ ├── request │ │ ├── GetGroupMigrateConfig.java │ │ ├── GetPaxosConfig.java │ │ ├── GetRegistryKeyQps.java │ │ ├── UploadGroupMaster.java │ │ └── UploadGroupMigrateState.java │ │ └── response │ │ ├── GetGroupMigrateConfigRes.java │ │ ├── GetPaxosConfRes.java │ │ └── GetRegistryKeyQpsRes.java │ └── util │ ├── ByteConverter.java │ ├── ProtocolHelper.java │ └── SessionIDGenerator.java ├── document ├── BENCHMARK.md ├── CONTRAST.md ├── DEPLOY.md ├── QUICKDEPLOY.md ├── USE.md ├── img │ ├── img1.png │ ├── qps.png │ ├── redisson.png │ ├── redlock1.png │ ├── redlock2.png │ ├── redlock3.png │ ├── rt.png │ ├── wlock-wechat.png │ ├── wlock1.png │ ├── wlock2.png │ ├── wlock3.png │ └── zookeeper.png └── sql │ └── create.sql ├── example ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── wuba │ └── wlock │ └── example │ ├── AcquireLockDemo.java │ ├── ProcessLockDemo.java │ ├── ReadWriteLockDemo.java │ └── RenewLockDemo.java ├── pom.xml ├── registry ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── wuba │ │ └── wlock │ │ └── registry │ │ ├── Application.java │ │ ├── admin │ │ ├── constant │ │ │ ├── ExceptionConstant.java │ │ │ ├── KeyConfig.java │ │ │ └── ValidationConstant.java │ │ ├── domain │ │ │ ├── ActionResult.java │ │ │ ├── CommonArrayResponse.java │ │ │ ├── CommonResponse.java │ │ │ ├── request │ │ │ │ ├── ApplyKeyReq.java │ │ │ │ ├── BaseMigrateReq.java │ │ │ │ ├── ChangeGroupNodeOperateInfoReq.java │ │ │ │ ├── ChangeNodeOperateInfoReq.java │ │ │ │ ├── ClusterInfoReq.java │ │ │ │ ├── ClusterSplitOperateInfoReq.java │ │ │ │ ├── KeyInfoReq.java │ │ │ │ ├── KeyUpdateReq.java │ │ │ │ ├── ListInfoReq.java │ │ │ │ ├── MigrateControlInfoReq.java │ │ │ │ ├── MigrateKeyInfoReq.java │ │ │ │ ├── MigrateReqKeyOperateInfoReq.java │ │ │ │ ├── MigrateRequestParseFactory.java │ │ │ │ ├── QuickInitReq.java │ │ │ │ └── ServerInfoReq.java │ │ │ └── response │ │ │ │ ├── ClusterResp.java │ │ │ │ ├── KeyResp.java │ │ │ │ ├── MigrateBaseResp.java │ │ │ │ ├── MigrateGroupNodeInfoResp.java │ │ │ │ ├── MigrateResp.java │ │ │ │ ├── QuickInitResp.java │ │ │ │ ├── ServerOnlineOfflineResp.java │ │ │ │ └── ServerResp.java │ │ ├── enums │ │ │ └── ServerQueryType.java │ │ ├── exceptions │ │ │ └── ServiceException.java │ │ ├── migrate │ │ │ ├── BaseMigrateOperateHandlerInterface.java │ │ │ ├── ChangeGroupNodeOperateHandler.java │ │ │ ├── ChangeNodeOperateHandler.java │ │ │ ├── ClusterSplitOperateHandler.java │ │ │ ├── MigrateKeyOperateHandler.java │ │ │ ├── MigrateOperateFactory.java │ │ │ └── RestoreMigrationStateOperateHandler.java │ │ ├── rest │ │ │ ├── ClusterRest.java │ │ │ ├── KeyRest.java │ │ │ ├── MigrateRest.java │ │ │ ├── QuickRest.java │ │ │ └── ServerRest.java │ │ ├── service │ │ │ ├── ClusterService.java │ │ │ ├── KeyService.java │ │ │ ├── MigrateService.java │ │ │ └── NodeService.java │ │ ├── utils │ │ │ ├── CommonResultUtil.java │ │ │ ├── GroupUtil.java │ │ │ └── SetUtil.java │ │ └── validators │ │ │ ├── ParamValidateUtil.java │ │ │ ├── ValidateResult.java │ │ │ └── ValidationCheck.java │ │ ├── config │ │ ├── Environment.java │ │ └── SwaggerConfig.java │ │ ├── constant │ │ ├── CommonConstant.java │ │ └── RedisKeyConstant.java │ │ ├── server │ │ ├── bootstrap │ │ │ └── RegistryServer.java │ │ ├── command │ │ │ ├── Command.java │ │ │ ├── ResponseAckCommand.java │ │ │ ├── client │ │ │ │ ├── ClientCommand.java │ │ │ │ ├── ClientConfigGetCommand.java │ │ │ │ ├── ClientConfigPushCommand.java │ │ │ │ ├── ClientHeartBeatCommand.java │ │ │ │ └── ClientVersionCommand.java │ │ │ └── server │ │ │ │ ├── GetKeyQpsCommand.java │ │ │ │ ├── GetMigrateConfigCommand.java │ │ │ │ ├── ServerCommand.java │ │ │ │ ├── ServerGetPaxosConfigCommand.java │ │ │ │ ├── ServerUploadMasterCommand.java │ │ │ │ └── UploadMigrateStateCommand.java │ │ ├── communication │ │ │ ├── IServer.java │ │ │ ├── IServerHandler.java │ │ │ └── tcp │ │ │ │ ├── RegistryFrameDecoder.java │ │ │ │ ├── RegistryPrepender.java │ │ │ │ ├── TcpServer.java │ │ │ │ └── TcpUpstreamHandler.java │ │ ├── config │ │ │ ├── Configuration.java │ │ │ ├── ServerConfig.java │ │ │ └── TCPServerConfig.java │ │ ├── context │ │ │ ├── WLockRegistryChannel.java │ │ │ └── WLockRegistryContext.java │ │ ├── entity │ │ │ ├── ChannelMessage.java │ │ │ ├── ChannelMessageType.java │ │ │ ├── ClientConfInfo.java │ │ │ ├── ClusterMasterGroupDistribute.java │ │ │ ├── FileInfo.java │ │ │ ├── Key.java │ │ │ ├── RemoveVersion.java │ │ │ └── ServerResult.java │ │ ├── handler │ │ │ ├── AsyncInvokerHandler.java │ │ │ └── InvokerHandler.java │ │ ├── manager │ │ │ ├── ChannelKeyPool.java │ │ │ ├── ChannelManager.java │ │ │ └── ClientVersionManager.java │ │ ├── redisscriber │ │ │ ├── PushMessageListener.java │ │ │ └── SubscribeClient.java │ │ ├── service │ │ │ ├── ClientService.java │ │ │ └── ServerService.java │ │ ├── util │ │ │ └── ConversionUtil.java │ │ └── worker │ │ │ └── RedisClusterConfSubscribeWorker.java │ │ └── util │ │ ├── IDHelper.java │ │ ├── MD5.java │ │ ├── RedisUtil.java │ │ ├── ThreadPool.java │ │ ├── ThreadRenameFactory.java │ │ └── Validator.java │ └── resources │ ├── application.yml │ ├── bin │ ├── quickStart.sh │ ├── start.sh │ └── stop.sh │ ├── logback-spring.xml │ └── schema.sql ├── repository ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── wuba │ │ └── wlock │ │ └── repository │ │ ├── DemoApplication.java │ │ ├── bean │ │ └── WlockDynamicDataSourceAutoConfiguration.java │ │ ├── config │ │ └── MybatisPlusConfig.java │ │ ├── domain │ │ ├── BaseDO.java │ │ ├── ClusterDO.java │ │ ├── GroupNodeDO.java │ │ ├── GroupServerRefDO.java │ │ ├── KeyDO.java │ │ ├── MigrateDO.java │ │ ├── MigrateProcessDO.java │ │ └── ServerDO.java │ │ ├── enums │ │ ├── ClusterState.java │ │ ├── GroupNodeState.java │ │ ├── LockOperationType.java │ │ ├── MasterLoadBalance.java │ │ ├── MigrateProcessState.java │ │ ├── MultiGroup.java │ │ ├── ServerState.java │ │ └── UseMasterState.java │ │ ├── helper │ │ ├── Page.java │ │ └── PageInfo.java │ │ ├── interceptor │ │ └── WlockDynamicDataSourceAnnotationInterceptor.java │ │ ├── mappers │ │ ├── ClusterMapper.java │ │ ├── GroupNodeMapper.java │ │ ├── GroupServerRefMapper.java │ │ ├── KeyMapper.java │ │ ├── MigrateMapper.java │ │ ├── MigrateProcessMapper.java │ │ └── ServerMapper.java │ │ └── repository │ │ ├── BaseRepository.java │ │ ├── ClusterRepository.java │ │ ├── GroupNodeRepository.java │ │ ├── GroupServerRefRepository.java │ │ ├── KeyRepository.java │ │ ├── MigrateProcessRepository.java │ │ ├── MigrateRepository.java │ │ └── ServerRepository.java │ └── test │ └── resources │ └── application.yaml ├── server ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── wuba │ │ └── wlock │ │ └── server │ │ ├── bootstrap │ │ ├── Main.java │ │ ├── base │ │ │ └── IServer.java │ │ └── signal │ │ │ └── RebootSignalHandle.java │ │ ├── client │ │ ├── ClientManager.java │ │ └── LockClient.java │ │ ├── collector │ │ ├── QpsAbandon.java │ │ ├── QpsCounter.java │ │ ├── entity │ │ │ ├── QpsLockStatCounter.java │ │ │ └── QpsVO.java │ │ └── log │ │ │ ├── CollectorLog.java │ │ │ ├── GroupLog.java │ │ │ ├── KeyGroupLog.java │ │ │ ├── KeyLog.java │ │ │ └── ServerLog.java │ │ ├── communicate │ │ ├── IProtocolFactory.java │ │ ├── ProtocolConst.java │ │ ├── ProtocolType.java │ │ ├── ResponseStatus.java │ │ ├── TcpHandler.java │ │ ├── TcpPipelineFactory.java │ │ ├── TcpServer.java │ │ ├── WLockProtocol.java │ │ ├── WLockRequest.java │ │ ├── WLockResponse.java │ │ ├── WlockFrameDecoder.java │ │ ├── WlockPrepender.java │ │ ├── constant │ │ │ ├── AckContext.java │ │ │ └── LockContext.java │ │ ├── protocol │ │ │ ├── AcquireLockRequest.java │ │ │ ├── AcquireLockResponse.java │ │ │ ├── DeleteLockRequest.java │ │ │ ├── EventNotifyRequest.java │ │ │ ├── EventNotifyResponse.java │ │ │ ├── GetLockRequest.java │ │ │ ├── GetLockResponse.java │ │ │ ├── HeartbeatRequest.java │ │ │ ├── HeartbeatResponse.java │ │ │ ├── MasterRedirectResponse.java │ │ │ ├── ProtocolFactoryImpl.java │ │ │ ├── RebootRequest.java │ │ │ ├── ReleaseLockRequest.java │ │ │ ├── ReleaseLockResponse.java │ │ │ ├── RenewLockRequest.java │ │ │ ├── RenewLockResponse.java │ │ │ ├── TrySnatchLockRequest.java │ │ │ ├── WatchLockRequest.java │ │ │ └── WatchLockResponse.java │ │ ├── registry │ │ │ ├── AutoResetEvent.java │ │ │ ├── RegisterChannel.java │ │ │ ├── RegistryClient.java │ │ │ ├── RegistryHandler.java │ │ │ ├── WindowData.java │ │ │ └── handler │ │ │ │ ├── AbstractPaxosHandler.java │ │ │ │ ├── GetGroupMigrateConfigHandler.java │ │ │ │ ├── GetKeyQpsHandler.java │ │ │ │ ├── GetPaxosConfigHandler.java │ │ │ │ ├── IPaxosHandler.java │ │ │ │ ├── UploadConfigHandler.java │ │ │ │ └── UploadGroupMigrateStateHandler.java │ │ ├── retrans │ │ │ ├── RetransChannel.java │ │ │ ├── RetransConfig.java │ │ │ ├── RetransDaemonChecker.java │ │ │ ├── RetransHandler.java │ │ │ ├── RetransServer.java │ │ │ ├── RetransServerConfig.java │ │ │ ├── RetransServerManager.java │ │ │ ├── RetransServerState.java │ │ │ ├── RetransWaitWindow.java │ │ │ └── WindowData.java │ │ └── signal │ │ │ ├── KeepMasterUdpClient.java │ │ │ ├── KeepMasterUdpServer.java │ │ │ ├── UDPServerHandler.java │ │ │ ├── UdpChannelPipelineFactory.java │ │ │ └── protocol │ │ │ └── TryBeMasterMessage.java │ │ ├── config │ │ ├── CheckpointConfig.java │ │ ├── DynamicConfig.java │ │ ├── IConfig.java │ │ ├── IDynamicConfig.java │ │ ├── LogConfig.java │ │ ├── PaxosConfig.java │ │ ├── RegistryConfig.java │ │ ├── RocksDbConfig.java │ │ ├── RootPath.java │ │ └── ServerConfig.java │ │ ├── constant │ │ ├── ConfigPath.java │ │ ├── GroupState.java │ │ ├── PaxosState.java │ │ └── ServerState.java │ │ ├── dispatcher │ │ └── ContextDispatcher.java │ │ ├── domain │ │ ├── AcquireLockDO.java │ │ ├── BaseLockDO.java │ │ ├── DeleteLockDO.java │ │ ├── GroupMeta.java │ │ ├── LockOwner.java │ │ ├── ReleaseLockDO.java │ │ └── RenewLockDO.java │ │ ├── exception │ │ ├── CommunicationException.java │ │ ├── ConfigException.java │ │ ├── GroupMetaException.java │ │ ├── LockException.java │ │ ├── OperationCanceledException.java │ │ ├── OperationTimeoutException.java │ │ ├── ProtocolException.java │ │ ├── RegistryClientRuntimeException.java │ │ └── RetransRuntimeException.java │ │ ├── expire │ │ ├── ExpireManager.java │ │ ├── ExpireStrategyFactory.java │ │ ├── ExpireTriggerProcessor.java │ │ ├── IExpireOperation.java │ │ ├── event │ │ │ ├── ExpireEvent.java │ │ │ ├── ExpireEventType.java │ │ │ ├── LockExpireEvent.java │ │ │ └── WatchExpireEvent.java │ │ └── queue │ │ │ └── all │ │ │ ├── ExpireQueueAllDispatcher.java │ │ │ └── QueueAllExpireManager.java │ │ ├── filter │ │ ├── IFilter.java │ │ └── IptablesFilter.java │ │ ├── keepmaster │ │ ├── GroupMasterStrategy.java │ │ └── HashStrategy.java │ │ ├── lock │ │ ├── LockResult.java │ │ ├── protocol │ │ │ ├── LockCodeEnum.java │ │ │ ├── LockOwnerInfo.java │ │ │ ├── LockSmCtx.java │ │ │ ├── LockTypeEnum.java │ │ │ ├── OpcodeEnum.java │ │ │ └── ReentrantLockValue.java │ │ ├── repository │ │ │ ├── ExpireEventRepository.java │ │ │ ├── LockRepositoryImpl.java │ │ │ └── base │ │ │ │ └── ILockRepository.java │ │ └── service │ │ │ ├── LockNotify.java │ │ │ ├── ReadWriteLock.java │ │ │ ├── ReentrantLock.java │ │ │ └── base │ │ │ ├── ILock.java │ │ │ ├── ILockNotify.java │ │ │ ├── IReadWriteLock.java │ │ │ └── IReentrantLock.java │ │ ├── migrate │ │ ├── domain │ │ │ ├── GroupMigrateState.java │ │ │ └── MigrateChangePoint.java │ │ ├── handler │ │ │ ├── BaseCommandHandler.java │ │ │ ├── CommandHandler.java │ │ │ ├── GroupChangeCommandHandler.java │ │ │ ├── GroupChangeRollbackCommandHandler.java │ │ │ ├── GroupChangeSafetypointCommandHandler.java │ │ │ ├── GroupChangeSafetypointRollbackCommandHandler.java │ │ │ ├── MigrateCommandHandlerFactory.java │ │ │ ├── MigrateEndCommandHandler.java │ │ │ ├── MigratePreparateCommandHandler.java │ │ │ └── MigratePreparateRollbackCommandHandler.java │ │ ├── protocol │ │ │ ├── MigrateChangePointDO.java │ │ │ ├── MigrateCommandDO.java │ │ │ ├── MigrateResult.java │ │ │ └── MigrateSmCtx.java │ │ ├── repository │ │ │ ├── MigrateChangePointRepository.java │ │ │ └── MigrateStateRepository.java │ │ └── service │ │ │ ├── MigrateChangePointService.java │ │ │ ├── MigrateService.java │ │ │ └── MigrateStateService.java │ │ ├── repository │ │ └── GroupMetaRepository.java │ │ ├── service │ │ ├── GroupMetaService.java │ │ ├── ILockService.java │ │ ├── KeepMasterService.java │ │ └── impl │ │ │ ├── BaseReadWriteLockService.java │ │ │ ├── KeepMasterServiceImpl.java │ │ │ ├── MasterChangeService.java │ │ │ ├── ReadLockService.java │ │ │ ├── ReentrantLockService.java │ │ │ └── WriteLockService.java │ │ ├── trace │ │ ├── LockTrace.java │ │ └── TraceWorker.java │ │ ├── util │ │ ├── ByteConverter.java │ │ ├── ConnManager.java │ │ ├── Factor.java │ │ ├── HostUtil.java │ │ ├── IPUtil.java │ │ ├── IpTablesFactory.java │ │ ├── OpaqueGenerator.java │ │ ├── SystemUtils.java │ │ ├── ThreadPoolUtil.java │ │ ├── ThreadRenameFactory.java │ │ └── TimeUtil.java │ │ ├── watch │ │ ├── EventType.java │ │ ├── IEventStorage.java │ │ ├── IWatchService.java │ │ ├── NotifyEvent.java │ │ ├── WatchEvent.java │ │ ├── WatchIndex.java │ │ ├── WatchType.java │ │ └── impl │ │ │ ├── EventStoreMemImpl.java │ │ │ └── WatchServiceImpl.java │ │ ├── worker │ │ ├── AckWorker.java │ │ ├── CollectorWorker.java │ │ ├── HeartbeatWorker.java │ │ ├── KeepMasterWorker.java │ │ ├── LockWorker.java │ │ └── MasterMgrWorker.java │ │ └── wpaxos │ │ ├── SMID.java │ │ ├── WpaxosService.java │ │ ├── checkpoint │ │ ├── AbstractCheckpointManager.java │ │ ├── CheckPoint.java │ │ ├── CheckpointGroupManager.java │ │ ├── CheckpointManager.java │ │ ├── ICheckPoint.java │ │ ├── ICheckpointGroupManager.java │ │ ├── ICheckpointManager.java │ │ ├── LockCheckpointFlag.java │ │ └── meta │ │ │ ├── MetaCheckPoint.java │ │ │ ├── MetaCheckpointGroupManager.java │ │ │ └── MetaCheckpointManager.java │ │ ├── rocksdb │ │ ├── DB.java │ │ ├── RocksDB.java │ │ └── RocksDBHolder.java │ │ └── statemachine │ │ ├── AbstractMetaStateMachine.java │ │ ├── AbstractStateMachine.java │ │ ├── GroupMetaSM.java │ │ ├── KeepMasterSM.java │ │ ├── LockStateMachine.java │ │ ├── MigrateChangePointSM.java │ │ └── MigrateCommandSM.java │ └── resources │ ├── bin │ ├── rshutdown.sh │ ├── shutdown.sh │ └── start.sh │ └── config │ ├── checkpoint.properties │ ├── dynamic.properties │ ├── log4j.xml │ ├── paxos.properties │ ├── registry.properties │ ├── rocksdb.properties │ ├── server.properties │ └── store.properties └── starter ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── wuba │ │ └── wlock │ │ └── starter │ │ ├── WLockAutoConfiguration.java │ │ ├── annotation │ │ ├── Lock.java │ │ ├── LockClient.java │ │ ├── LockItem.java │ │ ├── LockKey.java │ │ ├── MultiLock.java │ │ ├── ReadLock.java │ │ ├── ReadWriteLock.java │ │ └── WriteLock.java │ │ ├── aspect │ │ ├── WLockAspect.java │ │ └── lock │ │ │ ├── BaseLock.java │ │ │ ├── ILock.java │ │ │ ├── LockFactory.java │ │ │ ├── LockImpl.java │ │ │ ├── LockKeyGenerator.java │ │ │ ├── ReadLockImpl.java │ │ │ └── WriteLockImpl.java │ │ ├── config │ │ └── WLockProperties.java │ │ ├── enums │ │ └── LockTypeEnum.java │ │ ├── exception │ │ └── AcquireLockFailException.java │ │ └── processor │ │ ├── AnnotationBeanProcessor.java │ │ ├── BaseBeanProcessor.java │ │ ├── WLockBeanProcessor.java │ │ ├── WLockClientBeanProcessor.java │ │ ├── WReadLockBeanProcessor.java │ │ ├── WReadWriteLockBeanProcessor.java │ │ └── WWriteLockBeanProcessor.java └── resources │ └── META-INF │ └── spring.factories └── test ├── java └── com │ └── wuba │ └── wlock │ └── starter │ ├── LockKeyGeneratorImpl.java │ ├── ServerApplication.java │ └── TestService.java └── resources └── application.yml /CONTRIBUTING.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/CONTRIBUTING.md -------------------------------------------------------------------------------- /DEVELOPING.md: -------------------------------------------------------------------------------- 1 | ## Developers 2 | 3 | | Github ID | Organization | TimeZone 4 | | ------ | ------ | ------ | 5 | | liuliuwd | 58.com | +8 | 6 | | skywalkerfy | 58.com | +8 | 7 | | hucaicai | 58.com | +8 | 8 | | YczYanchengzhe | 58.com | +8 | 9 | | abstinencetang | 58.com | +8 | 10 | | Begro | 58.com | +8 | -------------------------------------------------------------------------------- /benchmark/src/main/java/com/wuba/wlock/benchmark/EtcdPress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.benchmark; 17 | 18 | public class EtcdPress implements Press{ 19 | 20 | @Override 21 | public boolean run(String lockName) throws Exception{ 22 | try { 23 | EtcdDistributedLock lock = new EtcdDistributedLock(lockName); 24 | lock.lock(); 25 | lock.unlock(); 26 | return true; 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /benchmark/src/main/java/com/wuba/wlock/benchmark/Press.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.benchmark; 17 | 18 | public interface Press { 19 | 20 | boolean run(String lockKey) throws Exception; 21 | } 22 | -------------------------------------------------------------------------------- /benchmark/src/main/java/com/wuba/wlock/benchmark/RedisPress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.benchmark; 17 | 18 | import redis.clients.jedis.Jedis; 19 | 20 | public class RedisPress implements Press{ 21 | Jedis jedis = new Jedis("127.0.0.1", 6379); 22 | 23 | @Override 24 | public boolean run(String lockName) throws Exception{ 25 | try { 26 | jedis.setnx(lockName, String.valueOf(Thread.currentThread())); 27 | jedis.del(lockName); 28 | return true; 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | return false; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/communication/LockTypeEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.communication; 17 | 18 | 19 | public enum LockTypeEnum { 20 | /** 21 | * 可重入锁 22 | */ 23 | reentrantLock(0), 24 | /** 25 | * 可重入读写 26 | */ 27 | readWriteReentrantLock(1); 28 | 29 | private int value; 30 | 31 | LockTypeEnum(int value) { 32 | this.value = value; 33 | } 34 | 35 | public int getValue() { 36 | return value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/communication/ServerState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.communication; 17 | 18 | public enum ServerState { 19 | 20 | Normal, 21 | 22 | ReStart, 23 | 24 | Dead, 25 | 26 | Testing, 27 | 28 | Closing 29 | } 30 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/config/Delimiter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.config; 17 | 18 | public class Delimiter { 19 | public static byte[] start = {}; 20 | public static byte[] end = new byte[]{9, 10, 13, 17, 18}; 21 | } 22 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/config/WLockConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.config; 17 | 18 | public class WLockConfig { 19 | /** 20 | * 发送队列最大长度 21 | */ 22 | public static final int MAX_WRITE_QUEUE_LEN = 100000; 23 | /** 24 | * 发送重试次数 25 | */ 26 | public static int SEND_RETRY_COUNT = 100; 27 | } 28 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/exception/CommunicationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.exception; 17 | 18 | public class CommunicationException extends Exception{ 19 | 20 | private static final long serialVersionUID = -3864991520786547002L; 21 | 22 | public CommunicationException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public CommunicationException(String message) { 27 | super(message); 28 | } 29 | 30 | public CommunicationException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public CommunicationException() { 35 | super("comunication exception"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/exception/ConnectTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.exception; 17 | 18 | public class ConnectTimeoutException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public ConnectTimeoutException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public ConnectTimeoutException(String message) { 27 | super(message); 28 | } 29 | 30 | public ConnectTimeoutException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public ConnectTimeoutException() { 35 | super("connection timeout exception"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/exception/OperationCanceledException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.exception; 17 | 18 | public class OperationCanceledException extends Exception{ 19 | private static final long serialVersionUID = 1L; 20 | 21 | public OperationCanceledException(String message, Throwable cause) { 22 | super(message, cause); 23 | } 24 | 25 | public OperationCanceledException(String message) { 26 | super(message); 27 | } 28 | 29 | public OperationCanceledException(Throwable cause) { 30 | super(cause); 31 | } 32 | 33 | public OperationCanceledException() { 34 | super("operation canceled exception"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/exception/ParameterIllegalException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.exception; 17 | 18 | public class ParameterIllegalException extends Exception { 19 | 20 | private static final long serialVersionUID = -3864991520786547002L; 21 | 22 | public ParameterIllegalException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public ParameterIllegalException(String message) { 27 | super(message); 28 | } 29 | 30 | public ParameterIllegalException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public ParameterIllegalException() { 35 | super("parameter illegal exception"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/exception/ProtocolException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.exception; 17 | 18 | public class ProtocolException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public ProtocolException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public ProtocolException(String message) { 27 | super(message); 28 | } 29 | 30 | public ProtocolException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public ProtocolException() { 35 | super("create or parse protocol error"); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/exception/RegistryClientRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.exception; 17 | 18 | public class RegistryClientRuntimeException extends Exception{ 19 | 20 | private static final long serialVersionUID = 5670502632996699019L; 21 | 22 | public RegistryClientRuntimeException(String message) { 23 | super(message); 24 | } 25 | 26 | public RegistryClientRuntimeException(Throwable e) { 27 | super(e); 28 | } 29 | 30 | public RegistryClientRuntimeException(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/exception/SerializeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.exception; 17 | 18 | public class SerializeException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public SerializeException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public SerializeException(String message) { 27 | super(message); 28 | } 29 | 30 | public SerializeException(Throwable cause) { 31 | super("serialize exception", cause); 32 | } 33 | 34 | public SerializeException() { 35 | super("serialize exception"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/helper/PathUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.helper; 17 | 18 | public class PathUtil { 19 | 20 | public static final String NAMESPACE_CONFIG_FOLDER; 21 | 22 | static { 23 | NAMESPACE_CONFIG_FOLDER = FileUtil.getRootPath() + "/opt/wlockconfig/"; 24 | } 25 | 26 | public static String getFilePath(String abstractResourcePath) { 27 | return NAMESPACE_CONFIG_FOLDER + abstractResourcePath; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/helper/ThreadPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.helper; 17 | 18 | import com.wuba.wlock.client.util.ThreadPoolUtil; 19 | import com.wuba.wlock.client.util.ThreadRenameFactory; 20 | 21 | import java.util.concurrent.ScheduledExecutorService; 22 | 23 | public class ThreadPool { 24 | 25 | public static final ScheduledExecutorService registryScheduler = ThreadPoolUtil.newScheduledThreadPool(1, new ThreadRenameFactory("registryScheduler")); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/listener/HoldLockListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.listener; 17 | 18 | 19 | public interface HoldLockListener { 20 | /** 21 | * 锁的持有者变更 , 此时不会在持有锁 22 | * @param lockKey 23 | * @param changeType : 变更类型 24 | */ 25 | void onOwnerChange(String lockKey, String changeType); 26 | } 27 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/listener/LockExpireListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.listener; 17 | 18 | public interface LockExpireListener { 19 | void onExpire(String lockkey); 20 | } 21 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/listener/RenewListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.listener; 17 | 18 | 19 | public interface RenewListener { 20 | /** 21 | * 续约成功,回调 22 | */ 23 | void onRenewSuccess(String lockkey); 24 | 25 | /** 26 | * 续约失败,回调 27 | */ 28 | void onRenewFailed(String lockkey); 29 | } 30 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/listener/WatchListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.listener; 17 | 18 | public interface WatchListener { 19 | /** 20 | * 锁owner发生变化 21 | * @param lockkey 22 | */ 23 | void onLockChange(String lockkey, long lockversion); 24 | 25 | /** 26 | * 锁被释放 27 | * @param lockkey 28 | */ 29 | void onLockReleased(String lockkey); 30 | 31 | /** 32 | * 锁被获取到 33 | * @param lockkey 34 | */ 35 | void onLockAcquired(String lockkey); 36 | 37 | /** 38 | * watch事件过期回调 39 | * @param lockkey 40 | */ 41 | void onTimeout(String lockkey); 42 | } 43 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/ProtocolConst.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol; 17 | 18 | public class ProtocolConst { 19 | public static final String NAME_VALUE_SEPARATOR = "!"; 20 | public static final String PROPERTY_SEPARATOR = "\\^"; 21 | public static final String PROPERTY_SEPARATOR_T = "^"; 22 | 23 | public static final String PROPERTY_MASTER_ADDR = "PROPERTY_MASTER"; 24 | public static final String IP_PORT_SEPARATOR = ":"; 25 | } 26 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/ProtocolType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol; 17 | 18 | public class ProtocolType { 19 | public static byte ACQUIRE_LOCK = 0x00; 20 | public static byte WATCH_LOCK = 0x01; 21 | public static byte RELEASE_LOCK = 0x02; 22 | public static byte GET_LOCK = 0X03; 23 | public static byte RENEW_LOCK = 0X04; 24 | public static byte EVENT_NOTIFY = 0X05; 25 | public static byte HEARTBEAT = 0X06; 26 | public final static byte REBOOT = 0x08; 27 | } 28 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/WLockProtocol.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | 20 | public interface WLockProtocol { 21 | void setTimestamp(long timestamp); 22 | 23 | void setSessionID(long sessionID); 24 | 25 | String getLockKey(); 26 | 27 | byte getProtocolType(); 28 | 29 | byte[] toBytes() throws ProtocolException; 30 | 31 | void fromBytes(byte[] dataBuf) throws ProtocolException; 32 | } 33 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/CommonWlockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockResponse; 20 | 21 | public class CommonWlockResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | 26 | return null; 27 | } 28 | 29 | @Override 30 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 31 | 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/EventNotifyResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockResponse; 20 | 21 | public class EventNotifyResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | 26 | return null; 27 | } 28 | 29 | @Override 30 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 31 | 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/GetLockRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockRequest; 20 | 21 | public class GetLockRequest extends WLockRequest { 22 | public static int EXTEND_FIXED_LENGTH = 0; 23 | 24 | @Override 25 | public byte[] genExtraBytes() throws ProtocolException { 26 | 27 | return null; 28 | } 29 | 30 | @Override 31 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 32 | } 33 | 34 | @Override 35 | public boolean isAsync() { 36 | return false; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/HeartbeatRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockRequest; 20 | 21 | public class HeartbeatRequest extends WLockRequest { 22 | public static int EXTEND_FIXED_LENGTH = 0; 23 | 24 | @Override 25 | public byte[] genExtraBytes() throws ProtocolException { 26 | 27 | return null; 28 | } 29 | 30 | @Override 31 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 32 | } 33 | 34 | @Override 35 | public boolean isAsync() { 36 | 37 | return false; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/HeartbeatResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockResponse; 20 | 21 | public class HeartbeatResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | 26 | return null; 27 | } 28 | 29 | @Override 30 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 31 | 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/RebootRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockRequest; 20 | 21 | public class RebootRequest extends WLockRequest { 22 | public static int EXTEND_FIXED_LENGTH = 0; 23 | 24 | @Override 25 | public byte[] genExtraBytes() throws ProtocolException { 26 | 27 | return null; 28 | } 29 | 30 | @Override 31 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/ReleaseLockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockResponse; 20 | 21 | public class ReleaseLockResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | 26 | return null; 27 | } 28 | 29 | @Override 30 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 31 | 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/RenewLockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockResponse; 20 | 21 | public class RenewLockResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | 26 | return null; 27 | } 28 | 29 | @Override 30 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 31 | 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/UnWatchLockRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockRequest; 20 | 21 | public class UnWatchLockRequest extends WLockRequest { 22 | public static int EXTEND_FIXED_LENGTH = 0; 23 | 24 | @Override 25 | public byte[] genExtraBytes() throws ProtocolException { 26 | 27 | return null; 28 | } 29 | 30 | @Override 31 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 32 | } 33 | 34 | @Override 35 | public boolean isAsync() { 36 | 37 | return false; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/protocol/extend/WatchLockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.protocol.extend; 17 | 18 | import com.wuba.wlock.client.exception.ProtocolException; 19 | import com.wuba.wlock.client.protocol.WLockResponse; 20 | 21 | public class WatchLockResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | 26 | return null; 27 | } 28 | 29 | @Override 30 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 31 | 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/registryclient/communication/IFrameDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.registryclient.communication; 17 | 18 | import com.wuba.wlock.client.exception.CommunicationException; 19 | 20 | import java.io.IOException; 21 | import java.net.ProtocolException; 22 | import java.nio.channels.NotYetConnectedException; 23 | import java.nio.channels.SocketChannel; 24 | 25 | interface IFrameDecoder { 26 | 27 | void decode(SocketChannel sockChannel, RegistryNIOChannel nioChannel) throws CommunicationException, IOException, NotYetConnectedException, ProtocolException; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/registryclient/protocal/OptionCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.registryclient.protocal; 17 | 18 | public class OptionCode { 19 | 20 | public static final byte OPCODE_LOCK_CLIENT_CONFIG_GET = (byte)0x00; 21 | public static final byte OPCODE_LOCK_CLIENT_CONFIG_PUSH = (byte)0x01; 22 | public static final byte OPCODE_LOCK_CLIENT_HEARTBEAT = (byte)0x02; 23 | public static final byte OPCODE_LOCK_CLIENT_VERSION = (byte)0x03; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/registryclient/protocal/ProtocolConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.registryclient.protocal; 17 | 18 | public class ProtocolConstant { 19 | 20 | /** 21 | * 最小message长度:version+opaque+msgType+totallen 22 | */ 23 | public static final int MIN_MESSAGE_LEN = 15; 24 | /** 25 | * 协议头 26 | */ 27 | public static final byte[] P_START_TAG = new byte[]{18, 17, 13, 10, 9}; 28 | /** 29 | * 协议尾 30 | */ 31 | public static final byte[] P_END_TAG = new byte[]{9, 10, 13, 17, 18}; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/util/ThreadPoolUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.util; 17 | 18 | import java.util.concurrent.*; 19 | 20 | public class ThreadPoolUtil { 21 | public static ScheduledExecutorService newScheduledThreadPool(int num, ThreadRenameFactory threadRenameFactory) { 22 | return new ScheduledThreadPoolExecutor(num, threadRenameFactory); 23 | } 24 | 25 | public static ExecutorService newFixedThreadPool(int num, ThreadRenameFactory threadRenameFactory) { 26 | return new ThreadPoolExecutor(num, num,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue(), threadRenameFactory); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/util/TimeUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.util; 17 | 18 | import org.apache.commons.logging.Log; 19 | import org.apache.commons.logging.LogFactory; 20 | 21 | import java.util.concurrent.TimeUnit; 22 | 23 | public class TimeUtil { 24 | private static final Log logger = LogFactory.getLog(TimeUtil.class); 25 | 26 | public static void secondSleep(long timeout) { 27 | try { 28 | TimeUnit.SECONDS.sleep(timeout); 29 | } catch (InterruptedException e) { 30 | logger.error("TimeUtil secondSleep error", e); 31 | } 32 | } 33 | 34 | public static long getCurrentMills() { 35 | return System.currentTimeMillis(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/watch/EventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.watch; 17 | 18 | /** 19 | * 三位数,locckType-lockOpcode-type 20 | */ 21 | public enum EventType { 22 | LOCK_ACQUIRED(0), 23 | LOCK_UPDATE(1), 24 | LOCK_RELEASE(2), 25 | LOCK_EXPIRED(3), 26 | WRITE_LOCK_EXPIRED(113), 27 | READ_LOCK_EXPIRED(123); 28 | 29 | 30 | int type; 31 | 32 | EventType(int type) { 33 | this.type = type; 34 | } 35 | 36 | public int getType() { 37 | return type; 38 | } 39 | 40 | public void setType(int type) { 41 | this.type = type; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /client/src/main/java/com/wuba/wlock/client/watch/WatchType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.client.watch; 17 | 18 | public enum WatchType { 19 | ACQUIRE(0), 20 | WATCH(1), 21 | WATCH_AND_ACQUIRE(2); 22 | 23 | int type; 24 | WatchType(int type) { 25 | this.type = type; 26 | } 27 | 28 | public int getType() { 29 | return type; 30 | } 31 | 32 | public void setType(int type) { 33 | this.type = type; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | wlock 7 | com.wuba.wlock 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | common 13 | 14 | 15 | 8 16 | 8 17 | 18 | 19 | 20 | 21 | com.alibaba 22 | fastjson 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/collector/protocol/GroupQps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.collector.protocol; 17 | 18 | import java.util.Map; 19 | 20 | 21 | public class GroupQps { 22 | private Map qps; 23 | 24 | public Map getQps() { 25 | return qps; 26 | } 27 | 28 | public void setQps(Map qps) { 29 | this.qps = qps; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/collector/protocol/KeyQps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.collector.protocol; 17 | 18 | import java.util.Map; 19 | 20 | 21 | public class KeyQps { 22 | 23 | /** 24 | * 单分组 : value 的 map 只有一个值 25 | * 多分组 : value 的 map 是所有分组的流量数据 26 | */ 27 | private Map> keyGroupQps; 28 | 29 | public Map> getKeyGroupQps() { 30 | return keyGroupQps; 31 | } 32 | 33 | public void setKeyGroupQps(Map> keyGroupQps) { 34 | this.keyGroupQps = keyGroupQps; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/collector/protocol/ServerQps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.collector.protocol; 17 | 18 | 19 | public class ServerQps { 20 | private QpsEntity qps; 21 | 22 | public QpsEntity getQps() { 23 | return qps; 24 | } 25 | 26 | public void setQps(QpsEntity qps) { 27 | this.qps = qps; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/entity/Node.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.entity; 17 | 18 | public class Node { 19 | private String ip; 20 | private int port; 21 | /** 22 | * 节点的唯一标识 23 | */ 24 | private int sequence; 25 | 26 | public String getIp() { 27 | return ip; 28 | } 29 | 30 | public void setIp(String ip) { 31 | this.ip = ip; 32 | } 33 | 34 | public int getPort() { 35 | return port; 36 | } 37 | 38 | public void setPort(int port) { 39 | this.port = port; 40 | } 41 | 42 | public int getSequence() { 43 | return sequence; 44 | } 45 | 46 | public void setSequence(int sequence) { 47 | this.sequence = sequence; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/entity/PushMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.entity; 17 | 18 | public class PushMessage { 19 | 20 | private String cluster; 21 | 22 | private long version; 23 | 24 | 25 | public String getCluster() { 26 | return cluster; 27 | } 28 | 29 | public void setCluster(String cluster) { 30 | this.cluster = cluster; 31 | } 32 | 33 | public long getVersion() { 34 | return version; 35 | } 36 | 37 | public void setVersion(long version) { 38 | this.version = version; 39 | } 40 | 41 | 42 | @Override 43 | public String toString() { 44 | return "PushMessage{" + 45 | "cluster='" + cluster + '\'' + 46 | ", version=" + version + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/enums/ChangeNodeOperateType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.enums; 17 | 18 | public enum ChangeNodeOperateType { 19 | /** 20 | * 添加或者更新节点 21 | */ 22 | Add(0), 23 | /** 24 | * 删除节点 25 | */ 26 | Delete(1); 27 | 28 | 29 | private final int value; 30 | 31 | private ChangeNodeOperateType(int value) { 32 | this.value = value; 33 | } 34 | 35 | public int getValue() { 36 | return this.value; 37 | } 38 | 39 | public static ChangeNodeOperateType parse(int value) { 40 | for (ChangeNodeOperateType tmp : values()) { 41 | if (value == tmp.value) { 42 | return tmp; 43 | } 44 | } 45 | throw new IllegalArgumentException("Illegal Argument [" + value + "] for ChangeNodeOperateType"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/enums/MigrateEndState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.enums; 17 | 18 | 19 | public enum MigrateEndState { 20 | NoEnd(0), 21 | End(1); 22 | 23 | 24 | private final int value; 25 | 26 | private MigrateEndState(int value) { 27 | this.value = value; 28 | } 29 | 30 | public int getValue() { 31 | return this.value; 32 | } 33 | 34 | public static MigrateEndState parse(int value) { 35 | for (MigrateEndState tmp : values()) { 36 | if (value == tmp.value) { 37 | return tmp; 38 | } 39 | } 40 | throw new IllegalArgumentException("Illegal Argument [" + value + "] for MigrateEndState"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/enums/MigrateExecuteResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.enums; 17 | 18 | 19 | public enum MigrateExecuteResult { 20 | Success(0), 21 | Running(1), 22 | Init(2); 23 | 24 | 25 | private final int value; 26 | 27 | private MigrateExecuteResult(int value) { 28 | this.value = value; 29 | } 30 | 31 | public int getValue() { 32 | return this.value; 33 | } 34 | 35 | public static MigrateExecuteResult parse(int value) { 36 | for (MigrateExecuteResult tmp : values()) { 37 | if (value == tmp.value) { 38 | return tmp; 39 | } 40 | } 41 | throw new IllegalArgumentException("Illegal Argument [" + value + "] for MigrateType"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/enums/MigrateProcessEndState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.enums; 17 | 18 | 19 | public enum MigrateProcessEndState { 20 | NoEnd(0), 21 | End(1); 22 | 23 | 24 | private final int value; 25 | 26 | private MigrateProcessEndState(int value) { 27 | this.value = value; 28 | } 29 | 30 | public int getValue() { 31 | return this.value; 32 | } 33 | 34 | public static MigrateProcessEndState parse(int value) { 35 | for (MigrateProcessEndState tmp : values()) { 36 | if (value == tmp.value) { 37 | return tmp; 38 | } 39 | } 40 | throw new IllegalArgumentException("Illegal Argument [" + value + "] for MigrateEndState"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/exception/ProtocolException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.exception; 17 | 18 | public class ProtocolException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public ProtocolException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public ProtocolException(String message) { 27 | super(message); 28 | } 29 | 30 | public ProtocolException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public ProtocolException() { 35 | super("create or parse protocol error"); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/exception/ValidateException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.exception; 17 | 18 | public class ValidateException extends Exception{ 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public ValidateException(String msg){ 23 | super(msg); 24 | } 25 | 26 | public ValidateException(String msg, Exception e){ 27 | super(msg, e); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/registry/protocol/ProtocolConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.registry.protocol; 17 | 18 | public class ProtocolConstant { 19 | 20 | /** 21 | * 最小message长度:version+opaque+msgType+totallen 22 | */ 23 | public static final int MIN_MESSAGE_LEN = 15; 24 | /** 25 | * 协议头 26 | */ 27 | public static final byte[] P_START_TAG = new byte[]{18, 17, 13, 10, 9}; 28 | /** 29 | * 协议尾 30 | */ 31 | public static final byte[] P_END_TAG = new byte[]{9, 10, 13, 17, 18}; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuba/wlock/common/registry/protocol/response/GetRegistryKeyQpsRes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.common.registry.protocol.response; 17 | 18 | import java.util.Map; 19 | 20 | public class GetRegistryKeyQpsRes { 21 | private Map keyQpsMap; 22 | private long version; 23 | 24 | public long getVersion() { 25 | return version; 26 | } 27 | 28 | public void setVersion(long version) { 29 | this.version = version; 30 | } 31 | 32 | public Map getKeyQpsMap() { 33 | return keyQpsMap; 34 | } 35 | 36 | public void setKeyQpsMap(Map keyQpsMap) { 37 | this.keyQpsMap = keyQpsMap; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /document/DEPLOY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # 服务端初始化详细步骤 : 5 | 6 | > 创建集群,添加节点,节点上线相关操作都可以通过 UI 快速完成 : http://localhost:8888/swagger-ui/index.html 7 | > url 中的 localhost 表示的是注册中心地址 8 | 9 | ## 常规服务部署与启动 10 | 11 | ### 创建数据表 [相关 SQL](sql/create.sql) 12 | ### 调整数据库配置 13 | ``` 14 | cd target 15 | unzip registry.zip 16 | cd registry 17 | # 编辑配置文件 : 18 | # 设置配置中的数据库 url 以及用户名,密码. 19 | # 设置配置中的redis ip 端口以及密码. 20 | vi config/application.yml 21 | ``` 22 | ### 部署注册中心并启动 23 | 24 | ```shell 25 | sh bin/start.sh 26 | ``` 27 | ### 通过swagger进行集群创建 28 | 29 | 接口 : `/wlock/cluster/add` 30 | 31 | ### 通过swagger进行节点添加 32 | 33 | > wlock 服务端支持集群模式部署和单机部署,如果服务端为单机部署,在添加节点时候只要添加一个节点即可. 34 | > 35 | > 如果是集群模式部署,请注意多个集群使用的paxos 端口 , tcp 端口 , telnet 端口,udp 端口需要保持一致,每个节点的序列 ID 需要不一样. 36 | 37 | 接口 : `/wlock/server/add` 38 | 39 | ### 通过swagger进行节点上线 40 | > 对于添加好的节点进行上线操作,只有上线后的节点才会真正对外提供服务 41 | 42 | 接口 : `/wlock/server/online` 43 | 44 | 45 | ### 服务端初始化 46 | > 依次启动已添加的服务节点 47 | 48 | ```shell 49 | # 1. 执行初始化之前请确认 config 下的registry.properties 中的 registryServerIp配置是不是注册中心 ip 50 | # 2. 确认 server.properties 配置的 listenPort 是不是注册中心新增节点的 tcp 端口,二者需要保持一致 51 | # 3. 由于服务端使用了 RocksDB,mac 的m1 芯片不支持运行 RocksDB,所以建议服务端部署服务器运行 52 | cd target 53 | unzip -d ./server server.zip 54 | sh server/bin/start.sh 55 | ``` 56 | 57 | -------------------------------------------------------------------------------- /document/QUICKDEPLOY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # 服务端初始化详细步骤 : 5 | 6 | > 创建集群,添加节点,节点上线相关操作都可以通过 UI 快速完成 : http://localhost:8888/swagger-ui/index.html 7 | > url 中的 localhost 表示的是注册中心地址 8 | 9 | ## 快速部署与启动 10 | ### 部署注册中心并启动 11 | ```shell 12 | # 在 target 目录中找到 registry 目录,cd 到该目录下执行下面命令 : 13 | sh bin/start.sh 14 | # 确认是否启动成功 : 15 | cat log/registry* | grep "Application start finish" 16 | ``` 17 | ### 快速初始化服务节点 18 | #### swagger 方式 : 19 | 20 | 快速启动接口 : `/wlock/quick/init` 21 | 22 | 备注 : 该接口会自动帮助创建 `default_cluster`集群,并且按照参数添加节点,对节点进行创建,给该集群添加秘钥`default_key`.秘钥key和集群会在响应中返回. 23 | 24 | #### 脚本方式 : 25 | 26 | ```shell 27 | # sequence_id 序列 id,用于唯一标识一个集群内的节点,同一集群内唯一 28 | # ip 节点 ip 29 | # tcp_port : 用于对外暴露的端口 30 | # paxos_port : 进行 paxos 的端口 31 | # udpPort : paxos 进行 udp 通信端口 32 | sh quickStart.sh quickinit 33 | ``` 34 | ### 启动服务节点 35 | > 依次启动已添加的服务节点 36 | 37 | ```shell 38 | # 启动前确认项: 39 | # 1. 执行初始化之前请确认 config 下的registry.properties 中的 registryServerIp配置是不是注册中心 ip 40 | # 2. 确认 server.properties 配置的 listenPort 是不是注册中心新增节点的 tcp 端口,二者需要保持一致 41 | # 3. 由于服务端使用了 RocksDB,mac 的m1 芯片不支持运行 RocksDB,所以建议服务端部署服务器运行 42 | cd target 43 | unzip -d ./server server.zip 44 | sh server/bin/start.sh 45 | ``` -------------------------------------------------------------------------------- /document/img/img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/img1.png -------------------------------------------------------------------------------- /document/img/qps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/qps.png -------------------------------------------------------------------------------- /document/img/redisson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/redisson.png -------------------------------------------------------------------------------- /document/img/redlock1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/redlock1.png -------------------------------------------------------------------------------- /document/img/redlock2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/redlock2.png -------------------------------------------------------------------------------- /document/img/redlock3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/redlock3.png -------------------------------------------------------------------------------- /document/img/rt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/rt.png -------------------------------------------------------------------------------- /document/img/wlock-wechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/wlock-wechat.png -------------------------------------------------------------------------------- /document/img/wlock1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/wlock1.png -------------------------------------------------------------------------------- /document/img/wlock2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/wlock2.png -------------------------------------------------------------------------------- /document/img/wlock3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/wlock3.png -------------------------------------------------------------------------------- /document/img/zookeeper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuba/WLock/1be8bbfa408630d0ee7f9a911adab26be90a37c5/document/img/zookeeper.png -------------------------------------------------------------------------------- /example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | wlock 7 | com.wuba.wlock 8 | 1.0.0 9 | 10 | 4.0.0 11 | 12 | example 13 | 14 | 15 | 8 16 | 8 17 | 18 | 19 | 20 | 21 | com.wuba.wlock 22 | client 23 | 24 | 25 | 26 | junit 27 | junit 28 | 29 | 30 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/constant/KeyConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.constant; 17 | 18 | public class KeyConfig { 19 | 20 | public static String NO_AUTO_RENEW = "否"; 21 | 22 | public static String AUTO_RENEW = "是"; 23 | } 24 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/constant/ValidationConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.constant; 17 | 18 | public class ValidationConstant { 19 | public static final String IP_REGEXP = "((?:(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d)))\\.){3}(?:25[0-5]|2[0-4]\\d|((1\\d{2})|([1-9]?\\d))))"; 20 | 21 | public static final String REGEX_NAME = "\\w+"; 22 | } 23 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/domain/request/BaseMigrateReq.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.domain.request; 17 | 18 | public abstract class BaseMigrateReq { 19 | } 20 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/domain/request/KeyInfoReq.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.domain.request; 17 | 18 | 19 | import com.wuba.wlock.registry.admin.constant.ValidationConstant; 20 | import com.wuba.wlock.registry.admin.validators.ValidationCheck; 21 | import lombok.Data; 22 | 23 | @Data 24 | public class KeyInfoReq { 25 | 26 | @ValidationCheck(allowEmpty = true, regexExpression = ValidationConstant.REGEX_NAME, filedDescription = "秘钥名") 27 | private String keyName; 28 | 29 | @ValidationCheck(allowEmpty = false, minValue = "1", filedDescription = "页码") 30 | private int pageNumber; 31 | 32 | @ValidationCheck(allowEmpty = false, minValue = "1", filedDescription = "每页条数") 33 | private int pageSize; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/domain/request/KeyUpdateReq.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.registry.admin.domain.request; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class KeyUpdateReq { 7 | private String id; 8 | private Integer autoRenew; 9 | private Integer qps; 10 | private String description; 11 | } 12 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/domain/response/QuickInitResp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.domain.response; 17 | 18 | import lombok.Data; 19 | 20 | 21 | @Data 22 | public class QuickInitResp { 23 | private String clusterName; 24 | private String keyName; 25 | private String keyHash; 26 | } 27 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/domain/response/ServerOnlineOfflineResp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.domain.response; 17 | 18 | public class ServerOnlineOfflineResp { 19 | 20 | private long serverId; 21 | 22 | private String ip; 23 | 24 | public long getServerId() { 25 | return serverId; 26 | } 27 | 28 | public void setServerId(long serverId) { 29 | this.serverId = serverId; 30 | } 31 | 32 | public String getIp() { 33 | return ip; 34 | } 35 | 36 | public void setIp(String ip) { 37 | this.ip = ip; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/domain/response/ServerResp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.domain.response; 17 | 18 | import lombok.Data; 19 | 20 | @Data 21 | public class ServerResp { 22 | 23 | private String id; 24 | 25 | private String server; 26 | 27 | 28 | private int paxosPort; 29 | 30 | private int udpPort; 31 | 32 | private String clusterName; 33 | 34 | private String state; 35 | 36 | private int sequenceId; 37 | } 38 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/enums/ServerQueryType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.enums; 17 | 18 | public enum ServerQueryType { 19 | 20 | /** 21 | * 查询方式 22 | */ 23 | QUERY("query"); 24 | 25 | private String value; 26 | 27 | ServerQueryType(String value) { 28 | this.value = value; 29 | } 30 | 31 | public String getValue() { 32 | return value; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/exceptions/ServiceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.exceptions; 17 | 18 | 19 | public class ServiceException extends Exception { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | public ServiceException(String message) { 24 | super(message); 25 | } 26 | 27 | public ServiceException(Throwable cause, String msg) { 28 | super(msg, cause); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/utils/GroupUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.utils; 17 | 18 | 19 | public final class GroupUtil { 20 | 21 | private GroupUtil(){} 22 | 23 | public static int getGroupByKey(String key, int groupCount) { 24 | return Math.abs(key.hashCode() % groupCount); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/utils/SetUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.utils; 17 | 18 | import java.util.HashSet; 19 | import java.util.Set; 20 | 21 | 22 | public class SetUtil { 23 | 24 | public static Set diffSet(Set set1, Set set2) { 25 | Set result = new HashSet<>(set1); 26 | Set m1 = new HashSet<>(set1); 27 | Set m2 = new HashSet<>(set2); 28 | result.removeAll(set2); 29 | m2.removeAll(m1); 30 | result.addAll(m2); 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/admin/validators/ValidateResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.admin.validators; 17 | 18 | 19 | public enum ValidateResult { 20 | /** 21 | * 验证通过 22 | */ 23 | PASS(""), 24 | /** 25 | * 验证失败 26 | */ 27 | NOT_PASS(""); 28 | 29 | private String errMsg; 30 | 31 | public String getErrMsg() { 32 | return errMsg; 33 | } 34 | 35 | public ValidateResult setErrMsg(String errMsg) { 36 | this.errMsg = errMsg; 37 | return this; 38 | } 39 | 40 | ValidateResult(String errMsg){ 41 | this.errMsg = errMsg; 42 | } 43 | 44 | public boolean isPass(){ 45 | return this==PASS; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/config/Environment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.config; 17 | 18 | import lombok.extern.slf4j.Slf4j; 19 | 20 | @Slf4j 21 | public class Environment { 22 | 23 | private static String env; 24 | 25 | public synchronized void setEnv(String env) throws Exception { 26 | Environment.env = env; 27 | } 28 | 29 | public static String env() { 30 | return env; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/constant/CommonConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.constant; 17 | 18 | public class CommonConstant { 19 | 20 | public static final String COMMA = ","; 21 | 22 | public static final int TWO = 2; 23 | 24 | public static final int THREE = 3; 25 | 26 | public static final int FOUR = 4; 27 | 28 | public static final String LEFT_BRACKETS = "["; 29 | public static final String RIGHT_BRACKETS = "]"; 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/command/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.command; 17 | 18 | import com.wuba.wlock.common.registry.protocol.RegistryProtocol; 19 | import com.wuba.wlock.registry.server.context.WLockRegistryContext; 20 | 21 | public interface Command { 22 | 23 | void execute(WLockRegistryContext context, RegistryProtocol reqProtocol) throws Exception; 24 | } 25 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/command/ResponseAckCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.command; 17 | 18 | import com.wuba.wlock.common.registry.protocol.RegistryProtocol; 19 | import com.wuba.wlock.registry.server.context.WLockRegistryContext; 20 | import lombok.extern.slf4j.Slf4j; 21 | import org.springframework.stereotype.Component; 22 | @Slf4j 23 | @Component 24 | public class ResponseAckCommand implements Command{ 25 | @Override 26 | public void execute(WLockRegistryContext context, RegistryProtocol reqProtocol) throws Exception { 27 | context.setAck(true); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/command/client/ClientCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.command.client; 17 | 18 | import com.wuba.wlock.registry.server.command.Command; 19 | 20 | public interface ClientCommand extends Command { 21 | } 22 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/command/server/ServerCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.command.server; 17 | 18 | import com.wuba.wlock.registry.server.command.Command; 19 | 20 | public interface ServerCommand extends Command { 21 | } 22 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/communication/IServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.communication; 17 | 18 | public interface IServer { 19 | 20 | void start() throws Exception; 21 | 22 | void stop() throws Exception; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/communication/IServerHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.communication; 17 | 18 | import com.wuba.wlock.registry.server.context.WLockRegistryContext; 19 | 20 | public interface IServerHandler { 21 | 22 | void writeResponse(WLockRegistryContext context); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/config/Configuration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.config; 17 | 18 | import java.util.Map; 19 | 20 | public interface Configuration { 21 | 22 | void setOptions(Map options); 23 | 24 | boolean setOption(String name, Object value); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/entity/ServerResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.entity; 17 | 18 | public class ServerResult { 19 | 20 | public static final int NO_CHANGE = 0; 21 | 22 | public static final int HAS_CHANGE = 1; 23 | 24 | private T result; 25 | 26 | private int status; 27 | 28 | public T getResult() { 29 | return result; 30 | } 31 | 32 | public void setResult(T result) { 33 | this.result = result; 34 | } 35 | 36 | public int getStatus() { 37 | return status; 38 | } 39 | 40 | public void setStatus(int status) { 41 | this.status = status; 42 | } 43 | 44 | public boolean isChanged() { 45 | return status == HAS_CHANGE; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/handler/InvokerHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.handler; 17 | 18 | import com.wuba.wlock.registry.server.context.WLockRegistryContext; 19 | 20 | public interface InvokerHandler { 21 | 22 | void invoke(WLockRegistryContext context) throws Exception; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/server/redisscriber/SubscribeClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.server.redisscriber; 17 | 18 | import redis.clients.jedis.Jedis; 19 | import redis.clients.jedis.JedisPubSub; 20 | 21 | public class SubscribeClient { 22 | private Jedis jedis; 23 | 24 | public SubscribeClient(Jedis jedis) { 25 | this.jedis = jedis; 26 | } 27 | 28 | public void clusterConfSubscribe(JedisPubSub listener, String channel) { 29 | jedis.subscribe(listener, channel); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /registry/src/main/java/com/wuba/wlock/registry/util/ThreadPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.registry.util; 17 | 18 | import java.util.concurrent.*; 19 | 20 | public class ThreadPool { 21 | 22 | private static final int CPU_CORE = Runtime.getRuntime().availableProcessors(); 23 | 24 | public static final ExecutorService EXECUTORS = new ThreadPoolExecutor(CPU_CORE, CPU_CORE, 25 | 0L, TimeUnit.MILLISECONDS, 26 | new LinkedBlockingQueue(), 27 | new ThreadRenameFactory("Registry-Server-Thread-")); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /registry/src/main/resources/bin/stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Copyright (C) 2005-present, 58.com. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # ---------------------------------------------------------------------------- 17 | 18 | PID=`pgrep -f registry` 19 | kill -9 ${PID} -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/DemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository; 17 | 18 | import org.springframework.boot.SpringApplication; 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | 21 | 22 | @SpringBootApplication 23 | public class DemoApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(DemoApplication.class, args); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/domain/BaseDO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.domain; 17 | 18 | import lombok.Data; 19 | 20 | @Data 21 | public class BaseDO> { 22 | 23 | } -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/enums/ClusterState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.enums; 17 | 18 | public enum ClusterState { 19 | 20 | /** 21 | * 下线状态 22 | */ 23 | offline(0), 24 | 25 | /** 26 | * 上线状态 27 | */ 28 | online(1); 29 | 30 | private int value; 31 | 32 | private ClusterState(int value) { 33 | this.value = value; 34 | } 35 | 36 | public int getValue() { 37 | return this.value; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/enums/GroupNodeState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.enums; 17 | 18 | public enum GroupNodeState { 19 | 20 | /** 21 | * 下线状态 22 | */ 23 | offline(0), 24 | 25 | /** 26 | * 上线状态 27 | */ 28 | online(1); 29 | 30 | private int value; 31 | 32 | private GroupNodeState(int value) { 33 | this.value = value; 34 | } 35 | 36 | public int getValue() { 37 | return this.value; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/enums/LockOperationType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.enums; 17 | 18 | public enum LockOperationType { 19 | /** 20 | * 加锁 21 | */ 22 | ACQUIRE_LOCK(0x00, "加锁"), 23 | /** 24 | * 释放锁 25 | */ 26 | RELEASE_LOCK(0x02, "释放锁"), 27 | /** 28 | * 刷新所 29 | */ 30 | RENEW_LOCK(0X04, "刷新锁"), 31 | /** 32 | * 删除锁 33 | */ 34 | DELETE_LOCK(0x07, "删除锁"); 35 | 36 | private int type; 37 | private String des; 38 | 39 | LockOperationType(int type, String des) { 40 | this.type = type; 41 | this.des = des; 42 | } 43 | 44 | public int getType() { 45 | return type; 46 | } 47 | 48 | public String getDes() { 49 | return des; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/enums/MasterLoadBalance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.enums; 17 | 18 | public enum MasterLoadBalance { 19 | 20 | /** 21 | * 下线状态 22 | */ 23 | noUse(0), 24 | 25 | /** 26 | * 上线状态 27 | */ 28 | use(1); 29 | 30 | private int value; 31 | 32 | private MasterLoadBalance(int value) { 33 | this.value = value; 34 | } 35 | 36 | public int getValue() { 37 | return this.value; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/enums/MultiGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.enums; 17 | 18 | 19 | public enum MultiGroup { 20 | 21 | /** 22 | * 下线状态 23 | */ 24 | UnUse(0), 25 | 26 | /** 27 | * 上线状态 28 | */ 29 | Use(1); 30 | 31 | private int value; 32 | 33 | private MultiGroup(int value) { 34 | this.value = value; 35 | } 36 | 37 | public int getValue() { 38 | return this.value; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/enums/ServerState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.enums; 17 | 18 | public enum ServerState { 19 | 20 | /** 21 | * 下线状态 22 | */ 23 | offline(0), 24 | 25 | /** 26 | * 上线状态 27 | */ 28 | online(1); 29 | 30 | private int value; 31 | 32 | private ServerState(int value) { 33 | this.value = value; 34 | } 35 | 36 | public int getValue() { 37 | return this.value; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/enums/UseMasterState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.enums; 17 | 18 | public enum UseMasterState { 19 | 20 | /** 21 | * 不使用 22 | */ 23 | noUse(0), 24 | 25 | /** 26 | * 使用 27 | */ 28 | use(1); 29 | 30 | private int value; 31 | 32 | private UseMasterState(int value) { 33 | this.value = value; 34 | } 35 | 36 | public int getValue() { 37 | return this.value; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/mappers/GroupNodeMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.mappers; 17 | 18 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 19 | import com.wuba.wlock.repository.domain.GroupNodeDO; 20 | import org.apache.ibatis.annotations.Mapper; 21 | import org.springframework.stereotype.Component; 22 | 23 | 24 | @Mapper 25 | @Component 26 | public interface GroupNodeMapper extends BaseMapper { 27 | } -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/mappers/MigrateMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.mappers; 17 | 18 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 19 | import com.wuba.wlock.repository.domain.MigrateDO; 20 | import org.apache.ibatis.annotations.Mapper; 21 | import org.springframework.stereotype.Component; 22 | 23 | 24 | @Mapper 25 | @Component 26 | public interface MigrateMapper extends BaseMapper { 27 | } -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/mappers/MigrateProcessMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.mappers; 17 | 18 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 19 | import com.wuba.wlock.repository.domain.MigrateProcessDO; 20 | import org.apache.ibatis.annotations.Mapper; 21 | import org.springframework.stereotype.Component; 22 | 23 | 24 | @Mapper 25 | @Component 26 | public interface MigrateProcessMapper extends BaseMapper { 27 | } -------------------------------------------------------------------------------- /repository/src/main/java/com/wuba/wlock/repository/repository/BaseRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.repository.repository; 17 | 18 | import com.baomidou.dynamic.datasource.annotation.DS; 19 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 20 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 21 | import com.wuba.wlock.repository.domain.BaseDO; 22 | 23 | @DS("") 24 | public class BaseRepository, T extends BaseDO> extends ServiceImpl { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /repository/src/test/resources/application.yaml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | application: 4 | name: WLock 5 | datasource: 6 | dynamic: 7 | primary: online 8 | datasource: 9 | offline: 10 | driver-class-name: com.mysql.jdbc.Driver 11 | url: jdbc:mysql://test.db.cn:10000/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull 12 | username: user 13 | password: 14 | online: 15 | driver-class-name: com.mysql.jdbc.Driver 16 | url: jdbc:mysql://test.db.cn:10000/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull 17 | username: user 18 | password: 19 | 20 | mybatis-plus: 21 | configuration: 22 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/bootstrap/base/IServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.bootstrap.base; 17 | 18 | public interface IServer { 19 | /** 20 | * 启动 21 | */ 22 | void start(); 23 | 24 | /** 25 | * 关闭 26 | */ 27 | void stop(); 28 | } 29 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/collector/log/CollectorLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.collector.log; 17 | 18 | public abstract class CollectorLog { 19 | public static final boolean mainEnable = true; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/ProtocolConst.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate; 17 | 18 | public class ProtocolConst { 19 | public static final String NAME_VALUE_SEPARATOR = "!"; 20 | public static final String PROPERTY_SEPARATOR = "\\^"; 21 | public static final String PROPERTY_SEPARATOR_T = "^"; 22 | 23 | public static final String PROPERTY_MASTER_ADDR = "PROPERTY_MASTER"; 24 | public static final String IP_PORT_SEPARATOR = ":"; 25 | 26 | public static final String PROPERTY_REAL_SESSIONID = "PROPERTY_REAL_SESSIONID"; 27 | } 28 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/ProtocolType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate; 17 | 18 | public class ProtocolType { 19 | public final static byte ACQUIRE_LOCK = 0x00; 20 | public final static byte WATCH_LOCK = 0x01; 21 | public final static byte RELEASE_LOCK = 0x02; 22 | public final static byte GET_LOCK = 0X03; 23 | public final static byte RENEW_LOCK = 0X04; 24 | public final static byte EVENT_NOTIFY = 0X05; 25 | public final static byte HEARTBEAT = 0X06; 26 | public final static byte DELETE_LOCK = 0x07; 27 | public final static byte REBOOT = 0x08; 28 | 29 | public final static byte TRY_SNATCH_LOCK = 0x09; 30 | } 31 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/ResponseStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate; 17 | 18 | public class ResponseStatus { 19 | public static short SUCCESS = 0x0000; // request success 20 | public static short TIMEOUT = 0x0001; // request failed, 请求超时 21 | public static short ERROR = 0X0002; 22 | public static short LOCK_OCCUPIED = 0X0003; // request failed, 锁已被占有 23 | public static short LOCK_DELETED = 0X0004; 24 | public static short LOCK_CHANGED_OWNER = 0X0005; 25 | 26 | public static short MASTER_REDIRECT = 0X0006; 27 | 28 | public static short TOKEN_ERROR = 0X0008; 29 | public static short LOCK_WAIT = 0X0009; 30 | } 31 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/WLockProtocol.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate; 17 | 18 | import com.wuba.wlock.server.exception.ProtocolException; 19 | 20 | public interface WLockProtocol { 21 | 22 | void setTimestamp(long timestamp); 23 | 24 | void setSessionID(long sessionID); 25 | 26 | String getLockKey(); 27 | 28 | byte getProtocolType(); 29 | 30 | byte[] toBytes() throws ProtocolException; 31 | 32 | void fromBytes(byte[] dataBuf) throws ProtocolException; 33 | } 34 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/constant/AckContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.constant; 17 | 18 | 19 | import org.jboss.netty.channel.Channel; 20 | 21 | public class AckContext { 22 | private Channel channel; 23 | private byte[] buf; 24 | 25 | public byte[] getBuf() { 26 | return buf; 27 | } 28 | 29 | public void setBuf(byte[] buf) { 30 | this.buf = buf; 31 | } 32 | 33 | public Channel getChannel() { 34 | 35 | return channel; 36 | } 37 | 38 | public void setChannel(Channel channel) { 39 | this.channel = channel; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/DeleteLockRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockRequest; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class DeleteLockRequest extends WLockRequest { 22 | 23 | @Override 24 | public boolean isAsync() { 25 | return false; 26 | } 27 | 28 | @Override 29 | public byte[] genExtraBytes() throws ProtocolException { 30 | return null; 31 | } 32 | 33 | @Override 34 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/EventNotifyResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockResponse; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class EventNotifyResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | return null; 26 | } 27 | 28 | @Override 29 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/GetLockRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockRequest; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | 22 | public class GetLockRequest extends WLockRequest { 23 | public static int EXTEND_FIXED_LENGTH = 0; 24 | 25 | @Override 26 | public byte[] genExtraBytes() throws ProtocolException { 27 | return null; 28 | } 29 | 30 | @Override 31 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 32 | } 33 | 34 | @Override 35 | public boolean isAsync() { 36 | return false; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/HeartbeatRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockRequest; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class HeartbeatRequest extends WLockRequest { 22 | public static int EXTEND_FIXED_LENGTH = 0; 23 | 24 | @Override 25 | public byte[] genExtraBytes() throws ProtocolException { 26 | return null; 27 | } 28 | 29 | @Override 30 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 31 | } 32 | 33 | @Override 34 | public boolean isAsync() { 35 | return false; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/HeartbeatResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockResponse; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class HeartbeatResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | return null; 26 | } 27 | 28 | @Override 29 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/MasterRedirectResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockResponse; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class MasterRedirectResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | return null; 26 | } 27 | 28 | @Override 29 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/RebootRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockRequest; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class RebootRequest extends WLockRequest { 22 | public static int EXTEND_FIXED_LENGTH = 0; 23 | 24 | @Override 25 | public byte[] genExtraBytes() throws ProtocolException { 26 | return null; 27 | } 28 | 29 | @Override 30 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/ReleaseLockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockResponse; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class ReleaseLockResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | return null; 26 | } 27 | 28 | @Override 29 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/RenewLockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockResponse; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class RenewLockResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | return null; 26 | } 27 | 28 | @Override 29 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/TrySnatchLockRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockRequest; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class TrySnatchLockRequest extends WLockRequest { 22 | 23 | @Override 24 | public boolean isAsync() { 25 | return false; 26 | } 27 | 28 | @Override 29 | public byte[] genExtraBytes() throws ProtocolException { 30 | return null; 31 | } 32 | 33 | @Override 34 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/protocol/WatchLockResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.protocol; 17 | 18 | import com.wuba.wlock.server.communicate.WLockResponse; 19 | import com.wuba.wlock.server.exception.ProtocolException; 20 | 21 | public class WatchLockResponse extends WLockResponse { 22 | 23 | @Override 24 | public byte[] genExtraBytes() throws ProtocolException { 25 | return null; 26 | } 27 | 28 | @Override 29 | public void parseExtraBytes(byte[] buf, int index) throws ProtocolException { 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/registry/handler/IPaxosHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.registry.handler; 17 | 18 | import com.wuba.wlock.common.registry.protocol.RegistryProtocol; 19 | import com.wuba.wlock.server.exception.ConfigException; 20 | 21 | public interface IPaxosHandler { 22 | 23 | RegistryProtocol buildMessage() throws ConfigException; 24 | 25 | boolean handleResponse(RegistryProtocol registryProtocol) throws Exception; 26 | } 27 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/retrans/RetransConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.retrans; 17 | 18 | public class RetransConfig { 19 | public static int CLIENT_REDIRECT_MAX_TIMES = 2; 20 | 21 | public static int CHANNEL_MAX_ERROR_TIMES = 3; 22 | 23 | public static int RETRANS_REQ_MAX_WAIT_TIME = 30000; //30s 24 | } 25 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/retrans/RetransServerState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.retrans; 17 | 18 | public enum RetransServerState { 19 | Normal, 20 | 21 | ReStart, 22 | 23 | Dead, 24 | 25 | Testing, 26 | 27 | Closing, 28 | 29 | Delete 30 | } 31 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/signal/UdpChannelPipelineFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.signal; 17 | 18 | import org.jboss.netty.channel.ChannelPipeline; 19 | import org.jboss.netty.channel.ChannelPipelineFactory; 20 | import org.jboss.netty.channel.Channels; 21 | 22 | public class UdpChannelPipelineFactory implements ChannelPipelineFactory{ 23 | 24 | /** 25 | * set the channel pipeline 26 | * 27 | */ 28 | @Override 29 | public ChannelPipeline getPipeline() throws Exception { 30 | ChannelPipeline pipeline = Channels.pipeline(); 31 | pipeline.addLast("handler", new UDPServerHandler()); 32 | return pipeline; 33 | } 34 | } -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/communicate/signal/protocol/TryBeMasterMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.communicate.signal.protocol; 17 | 18 | public class TryBeMasterMessage { 19 | 20 | private int groupId; 21 | private long nodeId; 22 | 23 | public TryBeMasterMessage() { 24 | } 25 | 26 | public TryBeMasterMessage(int subGroup, long myNodeID) { 27 | this.groupId = subGroup; 28 | this.nodeId = myNodeID; 29 | } 30 | 31 | public int getGroupId() { 32 | return groupId; 33 | } 34 | 35 | public void setGroupId(int groupId) { 36 | this.groupId = groupId; 37 | } 38 | 39 | public long getNodeId() { 40 | return nodeId; 41 | } 42 | 43 | public void setNodeId(long nodeId) { 44 | this.nodeId = nodeId; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/config/IDynamicConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.config; 17 | 18 | public interface IDynamicConfig { 19 | /** 20 | * 动态配置文件,重新加载文件方法 21 | */ 22 | void reload(); 23 | 24 | /** 25 | * 动态配置重新加载后,触发事件 26 | */ 27 | void reloadTrigger(); 28 | } 29 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/config/RootPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.config; 17 | 18 | public final class RootPath { 19 | private RootPath() { 20 | } 21 | 22 | public static final String getRootPath() { 23 | String property = System.getProperty("user.dir"); 24 | int indexOf = property.lastIndexOf("bin"); 25 | if (indexOf <= -1) { 26 | return property; 27 | } 28 | return property.substring(0, indexOf); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/constant/PaxosState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.constant; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | public class PaxosState { 22 | private static Map groupStart = new HashMap<>(); 23 | 24 | private PaxosState() { 25 | } 26 | 27 | public static boolean isStarted(int group) { 28 | return groupStart.containsKey(group) && groupStart.get(group); 29 | } 30 | 31 | public static boolean isStarted() { 32 | return !groupStart.values().stream().anyMatch(isStart -> !isStart); 33 | } 34 | 35 | public static void setGroupStart(int group) { 36 | groupStart.put(group, true); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/CommunicationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | public class CommunicationException extends Exception{ 19 | 20 | private static final long serialVersionUID = -3864991520786547002L; 21 | 22 | public CommunicationException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public CommunicationException(String message) { 27 | super(message); 28 | } 29 | 30 | public CommunicationException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public CommunicationException() { 35 | super("comunication exception"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/ConfigException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | public class ConfigException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public ConfigException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public ConfigException(String message) { 27 | super(message); 28 | } 29 | 30 | public ConfigException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/GroupMetaException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | public class GroupMetaException extends Exception{ 19 | public GroupMetaException(String message) { 20 | super(message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/LockException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | public class LockException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public LockException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public LockException(String message) { 27 | super(message); 28 | } 29 | 30 | public LockException(Throwable cause) { 31 | super(cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/OperationCanceledException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | public class OperationCanceledException extends Exception{ 19 | private static final long serialVersionUID = 1L; 20 | 21 | public OperationCanceledException(String message, Throwable cause) { 22 | super(message, cause); 23 | } 24 | 25 | public OperationCanceledException(String message) { 26 | super(message); 27 | } 28 | 29 | public OperationCanceledException(Throwable cause) { 30 | super(cause); 31 | } 32 | 33 | public OperationCanceledException() { 34 | super("operation canceled exception"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/OperationTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | import java.util.concurrent.TimeoutException; 19 | 20 | public class OperationTimeoutException extends TimeoutException { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | public OperationTimeoutException(String message) { 25 | super(message); 26 | } 27 | 28 | public OperationTimeoutException() { 29 | super("operation canceled exception"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/ProtocolException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | public class ProtocolException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public ProtocolException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public ProtocolException(String message) { 27 | super(message); 28 | } 29 | 30 | public ProtocolException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public ProtocolException() { 35 | super("create or parse protocol error"); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/RegistryClientRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | public class RegistryClientRuntimeException extends Exception{ 19 | 20 | /** 21 | * 22 | */ 23 | private static final long serialVersionUID = 5670502632996699019L; 24 | 25 | public RegistryClientRuntimeException(String message) { 26 | super(message); 27 | } 28 | 29 | public RegistryClientRuntimeException(Throwable e) { 30 | super(e); 31 | } 32 | 33 | public RegistryClientRuntimeException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/exception/RetransRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.exception; 17 | 18 | public class RetransRuntimeException extends Exception { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public RetransRuntimeException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public RetransRuntimeException(String message) { 27 | super(message); 28 | } 29 | 30 | public RetransRuntimeException(Throwable cause) { 31 | super(cause); 32 | } 33 | 34 | public RetransRuntimeException() { 35 | super("retrans client send data error"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/expire/IExpireOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.expire; 17 | 18 | import com.wuba.wlock.server.expire.event.ExpireEvent; 19 | 20 | public interface IExpireOperation { 21 | 22 | void start(); 23 | 24 | void stop(); 25 | 26 | void resume(int groupId); 27 | 28 | void pause(int groupId); 29 | 30 | void addExpireEvent(ExpireEvent expireEvent); 31 | 32 | void learnMaster(int groupId); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/expire/event/ExpireEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.expire.event; 17 | 18 | public class ExpireEventType { 19 | 20 | public static final byte EXPIRE_LOCK_EVENT = (byte) 0x01; 21 | 22 | public static final byte EXPIRE_WATCH_EVENT= (byte) 0x02; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/filter/IFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.filter; 17 | 18 | import java.net.SocketAddress; 19 | 20 | 21 | public interface IFilter { 22 | /** 23 | * 过虑 24 | * 25 | * @param address 26 | * @return 27 | */ 28 | boolean filter(SocketAddress address); 29 | } 30 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/keepmaster/GroupMasterStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.keepmaster; 17 | 18 | import com.wuba.wpaxos.comm.NodeInfo; 19 | 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | public interface GroupMasterStrategy { 24 | /** 25 | * 获取负载均衡后的mastergroup分布 26 | * 27 | * @param groupCounts group数量 28 | * @param nodeInfos 成员列表 29 | * @return group->nodeid 30 | */ 31 | Map getBalancedGroupMaster(int groupCounts, Map nodeInfos, Map> groupNodeMap); 32 | } 33 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/lock/LockResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.lock; 17 | 18 | public enum LockResult { 19 | SUCCESS(0,"成功"), 20 | PROTOCOL_SERIALIZATION_ERROR(1,"协议序列化错误"), 21 | PROTOCOL_TYPE_ERROR(2,"协议类型错误"), 22 | EXCEPTION(3,"异常情况"), 23 | KEY_NOT_EXIST(4,"key不存在"), 24 | OWNER_ERROR(5,"owner错误"), 25 | TOKEN_ERROR(6,"版本号错误"); 26 | 27 | private int value; 28 | private String des; 29 | 30 | LockResult(int value, String des) { 31 | this.value = value; 32 | this.des = des; 33 | } 34 | 35 | public int getValue() { 36 | return value; 37 | } 38 | 39 | public String getDes() { 40 | return des; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/lock/protocol/LockTypeEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.lock.protocol; 17 | 18 | public enum LockTypeEnum { 19 | /** 20 | * 可重入锁 21 | */ 22 | reentrantLock(0), 23 | /** 24 | * 可重入读写 25 | */ 26 | readWriteReentrantLock(1); 27 | 28 | private int value; 29 | 30 | LockTypeEnum(int value) { 31 | this.value = value; 32 | } 33 | 34 | public int getValue() { 35 | return value; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/lock/protocol/OpcodeEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.lock.protocol; 17 | 18 | public class OpcodeEnum { 19 | 20 | public enum ReadWriteOpcode { 21 | WRITE(1), 22 | READ(2) 23 | ; 24 | private byte value; 25 | 26 | ReadWriteOpcode(int value) { 27 | this.value = (byte) value; 28 | } 29 | 30 | public byte getValue() { 31 | return value; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/lock/service/base/ILock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.lock.service.base; 17 | 18 | public interface ILock { 19 | } 20 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/lock/service/base/IReadWriteLock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.lock.service.base; 17 | 18 | public interface IReadWriteLock extends IReentrantLock{ 19 | } 20 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/migrate/handler/CommandHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.migrate.handler; 17 | 18 | import com.wuba.wlock.server.migrate.protocol.MigrateCommandDO; 19 | import com.wuba.wlock.server.migrate.protocol.MigrateSmCtx; 20 | 21 | public interface CommandHandler { 22 | boolean handle(MigrateCommandDO migrateCommandDO, MigrateSmCtx migrateSmCtx); 23 | } 24 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/migrate/protocol/MigrateResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.migrate.protocol; 17 | 18 | public enum MigrateResult { 19 | SUCCESS(1, "成功"), 20 | EXCEPTION(2, "异常"), 21 | STATE_CHECK_FAIL(3, "状态校验失败"), 22 | VERSION_CHECK_FAIL(4, "版本校验失败"), 23 | REGISTER_KEY_CHECK_FAIL(5, "密钥校验失败") 24 | ; 25 | private Integer value; 26 | 27 | private String desc; 28 | 29 | MigrateResult(Integer value, String desc) { 30 | this.value = value; 31 | this.desc = desc; 32 | } 33 | 34 | public Integer getValue() { 35 | return value; 36 | } 37 | 38 | public String getDesc() { 39 | return desc; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/migrate/protocol/MigrateSmCtx.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.migrate.protocol; 17 | 18 | public class MigrateSmCtx { 19 | private MigrateResult migrateResult; 20 | 21 | public MigrateResult getMigrateResult() { 22 | return migrateResult; 23 | } 24 | 25 | public void setMigrateResult(MigrateResult migrateResult) { 26 | this.migrateResult = migrateResult; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/service/KeepMasterService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.service; 17 | 18 | public interface KeepMasterService { 19 | /** 20 | * step1:设置keepmaster态 21 | * step4:propose drop请求 22 | * 23 | * @param groupIdx 24 | * @param targetNodeId 25 | */ 26 | void keepMaster(int groupIdx, long targetNodeId); 27 | } 28 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/util/Factor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.util; 17 | 18 | public class Factor { 19 | 20 | public final static int SEQ_LIMIT = (1 << 31) - 2048; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/watch/EventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.watch; 17 | 18 | public enum EventType { 19 | LOCK_ACQUIRED(0), 20 | LOCK_UPDATE(1), 21 | LOCK_RELEASE(2), 22 | LOCK_EXPIRED(3), 23 | WRITE_LOCK_EXPIRED(113), 24 | READ_LOCK_EXPIRED(123); 25 | 26 | int type; 27 | 28 | EventType(int type) { 29 | this.type = type; 30 | } 31 | 32 | public int getType() { 33 | return type; 34 | } 35 | 36 | public void setType(int type) { 37 | this.type = type; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/watch/WatchType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.watch; 17 | 18 | public enum WatchType { 19 | ACQUIRE(0), 20 | WATCH(1), 21 | WATCH_AND_ACQUIRE(2); 22 | 23 | int type; 24 | private WatchType(int type) { 25 | this.type = type; 26 | } 27 | 28 | public int getType() { 29 | return type; 30 | } 31 | 32 | public void setType(int type) { 33 | this.type = type; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/wpaxos/SMID.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.wpaxos; 17 | 18 | public enum SMID { 19 | /** 20 | * 锁操作相关 21 | */ 22 | LOCK_SMID(1), 23 | KEEP_MASTER(2), 24 | WHEEL_TICK(3), 25 | MIGRATE_COMMAND(4), 26 | MIGRATE_POINT(5), 27 | GROUP_META(6) 28 | ; 29 | 30 | private int value; 31 | 32 | SMID(int value) { 33 | this.value = value; 34 | } 35 | 36 | public int getValue() { 37 | return value; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/wpaxos/checkpoint/ICheckPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.wpaxos.checkpoint; 17 | 18 | 19 | public interface ICheckPoint { 20 | 21 | String filePath(); 22 | } 23 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/wpaxos/checkpoint/LockCheckpointFlag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.wpaxos.checkpoint; 17 | 18 | public enum LockCheckpointFlag { 19 | 20 | UNLOCK((byte)0), 21 | LOCK((byte)1); 22 | 23 | private byte value; 24 | 25 | LockCheckpointFlag(byte value) { 26 | this.value = value; 27 | } 28 | 29 | public byte getValue() { 30 | return value; 31 | } 32 | 33 | public void setValue(byte value) { 34 | this.value = value; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /server/src/main/java/com/wuba/wlock/server/wpaxos/rocksdb/DB.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005-present, 58.com. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.wuba.wlock.server.wpaxos.rocksdb; 17 | 18 | import org.rocksdb.RocksDBException; 19 | import org.rocksdb.RocksIterator; 20 | 21 | public interface DB { 22 | 23 | void init(int groupCount) throws RocksDBException; 24 | 25 | void close(); 26 | 27 | void put(byte[] key, byte[] value, int groupId) throws RocksDBException; 28 | 29 | byte[] get(byte[] key, int groupId) throws RocksDBException; 30 | 31 | void delete(byte[] key, int groupId) throws RocksDBException; 32 | 33 | RocksIterator newIterator(int groupId); 34 | } 35 | -------------------------------------------------------------------------------- /server/src/main/resources/config/checkpoint.properties: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Copyright (C) 2005-present, 58.com. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ---------------------------------------------------------------------------- 16 | #非必填 17 | checkpoint.dir= 18 | checkpoint.intervalmin= -------------------------------------------------------------------------------- /server/src/main/resources/config/dynamic.properties: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Copyright (C) 2005-present, 58.com. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ---------------------------------------------------------------------------- 16 | tracelog.enable=true 17 | log.debug.enable=false 18 | expire.limit.start=false 19 | limit.enable=true 20 | 21 | server.log.enable=true 22 | group.log.enable=true 23 | key.log.enable=true 24 | key.group.log.enable=true 25 | collector.log.main.enable=true -------------------------------------------------------------------------------- /server/src/main/resources/config/paxos.properties: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Copyright (C) 2005-present, 58.com. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ---------------------------------------------------------------------------- 16 | #非必填 17 | optionsUseMembership= 18 | optionsUseBatchPropose=true 19 | optionsUDPMaxSize= 20 | optionsPrepareTimeout= 21 | optionsAcceptTimeout= 22 | optionsAskForLearnTimeout= 23 | optionsIoThreadCount= 24 | optionsUseMaster= 25 | indexlog= 26 | optionslearnerSendSpeed= 27 | optionsCommitTimeout= 28 | myNode= 29 | nodeList= 30 | -------------------------------------------------------------------------------- /server/src/main/resources/config/registry.properties: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Copyright (C) 2005-present, 58.com. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ---------------------------------------------------------------------------- 16 | #必填 17 | registryServerIp=registry.server.org 18 | registryServerPort=22020 19 | #非必填 20 | sendBufferSize= 21 | maxPakageSize= 22 | connectTimeOut= 23 | frameMaxLength= -------------------------------------------------------------------------------- /server/src/main/resources/config/rocksdb.properties: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Copyright (C) 2005-present, 58.com. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ---------------------------------------------------------------------------- 16 | #非必填 17 | boolmFilter= 18 | createIfMissing= 19 | maxWriteBufferNumber= 20 | maxBackgroundCompactions= 21 | maxBackgroundFlushes= 22 | useFsync= 23 | targetFileSizeBase= 24 | writeBufferSize= 25 | dbPath= -------------------------------------------------------------------------------- /server/src/main/resources/config/store.properties: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------- 2 | # Copyright (C) 2005-present, 58.com. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ---------------------------------------------------------------------------- 16 | #非必填 17 | mapedFileSizePhysic=52428800 18 | transientStorePoolSize=90 19 | transientStoreIndexDBPoolSize=90 20 | 21 | -------------------------------------------------------------------------------- /starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | wlock 9 | com.wuba.wlock 10 | 1.0.0 11 | 12 | 13 | starter 14 | 1.0.0 15 | 16 | 17 | 1.8 18 | UTF-8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-aop 25 | 26 | 27 | 28 | com.wuba.wlock 29 | client 30 | 31 | 32 | org.projectlombok 33 | lombok 34 | provided 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/annotation/Lock.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.annotation; 2 | 3 | 4 | 5 | import com.wuba.wlock.starter.aspect.lock.LockKeyGenerator; 6 | 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | /** 13 | * @author huguocai 14 | */ 15 | @Target({ElementType.FIELD, ElementType.METHOD}) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | public @interface Lock { 18 | 19 | String lockKey() default ""; 20 | 21 | String prefix() default ""; 22 | 23 | long expireTime() default 0; 24 | 25 | int maxWaitTime() default 0; 26 | 27 | int renewInterval() default 0; 28 | 29 | Class lockKeyGenerator() default LockKeyGenerator.class; 30 | } 31 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/annotation/LockClient.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author huguocai 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface LockClient { 14 | } 15 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/annotation/LockItem.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.annotation; 2 | 3 | import com.wuba.wlock.starter.aspect.lock.LockKeyGenerator; 4 | import com.wuba.wlock.starter.enums.LockTypeEnum; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * @author huguocai 12 | */ 13 | @Target({ElementType.METHOD}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface LockItem { 16 | LockTypeEnum lockType(); 17 | 18 | String lockKey() default ""; 19 | 20 | String prefix() default ""; 21 | 22 | long expireTime() default 0; 23 | 24 | int maxWaitTime() default 0; 25 | 26 | int renewInterval() default 0; 27 | 28 | Class lockKeyGenerator() default LockKeyGenerator.class; 29 | } 30 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/annotation/LockKey.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author huguocai 10 | */ 11 | @Target({ElementType.PARAMETER}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface LockKey { 14 | 15 | String value(); 16 | } 17 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/annotation/MultiLock.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author huguocai 10 | */ 11 | @Target({ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface MultiLock { 14 | 15 | LockItem[] value(); 16 | } 17 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/annotation/ReadLock.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.annotation; 2 | 3 | import com.wuba.wlock.starter.aspect.lock.LockKeyGenerator; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * @author huguocai 12 | */ 13 | @Target({ElementType.FIELD, ElementType.METHOD}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface ReadLock { 16 | 17 | String lockKey() default ""; 18 | 19 | String prefix() default ""; 20 | 21 | long expireTime() default 0; 22 | 23 | int maxWaitTime() default 0; 24 | 25 | int renewInterval() default 0; 26 | 27 | Class lockKeyGenerator() default LockKeyGenerator.class; 28 | } 29 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/annotation/ReadWriteLock.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author huguocai 10 | */ 11 | @Target({ElementType.FIELD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface ReadWriteLock { 14 | 15 | String lockKey(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/annotation/WriteLock.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.annotation; 2 | 3 | import com.wuba.wlock.starter.aspect.lock.LockKeyGenerator; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * @author huguocai 12 | */ 13 | @Target({ElementType.FIELD, ElementType.METHOD}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface WriteLock { 16 | 17 | String lockKey() default ""; 18 | 19 | String prefix() default ""; 20 | 21 | long expireTime() default 0; 22 | 23 | int maxWaitTime() default 0; 24 | 25 | int renewInterval() default 0; 26 | 27 | Class lockKeyGenerator() default LockKeyGenerator.class; 28 | } 29 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/aspect/lock/BaseLock.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.aspect.lock; 2 | 3 | /** 4 | * @author huguocai 5 | */ 6 | public abstract class BaseLock implements ILock{ 7 | private String lockKey; 8 | 9 | public BaseLock(String lockKey) { 10 | this.lockKey = lockKey; 11 | } 12 | 13 | @Override 14 | public String lockKey() { 15 | return this.lockKey; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/aspect/lock/ILock.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.aspect.lock; 2 | 3 | import com.wuba.wlock.client.exception.ParameterIllegalException; 4 | import com.wuba.wlock.client.lockresult.AcquireLockResult; 5 | import com.wuba.wlock.client.lockresult.LockResult; 6 | import com.wuba.wlock.starter.enums.LockTypeEnum; 7 | 8 | public interface ILock { 9 | 10 | AcquireLockResult tryAcquireLock(long expireTime, int maxWaitTime, int renewInterval) throws ParameterIllegalException; 11 | 12 | LockResult releaseLock() throws ParameterIllegalException; 13 | 14 | LockTypeEnum lockType(); 15 | 16 | String lockKey(); 17 | } 18 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/aspect/lock/LockImpl.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.aspect.lock; 2 | 3 | 4 | import com.wuba.wlock.client.WDistributedLock; 5 | import com.wuba.wlock.client.exception.ParameterIllegalException; 6 | import com.wuba.wlock.client.lockresult.AcquireLockResult; 7 | import com.wuba.wlock.client.lockresult.LockResult; 8 | import com.wuba.wlock.starter.enums.LockTypeEnum; 9 | 10 | /** 11 | * @author huguocai 12 | */ 13 | public class LockImpl extends BaseLock { 14 | private WDistributedLock lock; 15 | 16 | public LockImpl(WDistributedLock lock, String lockKey) { 17 | super(lockKey); 18 | this.lock = lock; 19 | } 20 | 21 | @Override 22 | public AcquireLockResult tryAcquireLock(long expireTime, int maxWaitTime, int renewInterval) throws ParameterIllegalException { 23 | if (renewInterval > 0) { 24 | return lock.tryAcquireLock(expireTime, maxWaitTime, renewInterval); 25 | } 26 | return lock.tryAcquireLock(expireTime, maxWaitTime); 27 | } 28 | 29 | @Override 30 | public LockResult releaseLock() throws ParameterIllegalException { 31 | return lock.releaseLock(); 32 | } 33 | 34 | @Override 35 | public LockTypeEnum lockType() { 36 | return LockTypeEnum.LOCK; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/aspect/lock/LockKeyGenerator.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.aspect.lock; 2 | 3 | /** 4 | * @author huguocai 5 | */ 6 | public interface LockKeyGenerator { 7 | 8 | String generate(Object[] args); 9 | } 10 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/aspect/lock/ReadLockImpl.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.aspect.lock; 2 | 3 | 4 | import com.wuba.wlock.client.WReadLock; 5 | import com.wuba.wlock.client.exception.ParameterIllegalException; 6 | import com.wuba.wlock.client.lockresult.AcquireLockResult; 7 | import com.wuba.wlock.client.lockresult.LockResult; 8 | import com.wuba.wlock.starter.enums.LockTypeEnum; 9 | 10 | /** 11 | * @author huguocai 12 | */ 13 | public class ReadLockImpl extends BaseLock { 14 | private WReadLock lock; 15 | 16 | public ReadLockImpl(WReadLock lock, String lockKey) { 17 | super(lockKey); 18 | this.lock = lock; 19 | } 20 | 21 | @Override 22 | public AcquireLockResult tryAcquireLock(long expireTime, int maxWaitTime, int renewInterval) throws ParameterIllegalException { 23 | if (renewInterval > 0) { 24 | return lock.tryAcquireLock(expireTime, maxWaitTime, renewInterval); 25 | } 26 | return lock.tryAcquireLock(expireTime, maxWaitTime); 27 | } 28 | 29 | @Override 30 | public LockResult releaseLock() throws ParameterIllegalException { 31 | return lock.releaseLock(); 32 | } 33 | 34 | @Override 35 | public LockTypeEnum lockType() { 36 | return LockTypeEnum.READ_LOCK; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/aspect/lock/WriteLockImpl.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.aspect.lock; 2 | 3 | 4 | import com.wuba.wlock.client.WWriteLock; 5 | import com.wuba.wlock.client.exception.ParameterIllegalException; 6 | import com.wuba.wlock.client.lockresult.AcquireLockResult; 7 | import com.wuba.wlock.client.lockresult.LockResult; 8 | import com.wuba.wlock.starter.enums.LockTypeEnum; 9 | 10 | /** 11 | * @author huguocai 12 | */ 13 | public class WriteLockImpl extends BaseLock{ 14 | private WWriteLock lock; 15 | 16 | public WriteLockImpl(WWriteLock lock, String lockKey) { 17 | super(lockKey); 18 | this.lock = lock; 19 | } 20 | 21 | @Override 22 | public AcquireLockResult tryAcquireLock(long expireTime, int maxWaitTime, int renewInterval) throws ParameterIllegalException { 23 | if (renewInterval > 0) { 24 | return lock.tryAcquireLock(expireTime, maxWaitTime, renewInterval); 25 | } 26 | return lock.tryAcquireLock(expireTime, maxWaitTime); 27 | } 28 | 29 | @Override 30 | public LockResult releaseLock() throws ParameterIllegalException { 31 | return lock.releaseLock(); 32 | } 33 | 34 | @Override 35 | public LockTypeEnum lockType() { 36 | return LockTypeEnum.WRITE_LOCK; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/config/WLockProperties.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | 7 | @Data 8 | @ConfigurationProperties("wlock") 9 | public class WLockProperties { 10 | 11 | private Boolean enabled = true; 12 | 13 | private String key; 14 | 15 | private String registryServerIp; 16 | 17 | private Integer registryServerPort; 18 | 19 | private Long expireTime; 20 | 21 | private Integer maxWaitTime; 22 | 23 | private int timeoutForReq; 24 | 25 | private int retryTimes; 26 | } 27 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/enums/LockTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.enums; 2 | 3 | /** 4 | * @author huguocai 5 | */ 6 | 7 | public enum LockTypeEnum { 8 | LOCK, 9 | READ_LOCK, 10 | WRITE_LOCK; 11 | } 12 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/exception/AcquireLockFailException.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.exception; 2 | 3 | public class AcquireLockFailException extends RuntimeException{ 4 | 5 | public AcquireLockFailException(String message) { 6 | super(message); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/processor/WLockBeanProcessor.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.processor; 2 | 3 | import com.wuba.wlock.client.WDistributedLock; 4 | import com.wuba.wlock.starter.annotation.Lock; 5 | import com.wuba.wlock.starter.config.WLockProperties; 6 | import org.springframework.beans.BeansException; 7 | import java.lang.annotation.Annotation; 8 | 9 | /** 10 | * @author huguocai 11 | */ 12 | public class WLockBeanProcessor extends BaseBeanProcessor { 13 | private static final String PREFIX = "WLock_"; 14 | 15 | public WLockBeanProcessor(WLockProperties properties) { 16 | super(properties); 17 | } 18 | 19 | @Override 20 | protected WDistributedLock createBean(Annotation annotation) { 21 | return createWDistributedLock(annotation); 22 | } 23 | 24 | @Override 25 | protected String beanName(Annotation annotation) { 26 | Lock lock = (Lock) annotation; 27 | return PREFIX + lock.prefix() + lock.lockKey(); 28 | } 29 | 30 | @Override 31 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 32 | return this.inject(bean, Lock.class); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/processor/WLockClientBeanProcessor.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.processor; 2 | 3 | import com.wuba.wlock.client.WLockClient; 4 | import com.wuba.wlock.starter.annotation.LockClient; 5 | import com.wuba.wlock.starter.config.WLockProperties; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.BeansException; 9 | 10 | import java.lang.annotation.Annotation; 11 | 12 | /** 13 | * @author huguocai 14 | */ 15 | public class WLockClientBeanProcessor extends BaseBeanProcessor { 16 | private static final Logger log = LoggerFactory.getLogger(WLockClientBeanProcessor.class); 17 | 18 | static final String NAME = "WLockClient"; 19 | 20 | public WLockClientBeanProcessor(WLockProperties properties) { 21 | super(properties); 22 | } 23 | 24 | @Override 25 | protected WLockClient createBean(Annotation annotation) { 26 | return createWLockClient(annotation); 27 | } 28 | 29 | @Override 30 | protected String beanName(Annotation annotation) { 31 | return NAME; 32 | } 33 | 34 | @Override 35 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 36 | return this.inject(bean, LockClient.class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/processor/WReadLockBeanProcessor.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.processor; 2 | 3 | import com.wuba.wlock.client.WDistributedLock; 4 | import com.wuba.wlock.client.WReadLock; 5 | import com.wuba.wlock.starter.annotation.ReadLock; 6 | import com.wuba.wlock.starter.config.WLockProperties; 7 | import org.springframework.beans.BeansException; 8 | 9 | import java.lang.annotation.Annotation; 10 | 11 | /** 12 | * @author huguocai 13 | */ 14 | public class WReadLockBeanProcessor extends BaseBeanProcessor { 15 | private static final String PREFIX = "WReadLock_"; 16 | 17 | public WReadLockBeanProcessor(WLockProperties properties) { 18 | super(properties); 19 | } 20 | 21 | @Override 22 | protected WReadLock createBean(Annotation annotation) { 23 | return createWReadLock(annotation); 24 | } 25 | 26 | @Override 27 | protected String beanName(Annotation annotation) { 28 | ReadLock readLock = (ReadLock) annotation; 29 | return PREFIX + readLock.prefix() + readLock.lockKey(); 30 | } 31 | 32 | @Override 33 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 34 | return this.inject(bean, ReadLock.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/processor/WReadWriteLockBeanProcessor.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.processor; 2 | 3 | import com.wuba.wlock.client.WDistributedLock; 4 | import com.wuba.wlock.client.WReadWriteLock; 5 | import com.wuba.wlock.starter.annotation.ReadWriteLock; 6 | import com.wuba.wlock.starter.config.WLockProperties; 7 | import org.springframework.beans.BeansException; 8 | import java.lang.annotation.Annotation; 9 | 10 | /** 11 | * @author huguocai 12 | */ 13 | public class WReadWriteLockBeanProcessor extends BaseBeanProcessor { 14 | static final String PREFIX = "WReadWriteLock_"; 15 | 16 | public WReadWriteLockBeanProcessor(WLockProperties properties) { 17 | super(properties); 18 | } 19 | 20 | @Override 21 | protected WReadWriteLock createBean(Annotation annotation) { 22 | return createWReadWriteLock(annotation); 23 | } 24 | 25 | @Override 26 | protected String beanName(Annotation annotation) { 27 | ReadWriteLock wLock = (ReadWriteLock) annotation; 28 | return PREFIX + wLock.lockKey(); 29 | } 30 | 31 | @Override 32 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 33 | return this.inject(bean, ReadWriteLock.class); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /starter/src/main/java/com/wuba/wlock/starter/processor/WWriteLockBeanProcessor.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter.processor; 2 | 3 | 4 | import com.wuba.wlock.client.WDistributedLock; 5 | import com.wuba.wlock.client.WWriteLock; 6 | import com.wuba.wlock.starter.annotation.WriteLock; 7 | import com.wuba.wlock.starter.config.WLockProperties; 8 | import org.springframework.beans.BeansException; 9 | import java.lang.annotation.Annotation; 10 | 11 | /** 12 | * @author huguocai 13 | */ 14 | public class WWriteLockBeanProcessor extends BaseBeanProcessor { 15 | private static final String PREFIX = "WWriteLock_"; 16 | 17 | public WWriteLockBeanProcessor(WLockProperties properties) { 18 | super(properties); 19 | } 20 | 21 | @Override 22 | protected WWriteLock createBean(Annotation annotation) { 23 | return createWWriteLock(annotation); 24 | } 25 | 26 | @Override 27 | protected String beanName(Annotation annotation) { 28 | WriteLock writeLock = (WriteLock) annotation; 29 | return PREFIX + writeLock.prefix() + writeLock.lockKey(); 30 | } 31 | 32 | @Override 33 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 34 | return this.inject(bean, WriteLock.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.wuba.wlock.starter.WLockAutoConfiguration,\ 3 | com.wuba.wlock.starter.aspect.WLockAspect -------------------------------------------------------------------------------- /starter/src/test/java/com/wuba/wlock/starter/LockKeyGeneratorImpl.java: -------------------------------------------------------------------------------- 1 | package com.wuba.wlock.starter; 2 | 3 | 4 | import com.wuba.wlock.starter.aspect.lock.LockKeyGenerator; 5 | 6 | public class LockKeyGeneratorImpl implements LockKeyGenerator { 7 | 8 | @Override 9 | public String generate(Object[] args) { 10 | 11 | return args[0]+ "_" + args[1]; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /starter/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | root: DEBUG 4 | 5 | wlock: 6 | enabled: true 7 | key: D484FEEF4F6E564920FABD0DE3C58D77 8 | registry-server-ip: 127.0.0.1 9 | registry-server-port: 22021 10 | expire-time: 5000 11 | max-wait-time: 5000 12 | timeout-for-req: 3000 13 | retry-times: 3 --------------------------------------------------------------------------------