-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid using reflection in meta clone (#758)
Co-authored-by: lishanglin <[email protected]>
- Loading branch information
1 parent
24b2c57
commit 4b1116f
Showing
48 changed files
with
671 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/meta/InnerMetaClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.ctrip.xpipe.redis.core.meta; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/13 | ||
*/ | ||
public interface InnerMetaClone<T> { | ||
|
||
T clone(T o); | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...s-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/ApplierContainerMetaClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.redis.core.entity.ApplierContainerMeta; | ||
import com.ctrip.xpipe.redis.core.meta.InnerMetaClone; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/14 | ||
*/ | ||
public class ApplierContainerMetaClone implements InnerMetaClone<ApplierContainerMeta> { | ||
|
||
@Override | ||
public ApplierContainerMeta clone(ApplierContainerMeta o) { | ||
ApplierContainerMeta clone = new ApplierContainerMeta(); | ||
clone.setId(o.getId()); | ||
clone.mergeAttributes(o); | ||
return clone; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/ApplierMetaClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.redis.core.entity.ApplierMeta; | ||
import com.ctrip.xpipe.redis.core.meta.InnerMetaClone; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/14 | ||
*/ | ||
public class ApplierMetaClone implements InnerMetaClone<ApplierMeta> { | ||
|
||
@Override | ||
public ApplierMeta clone(ApplierMeta o) { | ||
ApplierMeta clone = new ApplierMeta(); | ||
clone.setId(o.getId()); | ||
clone.mergeAttributes(o); | ||
return clone; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/AzMetaClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.redis.core.entity.AzMeta; | ||
import com.ctrip.xpipe.redis.core.meta.InnerMetaClone; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/13 | ||
*/ | ||
public class AzMetaClone implements InnerMetaClone<AzMeta> { | ||
|
||
@Override | ||
public AzMeta clone(AzMeta o) { | ||
AzMeta clone = new AzMeta(); | ||
clone.setId(o.getId()); | ||
clone.mergeAttributes(o); | ||
return clone; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/BaseEntityClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.redis.core.BaseEntity; | ||
import com.ctrip.xpipe.redis.core.meta.InnerMetaClone; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/13 | ||
*/ | ||
public class BaseEntityClone<T extends BaseEntity> implements InnerMetaClone<T> { | ||
|
||
@Override | ||
public T clone(T o) { | ||
try { | ||
T clone = (T)o.getClass().newInstance(); | ||
clone.mergeAttributes(o); | ||
return clone; | ||
} catch (InstantiationException|IllegalAccessException e) { | ||
throw new MetaCloneException(o.getClass().getSimpleName(), e); | ||
} | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/ClusterMetaClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.redis.core.entity.ClusterMeta; | ||
import com.ctrip.xpipe.redis.core.entity.ShardMeta; | ||
import com.ctrip.xpipe.redis.core.entity.SourceMeta; | ||
import com.ctrip.xpipe.redis.core.meta.InnerMetaClone; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/13 | ||
*/ | ||
public class ClusterMetaClone implements InnerMetaClone<ClusterMeta> { | ||
|
||
@Override | ||
public ClusterMeta clone(ClusterMeta o) { | ||
ClusterMeta clone = new ClusterMeta(); | ||
clone.setId(o.getId()); | ||
clone.mergeAttributes(o); | ||
|
||
if (null != o.getSources()) { | ||
for (SourceMeta sourceMeta: o.getSources()) { | ||
SourceMeta cloneSource = MetaCloneFacade.INSTANCE.clone(sourceMeta); | ||
clone.addSource(cloneSource); | ||
} | ||
} | ||
|
||
if (null != o.getShards()) { | ||
for (ShardMeta shardMeta: o.getShards().values()) { | ||
ShardMeta cloneShard = MetaCloneFacade.INSTANCE.clone(shardMeta); | ||
clone.addShard(cloneShard); | ||
} | ||
} | ||
|
||
return clone; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/DcMetaClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.redis.core.entity.*; | ||
import com.ctrip.xpipe.redis.core.meta.InnerMetaClone; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/13 | ||
*/ | ||
public class DcMetaClone implements InnerMetaClone<DcMeta> { | ||
|
||
@Override | ||
public DcMeta clone(DcMeta o) { | ||
DcMeta clone = new DcMeta(); | ||
clone.setId(o.getId()); | ||
clone.mergeAttributes(o); | ||
|
||
if (null != o.getClusters()) { | ||
for (ClusterMeta clusterMeta: o.getClusters().values()) { | ||
ClusterMeta cloneCluster = MetaCloneFacade.INSTANCE.clone(clusterMeta); | ||
clone.addCluster(cloneCluster); | ||
} | ||
} | ||
|
||
if (null != o.getRoutes()) { | ||
for (RouteMeta routeMeta: o.getRoutes()) { | ||
RouteMeta cloneRoute = MetaCloneFacade.INSTANCE.clone(routeMeta); | ||
clone.addRoute(cloneRoute); | ||
} | ||
} | ||
|
||
if (null != o.getKeeperContainers()) { | ||
for (KeeperContainerMeta keeperContainerMeta: o.getKeeperContainers()) { | ||
KeeperContainerMeta cloneKeeperContainer = MetaCloneFacade.INSTANCE.clone(keeperContainerMeta); | ||
clone.addKeeperContainer(cloneKeeperContainer); | ||
} | ||
} | ||
|
||
if (null != o.getApplierContainers()) { | ||
for (ApplierContainerMeta applierContainerMeta: o.getApplierContainers()) { | ||
ApplierContainerMeta cloneApplierContainer = MetaCloneFacade.INSTANCE.clone(applierContainerMeta); | ||
clone.addApplierContainer(cloneApplierContainer); | ||
} | ||
} | ||
|
||
if (null != o.getSentinels()) { | ||
for (SentinelMeta sentinelMeta: o.getSentinels().values()) { | ||
SentinelMeta cloneSentinel = MetaCloneFacade.INSTANCE.clone(sentinelMeta); | ||
clone.addSentinel(cloneSentinel); | ||
} | ||
} | ||
|
||
if (null != o.getMetaServers()) { | ||
for (MetaServerMeta metaServerMeta: o.getMetaServers()) { | ||
MetaServerMeta cloneMetaServer = MetaCloneFacade.INSTANCE.clone(metaServerMeta); | ||
clone.addMetaServer(cloneMetaServer); | ||
} | ||
} | ||
|
||
if (null != o.getAzs()) { | ||
for (AzMeta azMeta: o.getAzs()) { | ||
AzMeta cloneAz = MetaCloneFacade.INSTANCE.clone(azMeta); | ||
clone.addAz(cloneAz); | ||
} | ||
} | ||
|
||
if (null != o.getZkServer()) { | ||
ZkServerMeta cloneZkServer = MetaCloneFacade.INSTANCE.clone(o.getZkServer()); | ||
cloneZkServer.setParent(clone); | ||
clone.setZkServer(cloneZkServer); | ||
} | ||
|
||
return clone; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...is-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/KeeperContainerMetaClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.redis.core.entity.KeeperContainerMeta; | ||
import com.ctrip.xpipe.redis.core.meta.InnerMetaClone; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/14 | ||
*/ | ||
public class KeeperContainerMetaClone implements InnerMetaClone<KeeperContainerMeta> { | ||
|
||
@Override | ||
public KeeperContainerMeta clone(KeeperContainerMeta o) { | ||
KeeperContainerMeta clone = new KeeperContainerMeta(); | ||
clone.setId(o.getId()); | ||
clone.mergeAttributes(o); | ||
return clone; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/KeeperMetaClone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.redis.core.entity.KeeperMeta; | ||
import com.ctrip.xpipe.redis.core.meta.InnerMetaClone; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/14 | ||
*/ | ||
public class KeeperMetaClone implements InnerMetaClone<KeeperMeta> { | ||
|
||
@Override | ||
public KeeperMeta clone(KeeperMeta o) { | ||
KeeperMeta clone = new KeeperMeta(); | ||
clone.setId(o.getId()); | ||
clone.mergeAttributes(o); | ||
return clone; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
redis/redis-core/src/main/java/com/ctrip/xpipe/redis/core/meta/clone/MetaCloneException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.ctrip.xpipe.redis.core.meta.clone; | ||
|
||
import com.ctrip.xpipe.exception.XpipeRuntimeException; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2023/12/13 | ||
*/ | ||
public class MetaCloneException extends XpipeRuntimeException { | ||
|
||
public MetaCloneException(String message) { | ||
super(message); | ||
} | ||
|
||
public MetaCloneException(String message, Throwable th) { | ||
super(message, th); | ||
} | ||
|
||
} |
Oops, something went wrong.