-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: use extension on serializer register --------- Co-authored-by: 均源 <zhangminglun.zml@antgroup.com> Co-authored-by: junyuan <zhangminglun.zml@ant-group.com>
- Loading branch information
1 parent
a9af9cd
commit 5a0c0f7
Showing
10 changed files
with
175 additions
and
13 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
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
31 changes: 31 additions & 0 deletions
31
...ting-bolt/src/main/java/com/alipay/sofa/rpc/codec/bolt/AbstractSerializationRegister.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,31 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.rpc.codec.bolt; | ||
|
||
import com.alipay.sofa.rpc.ext.Extensible; | ||
|
||
/** | ||
* | ||
* @author junyuan | ||
* @version AbstractSerializationRegister.java, v 0.1 2022年12月23日 15:01 junyuan Exp $ | ||
*/ | ||
@Extensible | ||
public abstract class AbstractSerializationRegister { | ||
|
||
public abstract void doRegisterCustomSerializer(); | ||
|
||
} |
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
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
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
1 change: 1 addition & 0 deletions
1
...s/META-INF/services/sofa-rpc/com.alipay.sofa.rpc.codec.bolt.AbstractSerializationRegister
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 @@ | ||
sofaRpcSerializationRegister=com.alipay.sofa.rpc.codec.bolt.SofaRpcSerializationRegister |
55 changes: 55 additions & 0 deletions
55
...remoting-bolt/src/test/java/com/alipay/sofa/rpc/codec/bolt/BoltSerializationInitTest.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,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.rpc.codec.bolt; | ||
|
||
import com.alipay.remoting.CustomSerializerManager; | ||
import com.alipay.sofa.rpc.core.response.SofaResponse; | ||
import com.alipay.sofa.rpc.ext.ExtensionLoaderFactory; | ||
import com.alipay.sofa.rpc.test.TestSofaRpcSerializationRegister; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @author junyuan | ||
* @version BoltSerializationInitTest.java, v 0.1 2022年12月23日 16:26 junyuan Exp $ | ||
*/ | ||
public class BoltSerializationInitTest { | ||
|
||
/** | ||
* add a serializer to override existing serializer | ||
*/ | ||
@Test | ||
public void testSerializerRegisterOverride() { | ||
AbstractSerializationRegister abstractSerializationRegister = ExtensionLoaderFactory.getExtensionLoader( | ||
AbstractSerializationRegister.class).getExtension("sofaRpcSerializationRegister"); | ||
abstractSerializationRegister.doRegisterCustomSerializer(); | ||
|
||
Assert.assertNull("testRegister未能覆盖原版register", | ||
CustomSerializerManager.getCustomSerializer(SofaResponse.class.getName())); | ||
|
||
Assert.assertNotNull("testRegister未能覆盖原版register", CustomSerializerManager.getCustomSerializer( | ||
TestSofaRpcSerializationRegister.class.getName())); | ||
} | ||
|
||
@After | ||
public void clearClassSerializerMap() { | ||
CustomSerializerManager.clear(); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...emoting-bolt/src/test/java/com/alipay/sofa/rpc/test/TestSofaRpcSerializationRegister.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,54 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.rpc.test; | ||
|
||
import com.alipay.remoting.CustomSerializerManager; | ||
import com.alipay.sofa.rpc.codec.bolt.AbstractSerializationRegister; | ||
import com.alipay.sofa.rpc.codec.bolt.SofaRpcSerialization; | ||
import com.alipay.sofa.rpc.codec.bolt.SofaRpcSerializationRegister; | ||
import com.alipay.sofa.rpc.core.request.SofaRequest; | ||
import com.alipay.sofa.rpc.ext.Extension; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
/** | ||
* Register custom serializer to bolt. | ||
* | ||
* @author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a> | ||
*/ | ||
@Extension(value = "sofaRpcSerializationRegister", override = true, order = 20) | ||
public class TestSofaRpcSerializationRegister extends SofaRpcSerializationRegister { | ||
|
||
private final SofaRpcSerialization rpcSerialization = new SofaRpcSerialization(); | ||
|
||
/** | ||
* we can override or rewrite the method | ||
*/ | ||
@Override | ||
protected void innerRegisterCustomSerializer() { | ||
// 注册序列化器到bolt | ||
if (CustomSerializerManager.getCustomSerializer(SofaRequest.class.getName()) == null) { | ||
CustomSerializerManager.registerCustomSerializer(SofaRequest.class.getName(), | ||
rpcSerialization); | ||
} | ||
|
||
if (CustomSerializerManager.getCustomSerializer(TestSofaRpcSerializationRegister.class.getName()) == null) { | ||
CustomSerializerManager.registerCustomSerializer(TestSofaRpcSerializationRegister.class.getName(), | ||
rpcSerialization); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../resources/META-INF/services/com.alipay.sofa.rpc.codec.bolt.AbstractSerializationRegister
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 @@ | ||
sofaRpcSerializationRegister=com.alipay.sofa.rpc.test.TestSofaRpcSerializationRegister |