Skip to content

Commit

Permalink
refactor(sample): 简化示例代码并移除未使用的函数
Browse files Browse the repository at this point in the history
- 移除了 DemoService 接口中的 sayHi2 方法
- 更新了 XxlRpcClientAplication 中的测试方法,使用 sayHi 方法替代 sayHi2- 简化了 DemoServiceImpl 中的 sayHi 方法实现
-
  • Loading branch information
xuxueli committed Dec 31, 2024
1 parent 487da88 commit 1dca166
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ public interface DemoService {

public UserDTO sayHi(String name);

public UserDTO sayHi2(UserDTO userDTO);

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ private static DemoService buildReferenceBean(XxlRpcBootstrap rpcBootstrap, Call
*/
public static void testSYNC(DemoService demoService) throws Exception {

// test
//UserDTO userDTO = demoService.sayHi("[SYNC]jack");
UserDTO userDTO = demoService.sayHi2(new UserDTO("[SYNC]jack", "hello"));
UserDTO userDTO = demoService.sayHi("[SYNC]jack");
System.out.println(userDTO);


Expand All @@ -103,9 +101,7 @@ public static void testSYNC(DemoService demoService) throws Exception {
* CallType.FUTURE
*/
public static void testFUTURE(DemoService demoService) throws Exception {
// test
//demoService.sayHi("[FUTURE]jack" );
demoService.sayHi2(new UserDTO("[FUTURE]jack", "hello"));
demoService.sayHi("[FUTURE]jack" );
Future<UserDTO> userDTOFuture = XxlRpcInvokeFuture.getFuture(UserDTO.class);
UserDTO userDTO = userDTOFuture.get();

Expand All @@ -117,7 +113,6 @@ public static void testFUTURE(DemoService demoService) throws Exception {
* CallType.CALLBACK
*/
public static void testCALLBACK(DemoService demoService) throws Exception {
// test
XxlRpcInvokeCallback.setCallback(new XxlRpcInvokeCallback<UserDTO>() {
@Override
public void onSuccess(UserDTO result) {
Expand All @@ -130,18 +125,15 @@ public void onFailure(Throwable exception) {
}
});

//demoService.sayHi("[CALLBACK]jack");
demoService.sayHi2(new UserDTO("[CALLBACK]jack", "hello"));
demoService.sayHi("[CALLBACK]jack");
}


/**
* CallType.ONEWAY
*/
public static void testONEWAY(DemoService demoService) throws Exception {
// test
//demoService.sayHi("[ONEWAY]jack");
demoService.sayHi2(new UserDTO("[ONEWAY]jack", "hello"));
demoService.sayHi("[ONEWAY]jack");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,10 @@ public class DemoServiceImpl implements DemoService {

@Override
public UserDTO sayHi(String name) {

String word = MessageFormat.format("Hi {0}, from {1} as {2}",
String word = MessageFormat.format("Hi {0}, this from {1} at {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;
}

@Override
public UserDTO sayHi2(UserDTO userDTO) {
UserDTO userDTO2 =new UserDTO("Jack", "Hi " + userDTO.getName());
logger.info(userDTO2.toString());
return userDTO2;

return new UserDTO(name, word);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ public class DemoServiceImpl implements DemoService {
@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.");
}

String word = MessageFormat.format("Hi {0}, this from {1} at {2}", name, DemoServiceImpl.class.getName(), String.valueOf(System.currentTimeMillis()));
UserDTO userDTO = new UserDTO(name, word);
logger.info(userDTO.toString());

//logger.info(userDTO.toString());
return userDTO;
}

Expand Down

0 comments on commit 1dca166

Please sign in to comment.