本文整理汇总了Java中com.alibaba.dubbo.rpc.ServiceClassHolder类的典型用法代码示例。如果您正苦于以下问题:Java ServiceClassHolder类的具体用法?Java ServiceClassHolder怎么用?Java ServiceClassHolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceClassHolder类属于com.alibaba.dubbo.rpc包,在下文中一共展示了ServiceClassHolder类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportLocal
import com.alibaba.dubbo.rpc.ServiceClassHolder; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void exportLocal(URL url) {
if (!Constants.LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
URL local = URL.valueOf(url.toFullString())
.setProtocol(Constants.LOCAL_PROTOCOL)
.setHost(NetUtils.LOCALHOST)
.setPort(0);
// modified by lishen
ServiceClassHolder.getInstance().pushServiceClass(getServiceClass(ref));
Exporter<?> exporter = protocol.export(
proxyFactory.getInvoker(ref, (Class) interfaceClass, local));
exporters.add(exporter);
logger.info("Export dubbo service " + interfaceClass.getName() +" to local registry");
}
}
示例2: testRestProtocol
import com.alibaba.dubbo.rpc.ServiceClassHolder; //导入依赖的package包/类
@Test
public void testRestProtocol() throws InterruptedException {
RestService server = new RestServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
URL url = URL.valueOf("resteasy://127.0.0.1:5342/" + RestService.class.getName() + "?version=1.0.0&logger=slf4j");
ServiceClassHolder.getInstance().pushServiceClass(RestService.class);
Exporter<RestService> exporter = protocol.export(proxyFactory.getInvoker(server, RestService.class, url));
Invoker<RestService> invoker = protocol.refer(RestService.class, url);
RestService client = proxyFactory.getProxy(invoker);
RequestDto requestDto = new RequestDto();
requestDto.setAge(88);
requestDto.setName("doctor who");
ModelResult<String> modelResult = client.test(requestDto);
String expected = "test " + ToStringBuilder.reflectionToString(requestDto, ToStringStyle.SHORT_PREFIX_STYLE);
System.out.println(expected);
Assert.assertEquals(expected, modelResult.getData());
invoker.destroy();
// TimeUnit.MINUTES.sleep(1);
exporter.unexport();
}
示例3: doExport
import com.alibaba.dubbo.rpc.ServiceClassHolder; //导入依赖的package包/类
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
String addr = url.getIp() + ":" + url.getPort();
Class implClass = ServiceClassHolder.getInstance().popServiceClass();
RestServer server = servers.get(addr);
if (server == null) {
server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
server.start(url);
servers.put(addr, server);
}
String contextPath = getContextPath(url);
if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
if (servletContext == null) {
throw new RpcException("No servlet context found. Since you are using server='servlet', " +
"make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
}
String webappPath = servletContext.getContextPath();
if (StringUtils.isNotEmpty(webappPath)) {
webappPath = webappPath.substring(1);
if (!contextPath.startsWith(webappPath)) {
throw new RpcException("Since you are using server='servlet', " +
"make sure that the 'contextpath' property starts with the path of external webapp");
}
contextPath = contextPath.substring(webappPath.length());
if (contextPath.startsWith("/")) {
contextPath = contextPath.substring(1);
}
}
}
final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;
server.deploy(resourceDef, impl, contextPath);
final RestServer s = server;
return new Runnable() {
public void run() {
// TODO due to dubbo's current architecture,
// it will be called from registry protocol in the shutdown process and won't appear in logs
s.undeploy(resourceDef);
}
};
}
示例4: exportLocal
import com.alibaba.dubbo.rpc.ServiceClassHolder; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void exportLocal(URL url) {
if (!Constants.LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
URL local = URL.valueOf(url.toFullString()).setProtocol(Constants.LOCAL_PROTOCOL)
.setHost(NetUtils.LOCALHOST).setPort(0);
// modified by lishen
ServiceClassHolder.getInstance().pushServiceClass(getServiceClass(ref));
Exporter<?> exporter = protocol.export(proxyFactory.getInvoker(ref, (Class) interfaceClass, local));
exporters.add(exporter);
log.info("Export dubbo service " + interfaceClass.getName() + " to local registry");
}
}
示例5: doExport
import com.alibaba.dubbo.rpc.ServiceClassHolder; //导入依赖的package包/类
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
String addr = url.getIp() + ":" + url.getPort();
Class implClass = ServiceClassHolder.getInstance().popServiceClass();
RestServer server = servers.get(addr);
if (server == null) {
server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
server.start(url);
servers.put(addr, server);
}
String contextPath = getContextPath(url);
if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
if (servletContext == null) {
throw new RpcException("No servlet context found. Since you are using server='servlet', " +
"make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
}
String webappPath = servletContext.getContextPath();
if (StringUtils.isNotEmpty(webappPath)) {
webappPath = webappPath.substring(1);
if (!contextPath.startsWith(webappPath)) {
throw new RpcException("Since you are using server='servlet', " +
"make sure that the 'contextpath' property starts with the path of external webapp");
}
contextPath = contextPath.substring(webappPath.length());
if (contextPath.startsWith("/")) {
contextPath = contextPath.substring(1);
}
}
}
final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;
// dubbo 服务多版本
String version = url.getParameter(Constants.VERSION_KEY);
if (StringUtils.isNotEmpty(version)) {
contextPath = version + "/" + contextPath;
}
server.deploy(resourceDef, impl, contextPath);
final RestServer s = server;
return new Runnable() {
public void run() {
// TODO due to dubbo's current architecture,
// it will be called from registry protocol in the shutdown process and won't appear in logs
s.undeploy(resourceDef);
}
};
}
示例6: doExport
import com.alibaba.dubbo.rpc.ServiceClassHolder; //导入依赖的package包/类
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws JahhanException {
String addr = url.getIp() + ":" + url.getPort();
Class implClass = ServiceClassHolder.getInstance().popServiceClass();
RestServer server = servers.get(addr);
if (server == null) {
serverFactory.setHttpBinder(httpBinder);
server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
server.start(url);
servers.put(addr, server);
}
String contextPath = getContextPath(url);
if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
ServletContext servletContext = BaseContext.CTX.getServletContext(url.getPort());
if (servletContext == null) {
throw new JahhanException("No servlet context found. Since you are using server='servlet', "
+ "make sure that you've configured in web.xml");
}
String webappPath = servletContext.getContextPath();
if (StringUtils.isNotEmpty(webappPath)) {
webappPath = webappPath.substring(1);
if (!contextPath.startsWith(webappPath)) {
throw new JahhanException("Since you are using server='servlet', "
+ "make sure that the 'contextpath' property starts with the path of external webapp");
}
contextPath = contextPath.substring(webappPath.length());
if (contextPath.startsWith("/")) {
contextPath = contextPath.substring(1);
}
}
}
final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;
server.deploy(resourceDef, impl, contextPath);
final RestServer s = server;
return new Runnable() {
public void run() {
// TODO due to dubbo's current architecture,
// it will be called from registry protocol in the shutdown
// process and won't appear in logs
s.undeploy(resourceDef);
}
};
}