forked from sofastack/sofa-rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable dynamically load the extension from code. (sofastack#912)
- Loading branch information
Showing
19 changed files
with
192 additions
and
61 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
|
||
/** | ||
* Factory of TelnetHandler | ||
* | ||
* | ||
* @author <a href=mailto:[email protected]>GengZhang</a> | ||
*/ | ||
@Unstable | ||
|
@@ -52,18 +52,19 @@ public class TelnetHandlerFactory { | |
private final static ExtensionLoader<TelnetHandler> EXTENSION_LOADER = buildLoader(); | ||
|
||
private static ExtensionLoader<TelnetHandler> buildLoader() { | ||
return ExtensionLoaderFactory.getExtensionLoader(TelnetHandler.class, | ||
new ExtensionLoaderListener<TelnetHandler>() { | ||
@Override | ||
public void onLoad(ExtensionClass<TelnetHandler> extensionClass) { | ||
// 自己维护支持列表,不托管给ExtensionLoaderFactory | ||
TelnetHandler handler = extensionClass.getExtInstance(); | ||
supportedCmds.put(handler.getCommand(), handler); | ||
if (LOGGER.isDebugEnabled()) { | ||
LOGGER.debug("Add telnet handler {}:{}.", handler.getCommand(), handler); | ||
} | ||
ExtensionLoader<TelnetHandler> extensionLoader = ExtensionLoaderFactory.getExtensionLoader(TelnetHandler.class); | ||
extensionLoader.addListener(new ExtensionLoaderListener<TelnetHandler>() { | ||
@Override | ||
public void onLoad(ExtensionClass<TelnetHandler> extensionClass) { | ||
// 自己维护支持列表,不托管给ExtensionLoaderFactory | ||
TelnetHandler handler = extensionClass.getExtInstance(); | ||
supportedCmds.put(handler.getCommand(), handler); | ||
if (LOGGER.isDebugEnabled()) { | ||
LOGGER.debug("Add telnet handler {}:{}.", handler.getCommand(), handler); | ||
} | ||
}); | ||
} | ||
}); | ||
return extensionLoader; | ||
} | ||
|
||
public static TelnetHandler getHandler(String command) { | ||
|
35 changes: 35 additions & 0 deletions
35
core/api/src/test/java/com/alipay/sofa/rpc/ext/DynamicFilter.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,35 @@ | ||
/* | ||
* 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.ext; | ||
|
||
import com.alipay.sofa.rpc.core.exception.SofaRpcException; | ||
import com.alipay.sofa.rpc.core.request.SofaRequest; | ||
import com.alipay.sofa.rpc.core.response.SofaResponse; | ||
import com.alipay.sofa.rpc.filter.Filter; | ||
import com.alipay.sofa.rpc.filter.FilterInvoker; | ||
|
||
/** | ||
* @author zhaowang | ||
* @version : DynamicFilter.java, v 0.1 2020年05月08日 1:59 下午 zhaowang Exp $ | ||
*/ | ||
@Extension("dynamic0") | ||
public class DynamicFilter extends Filter { | ||
@Override | ||
public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.