Skip to main content

--- Logic Server Introduction ---

Lock-free asynchronous and event-driven architecture; truly lightweight. You can build a distributed network communication server without any third-party middleware.

Built-in load balancing, distributed support, and dynamic machine scale-out/scale-in.

NameScaling ModeResponsibility
ExternalServerDistributedResponsible for user connections and interaction
LogicServerDistributedResponsible for specific business logic processing

ionet


From this architecture overview, we know the overall architecture consists of external services and logic services. They can run independently or be integrated together.

In the architecture diagram, logic server is the right-side part, LogicServer.

Introduction

The responsibility of the logic server is to handle concrete business logic, i.e., the actions we write.

How to Install

If you are trying the framework for the first time or want a quick overview, add the following to pom.xml. run-one already includes both external and logic servers.

pom.xml
<dependency>
<groupId>com.iohao.net</groupId>
<artifactId>run-one</artifactId>
<version>${ionet.version}</version>
</dependency>

In real development, it is recommended to create a separate module for logic server and add this dependency in pom.xml:

see https://central.sonatype.com/artifact/com.iohao.net/net-logic-server

pom.xml
<dependency>
<groupId>com.iohao.net</groupId>
<artifactId>net-logic-server</artifactId>
<version>${ionet.version}</version>
</dependency>

Create Logic Server

A Logic Server needs to implement the LogicServer interface. Two methods must be implemented:

  1. settingBarSkeletonBuilder: configure the business framework for the current logic server.
  2. settingServerBuilder: configure metadata for the current logic server.

  • code 5: scan the package where action classes are located. The framework scans all classes under the current package and sub-packages. No matter how many action classes you have, configuring any one class from that package is enough.
  • code 7: add the console output plugin.
  • code 12: set the logic server name.
public class DemoLogicServer implements LogicServer {
@Override
public void settingBarSkeletonBuilder(BarSkeletonBuilder builder) {
// Scan the package where the action classes are located
builder.scanActionPackage(DemoAction.class);
// Add console output plugin
builder.addInOut(new DebugInOut());
}

@Override
public void settingServerBuilder(ServerBuilder builder) {
builder.setName("DemoLogicServer");
}
}

startupSuccess

After logic server starts successfully, startupSuccess is executed. Developers can override it as needed, for example:

public class DemoLogicServer implements LogicServer {
...
@Override
public void startupSuccess(BarSkeleton barSkeleton) { {
// Server server = barSkeleton.server;
// EventBus eventBus = barSkeleton.eventBus;
}
}

Startup

  • code 5: set logic server list.
  • code 10: create logic servers to start.
final class TestOneApplication {
static void main() {
new RunOne()
...
.setLogicServerList(listLogic())
.startup();
}

static List<LogicServer> listLogic() {
return List.of(new DemoLogicServer());
}
}

Summary

Business logic in logic server is handled by business framework, so we mainly focus on settingBarSkeletonBuilder.