Funiture Technical Demonstration

repository·master·Indexed 23 days ago

https://github.com/kanwangzjm/funiture

A technical demonstration repository implementing backend patterns and features using the Spring framework. It showcases enterprise capabilities including permission management, system monitoring, service degradation, and distributed component integration. The project includes implementations for both SyncHttpClient and AsyncHttpClient, and utilizes a stack comprising JDK 1.8, Maven, MySQL, and Tomcat, with optional support for Redis, RabbitMQ, and Zookeeper.

Tokens
1.1K
Snippets
0
Records
9
Agent score
84%

What's inside Funiture

  1. Use Lombok Annotations in Funiture

    master

    The project heavily utilizes Lombok for boilerplate reduction. Ensure your IDE has the Lombok plugin installed. Common annotations used throughout the project include:

    • @Slf4j (for logging)
    • @Getter / @Setter
    • @ToString
    • @AllArgsConstructor
    • @NoArgsConstructor
    • @Builder
  2. Configure Development Environment for IntelliJ IDEA

    master

    It is strongly recommended to use IntelliJ IDEA as the development tool. If using Eclipse, manual configuration is required to function correctly.

    When starting the project, ensure you load the appropriate Resources folder based on your target environment:

    • resources
    • resource.dev (for development)
    • resource.prod (for production)
  3. Project Requirements and Dependencies

    master

    To run or develop with Funiture, ensure your environment meets the following requirements:

    Backend Requirements

    • JDK: 1.8 or higher
    • Build Tool: Maven for dependency management
    • Database: MySQL for storage
    • Server: Tomcat
    • Optional Components (Configurable):
      • Redis: Used for caching
      • RabbitMQ: Used for queuing
      • Zookeeper: Can be enabled in configuration
    • Development Tools: Requires Lombok support (e.g., IntelliJ IDEA or Eclipse with Lombok plugin).

    Frontend Stack

    Note: The frontend consists only of the management interface and uses:

    • jQuery framework
    • Bootstrap for styling
    • Mustache template engine
    • Ace for template rendering
    • zTree for jQuery tree plugins
    • duallistbox for multi-select functionality.
  4. Access the Management Interface

    master

    The management interface can be accessed directly via the following URL:

    /admin/page.do

    Authentication Note:

    • User passwords are stored using standard MD5 encryption.
    • For specific login implementation details, refer to LoginServlet.java in the source code.
  5. Configure AsyncHttpClient thread pool size

    master

    The AsyncHttpClient uses a static threadPool initialized at class loading. You can control the size of the fixed thread pool using the GlobalConfig system.

    Configuration Key:

    • HTTP_MAX_THREAD: An integer defining the maximum number of threads in the fixed thread pool.

    Behavior:

    • If HTTP_MAX_THREAD is set to a value greater than 0, a FixedThreadPool of that size is used.
    • If HTTP_MAX_THREAD is null or 0, a CachedThreadPool is used instead.
  6. Use AsyncHttpClient for non-blocking HTTP requests

    master

    The AsyncHttpClient provides asynchronous versions of standard HTTP methods using a thread pool. It returns ListenableFuture<ResponseWrapper> objects, allowing you to handle responses via callbacks without blocking the main execution flow.

    Important Constraints:

    • You cannot use synchronous methods like get(String uri) or post(String uri, String content) with this client; doing so will throw an UnsupportedOperationException. You must use the async prefixed methods.
    • The client uses a multi-threaded approach to simulate asynchronicity rather than non-blocking sockets.

    Available Asynchronous Methods:

    • asyncGet(String uri): Performs an asynchronous GET request.
    • asyncPost(String uri, String content): Performs an asynchronous POST request with a body.
    • asyncPost(String uri): Performs an asynchronous POST request without a body.
  7. Use SyncHttpClient for synchronous HTTP requests

    master

    The SyncHttpClient class provides a synchronous (blocking) interface for making HTTP GET and POST requests. It extends AbstractHttpClient and is designed for scenarios where the execution thread should wait for the web request to complete.

    Note that calling asynchronous methods like asyncGet or asyncPost on this client will result in an UnsupportedOperationException. Instead, use the direct get and post methods.

  8. SyncHttpClient methods and signatures

    master

    The SyncHttpClient provides the following public methods for synchronous operations:

    • ResponseWrapper get(String uri): Executes a synchronous GET request to the specified URI. Throws an error if the URI is null or empty.
    • ResponseWrapper post(String uri, String content): Executes a synchronous POST request to the specified URI with the provided string content. Throws an error if the URI or content is null or empty.
    • ResponseWrapper post(String uri): Executes a synchronous POST request to the specified URI with no content.

    Error Handling:

    • If an AuthSSLInitializationError occurs during the request, the client triggers the onAuthority callback.
    • For all other Throwable errors, the client triggers the onFailure callback.
    • All methods ensure the connection is released via method.releaseConnection() in a finally block.