Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked from goudai/gd-rpc

goudai-rpc encapsulated using java the basic fundamental, minimize dependence, simple is the core idea

Notifications You must be signed in to change notification settings

walkersing/gd-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

51 Commits

Repository files navigation

###Nio实现细节架构图

Nio 架构图

单机RPC调用

rpc server

 public class ServerBootstrapTest {
 static {
 //1 init context
 Serializer serializer = new JavaSerializer();
 Context.<Request, Response>builder()
 .decoder(new DefaultDecoder<>(serializer))
 .encoder(new DefaultEncoder<>(serializer))
 .serializer(serializer)
 .channelHandler(new RequestHandler())
 .executorService(Executors.newFixedThreadPool(20, new NamedThreadFactory()))
 .build()
 .init();
 }
 public static void main(String[] args) throws Exception {
 // 2 init rpc server
 ServerBootstrap serverBootstrap = new ServerBootstrap(9999);
 //3 registry shutdown clean hook
 Runtime.getRuntime().addShutdownHook(new Thread(serverBootstrap::shutdown));
 //4 registry services..
 serverBootstrap.registry(UserService.class, new SimpleUserService());
 //5 started rpc server and await thread
 serverBootstrap.startup();
 }
 }

rpc client

 public class BootstrapTest {
 static {
 //1 init
 Serializer serializer = new JavaSerializer();
 Context.<Request, Response>builder()
 .decoder(new DefaultDecoder<>(serializer))
 .encoder(new DefaultEncoder<>(serializer))
 .serializer(serializer)
 .channelHandler(new ResponseHandler())
 .executorService(Executors.newFixedThreadPool(20, new NamedThreadFactory()))
 .build()
 .init();
 }
 public static void main(String[] args) throws Exception {
 //2 create client
 Bootstrap bootstrap = new Bootstrap("localhost", 9999);
 //3 started client
 bootstrap.startup();
 //4 get proxy service
 UserService service = bootstrap.getService(UserService.class);
 //5 remote invoker
 User add = service.add(new User());
 // out result
 System.out.println(add);
 //7 shutdown
 bootstrap.shutdown();
 }
 }

About

goudai-rpc encapsulated using java the basic fundamental, minimize dependence, simple is the core idea

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%

AltStyle によって変換されたページ (->オリジナル) /