-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
212 additions
and
0 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
91 changes: 91 additions & 0 deletions
91
...sample-jfinal-server/src/main/java/com/xxl/rpc/sample/server/config/JFinalCoreConfig.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,91 @@ | ||
package com.xxl.rpc.sample.server.config; | ||
|
||
import com.jfinal.config.*; | ||
import com.jfinal.kit.Prop; | ||
import com.jfinal.kit.PropKit; | ||
import com.xxl.rpc.registry.impl.XxlRegistryServiceRegistry; | ||
import com.xxl.rpc.remoting.net.NetEnum; | ||
import com.xxl.rpc.remoting.provider.XxlRpcProviderFactory; | ||
import com.xxl.rpc.sample.api.DemoService; | ||
import com.xxl.rpc.sample.server.service.DemoServiceImpl; | ||
import com.xxl.rpc.serialize.Serializer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* @author xuxueli 2018-12-21 | ||
*/ | ||
public class JFinalCoreConfig extends JFinalConfig { | ||
private Logger logger = LoggerFactory.getLogger(JFinalCoreConfig.class); | ||
|
||
|
||
|
||
// ---------------------- xxl-rpc server ---------------------- | ||
|
||
private XxlRpcProviderFactory xxlRpcProviderFactory; | ||
private void initXxlRpcServer() throws Exception { | ||
|
||
// init invoker factory | ||
final Prop xxlJobProp = PropKit.use("xxl-rpc-sample.properties"); | ||
xxlRpcProviderFactory = new XxlRpcProviderFactory(); | ||
xxlRpcProviderFactory.initConfig(NetEnum.NETTY, Serializer.SerializeEnum.HESSIAN.getSerializer(), null, 7080, null, XxlRegistryServiceRegistry.class, new HashMap<String, String>(){{ | ||
put(XxlRegistryServiceRegistry.XXL_REGISTRY_ADDRESS, xxlJobProp.get("xxl-rpc.registry.xxlregistry.address")); | ||
put(XxlRegistryServiceRegistry.ENV, xxlJobProp.get("xxl-rpc.registry.xxlregistry.env")); | ||
}}); | ||
|
||
// add services | ||
xxlRpcProviderFactory.addService(DemoService.class.getName(), null, new DemoServiceImpl()); | ||
|
||
// start | ||
xxlRpcProviderFactory.start(); | ||
} | ||
private void destoryXxlRpcServer() throws Exception { | ||
xxlRpcProviderFactory.stop(); | ||
} | ||
|
||
|
||
// ---------------------- jfinal ---------------------- | ||
|
||
@Override | ||
public void afterJFinalStart() { | ||
try { | ||
initXxlRpcServer(); | ||
} catch (Exception e) { | ||
logger.error(e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeJFinalStop() { | ||
try { | ||
destoryXxlRpcServer(); | ||
} catch (Exception e) { | ||
logger.error(e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public void configRoute(Routes routes) { | ||
|
||
} | ||
|
||
public void configConstant(Constants constants) { | ||
|
||
} | ||
|
||
public void configPlugin(Plugins plugins) { | ||
|
||
} | ||
|
||
public void configInterceptor(Interceptors interceptors) { | ||
|
||
} | ||
|
||
public void configHandler(Handlers handlers) { | ||
|
||
} | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...sample-jfinal-server/src/main/java/com/xxl/rpc/sample/server/service/DemoServiceImpl.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,30 @@ | ||
package com.xxl.rpc.sample.server.service; | ||
|
||
import com.xxl.rpc.sample.api.DemoService; | ||
import com.xxl.rpc.sample.api.dto.UserDTO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.text.MessageFormat; | ||
|
||
/** | ||
* @author xuxueli | ||
*/ | ||
public class DemoServiceImpl implements DemoService { | ||
private static Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class); | ||
|
||
@Override | ||
public UserDTO sayHi(String name) { | ||
|
||
String word = MessageFormat.format("Hi {0}, from {1} as {2}", | ||
name, DemoServiceImpl.class.getName(), String.valueOf(System.currentTimeMillis())); | ||
|
||
if ("error".equalsIgnoreCase(name)) throw new RuntimeException("test exception."); | ||
|
||
UserDTO userDTO = new UserDTO(name, word); | ||
logger.info(userDTO.toString()); | ||
|
||
return userDTO; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...executor-sample-jfinal/xxl-rpc-executor-sample-jfinal-server/src/main/resources/log4j.xml
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd"> | ||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" threshold="null" debug="null"> | ||
|
||
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> | ||
<param name="Target" value="System.out" /> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-rpc-executor-sample-jfinal-server [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender"> | ||
<param name="file" value="/data/applogs/xxl-rpc/xxl-rpc-executor-sample-jfinal-server.log"/> | ||
<param name="append" value="true"/> | ||
<param name="encoding" value="UTF-8"/> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-rpc-executor-sample-jfinal-server [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<root> | ||
<level value="INFO" /> | ||
<appender-ref ref="CONSOLE" /> | ||
<appender-ref ref="FILE" /> | ||
</root> | ||
|
||
</log4j:configuration> |
3 changes: 3 additions & 0 deletions
3
...jfinal/xxl-rpc-executor-sample-jfinal-server/src/main/resources/xxl-rpc-sample.properties
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,3 @@ | ||
# xxl-rpc | ||
xxl-rpc.registry.xxlregistry.address=http://localhost:8080/xxl-registry-admin | ||
xxl-rpc.registry.xxlregistry.env=default |
28 changes: 28 additions & 0 deletions
28
...cutor-sample-jfinal/xxl-rpc-executor-sample-jfinal-server/src/main/webapp/WEB-INF/web.xml
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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
id="WebApp_ID" version="2.5"> | ||
|
||
<display-name>xxl-rpc-executor-sample-jfinal-client</display-name> | ||
<context-param> | ||
<param-name>webAppRootKey</param-name> | ||
<param-value>xxl-rpc-executor-sample-jfinal-client</param-value> | ||
</context-param> | ||
|
||
<!-- jfinal --> | ||
<filter> | ||
<filter-name>jfinal</filter-name> | ||
<filter-class>com.jfinal.core.JFinalFilter</filter-class> | ||
<init-param> | ||
<param-name>configClass</param-name> | ||
<param-value>com.xxl.rpc.sample.server.config.JFinalCoreConfig</param-value> | ||
</init-param> | ||
</filter> | ||
<filter-mapping> | ||
<filter-name>jfinal</filter-name> | ||
<url-pattern>/*</url-pattern> | ||
</filter-mapping> | ||
|
||
|
||
</web-app> |