zfoo Framework

repository·main·Indexed 24 days ago

https://github.com/zfoo-project/zfoo

An asynchronous, actor-based, and lock-free universal RPC framework designed for high-performance applications like game servers and real-time web services. It features native GraalVM support and includes integrated modules for hot-swapping code, an annotation-based event bus, MongoDB ORM with caching and persistence policies, and system monitoring utilities (CPU, memory, disk, network). It provides a high-performance serialization protocol requiring JDK 17+ and offers Spring Boot integration via zfoo-boot.

Tokens
11.3K
Snippets
24
Records
67
Agent score
81%

What's inside zfoo

  1. Overview of zfoo scheduler

    main

    The zfoo-scheduler is a time-based task scheduling bus. It uses the Spring-provided interpreter pattern for parsing Cron expressions.

    Key characteristics:

    • Time Adjustment Sensitivity: Adjusting the local machine's time (forward or backward) will trigger task scheduling, which is useful for local development.
    • Single-Threaded Execution: The scheduler uses a single ScheduledExecutorService thread that executes a triggerPerSecond() method once every second to iterate through schedulers.
    • Performance: It uses Javassist bytecode enhancement technology to dynamically proxy scheduled tasks, avoiding reflection and minimizing performance overhead.

    Important Usage Note: Because the scheduler uses only a single thread, users must avoid performing time-consuming or blocking operations directly within the scheduled task. If a task requires heavy processing, it should be handed off to a separate thread pool.

  2. Overview of zfoo ORM

    main
    zfoo ORM is a mapping framework based on MongoDB that provides mapping between POJO (Plain Old Java Object) entities and MongoDB databases. It provides a simplified wrapper around the official MongoDB driver, allowing users to choose between low-level native operations, middle-level accessor/query interfaces, or high-level cache-based persistence.
  3. Overview of zfoo storage

    main

    zfoo storage is a Java framework for automatic mapping between Java POJOs (or Records) and Excel, CSV, or JSON files. It leverages Java reflection to parse data files without requiring manual parsing code.

    Key features:

    • Automatic Mapping: Define a Java class, and the framework handles the parsing of Excel, JSON, or CSV files.
    • Null Safety: Arrays and collections are handled safely; empty collections/arrays resolve to length 0 rather than null.
    • Data Normalization: Empty strings are parsed as length 0 strings, and empty objects are parsed as null.
    • Export Support: Supports exporting Excel data to JSON or CSV formats.
  4. Overview of zfoo net RPC framework

    main

    zfoo net is a high-performance, asynchronous RPC framework designed with Actor-based design principles and a lock-free architecture. It is suitable for scenarios requiring extreme performance, such as online games or high-concurrency microservices. It supports TCP, UDP, and WebSocket protocols and follows an MVC-style usage pattern based on Spring.

    Key features include:

    • Asynchronous/Synchronous Support: Elegant handling of both request types.
    • Service Discovery: Uses Zookeeper for service registration and discovery (extensible to other registries).
    • High-Performance Gateway: Includes a built-in gateway with customizable forwarding strategies.
    • Scalability: Supports load balancing, cluster monitoring, and service scaling.
  5. Use zfoo with Spring Boot via zfoo-boot

    main
    The zfoo-boot module provides Spring Boot auto-configuration support for the zfoo framework. This allows developers to easily integrate zfoo into a Spring Boot application by leveraging Spring's auto-configuration mechanism, reducing the manual setup required to bootstrap a zfoo-powered service.
  6. What is the zfoo event bus and how does it work?

    main

    The event module provides an event bus designed to decouple different modules and improve code quality using the Observer design pattern.

    Key characteristics:

    • Decoupling: It allows modules to interact without direct dependencies, similar to how hardware buses reduce complexity between CPU, memory, and I/O devices.
    • Annotation-based: It implements the event bus using simple annotations for ease of use.
    • High Performance: It utilizes Javassist bytecode enhancement for dynamic proxying of event receivers. This avoids the performance overhead typically associated with reflection.
  7. What is the zfoo event bus?

    main

    The zfoo event bus is a module designed to decouple different software modules and improve code quality by implementing the observer design pattern. It facilitates interaction between loosely coupled modules in a large-scale system using a publisher-subscriber model.

    Key technical characteristics:

    • Implementation: Uses a simple annotation-based approach to define event receivers.
    • Performance: Utilizes Javassist bytecode enhancement technology to dynamically proxy event receivers. This avoids the performance overhead typically associated with reflection.
  8. What is the zfoo scheduler?

    main
    The zfoo scheduler is a time task scheduling bus. It uses Spring's cron expression interpreter pattern for parsing and leverages Javassist bytecode enhancement technology to dynamically proxy scheduling tasks. This approach avoids reflection, ensuring there is no performance loss during task execution.
  9. Map Excel files to Java classes

    main

    To map an Excel file to a Java object, ensure the Excel structure follows these rules:

    1. The first row of the Excel file must correspond to the Java class property names.
    2. The first column must be the Id property.
    3. The second and third rows are ignored and do not act as comments.

    You can use standard Java classes or the newer Java record type for your data models.

  10. Understand the difference between IRouter and IConsumer

    main

    The net module provides two layers of API interfaces for network communication:

    1. IRouter (Low-level API): The underlying network interface. It is used to send messages directly through a Session connection.
    2. IConsumer (High-level API): An encapsulation of IRouter. It is used by consumers to send RPC messages to a service provider.
  11. Implement distributed server monitoring

    main

    You can build a distributed monitoring system by embedding the OSUtils static class calls into your Java programs. To implement this:

    1. Collect main server data (CPU, memory, disk, network) using OSUtils every second or minute.
    2. Upload the collected data to a database or a central monitoring server.
    3. Use the stored data to analyze performance, trigger alarms, or generate visual charts.
  12. Configure automatic mapping for Excel files

    main

    To map an Excel file to a Java class, follow these structural rules:

    1. Header Mapping: The first line of the Excel file must correspond to the Java class attribute names.
    2. Metadata Lines: The second and third lines of the Excel file are treated as metadata (not comments).
    3. Primary Key: The first column of the Excel file must be the Id attribute.

    You can use standard Java POJOs or the newer Java record classes for your data models.