Skip to main content

dawdler-core

Module Introduction​

Core module shared by dawdler-server and dawdler-client. It includes networking, the service discovery implementation, thread pools, annotations, compression algorithms, etc. (used internally by the system; users do not need to care about it). The individual annotations are documented in their respective modules.

1. Adding the dependency in pom​

<groupId>club.dawdler</groupId>
<artifactId>dawdler-core</artifactId>

2. ComponentLifeCycle container lifecycle interface​

Used to manage the before-start / after-start / destroy lifecycle of the client/server containers.

public interface ComponentLifeCycle {

default public void prepareInit() throws Throwable {
};

default public void init() throws Throwable {
};

default public void afterInit() throws Throwable {
};

default public void prepareDestroy() throws Throwable {
};

default public void destroy() throws Throwable {
};

default public void afterDestroy() throws Throwable {
};

}

On the client (tomcat) the order is prepareInit > WebContextListener > init

On the server (dawdler) the order is prepareInit > init > DawdlerServiceListener

See JedisLifeCycle.java, RabbitLifeCycle.java and similar component classes implementing this interface for concrete implementations.

3. CustomComponentInjector custom component injector​

Implement this interface to provide injection; refer to the other implementations.


public interface CustomComponentInjector {

/**
* Injection method
*/
public void inject(Class<?> type, Object target) throws Throwable;

/**
* Whether to inject
*/
default public boolean isInject() {
return true;
}

/**
* Matching classes or interfaces
*/
Class<?>[] getMatchTypes();

/**
* Matching annotations
*/
Set<? extends Class<? extends Annotation>> getMatchAnnotations();

/**
* Scan package paths (applies only to this injector)
*/
default String[] scanLocations() {
return new String[0];
}

/**
* Scan package paths (applies to all injectors, equivalent to packagePaths on the web and server sides)
*/
default String[] scanLocationsForAllInjector() {
return new String[0];
}

/**
* Whether to weave AOP into matching components
*/
default boolean useAop() {
return true;
}

/**
* Whether to store variable names in the ParameterNameReader class
*/
default boolean storeVariableNameByASM() {
return false;
}

default boolean requireInstantiation() {
return true;
}

default void afterScan() throws Throwable {
}

}

4. ContainerGracefulShutdown graceful container shutdown interface​

Graceful container shutdown interface; implements graceful container shutdown via SPI. See DawdlerServerGracefulShutdown.java

5. HealthIndicator health check interface​

Health check interface; implements container health checks via SPI. See JedisIndicator.java

6. System properties​

All properties below are JVM startup parameters (-D); defaults are used when not configured. Properties marked fail-fast on startup throw an exception and abort startup when configured with an illegal value (non-numeric or non-positive) instead of silently falling back to the default (so protection is not weakened by misconfiguration).

6.1 Protocol protection​

PropertyDefaultDescription
dawdler.max.frame.length8388608 (8MB)Maximum length of a single frame. Inbound frames over the limit are rejected (connection closed); outbound frames over the limit are rejected at the write entry point (IllegalArgumentException is thrown), guarding against oversized-frame memory attacks. If a server response exceeds the limit after serialization, it degrades to an error frame (cause=response too large, connection kept) instead of sending a frame the peer is bound to reject (fail-fast on startup)
dawdler.max.decompressed.length67108864 (64MB)Upper bound on the output of a single zlib decompression; decompression is aborted when exceeded, guarding against decompression bombs (fail-fast on startup)
-Ddawdler.max.frame.length=16777216
-Ddawdler.max.decompressed.length=134217728

6.2 Session read/write timeouts and backpressure (AbstractSocketSession)​

PropertyDefaultDescription
dawdler.core.write.stall.timeout10000Timeout for a single asynchronous write (ms). A write blocking longer than this is considered failed and triggers the reconnect flow; the timed-out frame's payload block is discarded for GC (the underlying write may still be in flight, so it must not be returned to the pool). Must be positive (fail-fast on startup)
dawdler.core.read.stall.timeout5000Timeout for a single asynchronous read (ms). A read blocking longer than this is considered failed. Must be positive (fail-fast on startup)
dawdler.core.read.frame.timeout30000Whole-frame deadline (ms), measured from the first byte of the frame to the last. Slow trickling/heartbeats do not extend it; on timeout the session is closed (fail-fast on startup)
dawdler.core.read.inflight.max.bytesmin(256MB, maxHeap/4)Global cap on in-flight bytes of incomplete large frames (>64KB); connections exceeding it are closed as invalid. 0 means unlimited. Accounting is based on borrowed block capacity (after tier rounding, never looser), not the declared length
dawdler.core.read.inflight.max.bytes.per.ipmax(1MB, min(32MB, global/8)); 32MB when the global value is 0Per-IP cap on in-flight bytes of incomplete large frames; 0 means unlimited
dawdler.core.write.queue.max.bytes8388608 (8MB)Per-session write queue byte limit (Semaphore backpressure). When the queue is full, business frame writes block and wait, while control frames such as heartbeats skip it. The effective value is at least 1024
dawdler.core.write.acquire.timeout30000Timeout (ms) for a business frame to acquire a backpressure permit when the write queue is saturated. On timeout a WriteBackpressureTimeoutException is thrown (stalled peer): the server closes the session, the client closes it and reconnects, so business threads are no longer occupied indefinitely by a slow peer
dawdler.core.idle.writer.millis8000Write idle detection period (ms); when idle, a SessionIdleType.WRITE notification is fired and a heartbeat is sent
dawdler.core.idle.reader.millis120000 (write idle × 15)Read idle detection period (ms); when idle, a SessionIdleType.READ notification is fired so the upper layer can determine the connection is dead and reconnect

6.3 Session direct buffer pool​

The session read buffer (128KiB) and outgoing frame header (256B) use off-heap native memory with two tiers of ArrayBlockingQueue idle caches. Each session borrows once and keeps reusing it, instead of borrowing and returning on every RPC/read callback. Borrowing is only poll(); on a miss memory is allocated outside the queue lock. On normal termination, once all in-flight accesses have completed, the block is reset and offer()ed; if the cache is full it exits reuse.

Native blocks are allocated with jdk.internal.misc.Unsafe.allocateMemory and wrapped in a reflectively constructed DirectByteBuffer(long,long), without registering a Cleaner with the JDK. Blocks leaving reuse (capacity above the tier / idle cache full / discard) are destroyed deterministically with freeMemory on the returning thread immediately, without waiting for GC; blocks in the idle cache are released by DirectBufferPool.clearIdle(). This requires the startup parameters --add-opens java.base/jdk.internal.misc=... --add-opens java.base/java.nio=...; when neither is available it degrades to ByteBuffer.allocateDirect (GC/Cleaner as a fallback) with no functional impact.

PropertyDefaultDescription
dawdler.core.session.buffer.pool.max.idle64Maximum number of idle blocks retained per exact capacity tier; the two tiers total about 8MiB. 0 disables the idle cache. Blocks are created on demand and not pre-filled; the number of active connections is not limited and nothing waits for an idle block to be returned