Implementation:Risingwavelabs Risingwave CdcSourceChannel
| Property | Value |
|---|---|
| Component | Java Binding |
| Language | Java |
| Source File | java/java-binding/src/main/java/com/risingwave/java/binding/CdcSourceChannel.java
|
| Lines | 46 |
| Package | com.risingwave.java.binding
|
| License | Apache 2.0 |
Overview
CdcSourceChannel is a wrapper around a native pointer to a CDC (Change Data Capture) source message channel. It enables Java CDC source connectors to push change events into the RisingWave streaming engine via JNI.
The class holds a native channel pointer and uses a java.lang.ref.Cleaner for automatic resource cleanup. When the object becomes phantom-reachable, the cleaner triggers Binding.cdcSourceSenderClose to release the native channel resource. The class provides two communication methods: send for delivering serialized CDC messages, and sendError for reporting error conditions to the Rust engine.
Code Reference
Source Location
java/java-binding/src/main/java/com/risingwave/java/binding/CdcSourceChannel.java
Signature
public class CdcSourceChannel {
private final long pointer;
private static final Cleaner cleaner = Cleaner.create();
CdcSourceChannel(long pointer);
public static CdcSourceChannel fromOwnedPointer(long pointer);
public boolean send(byte[] msg);
public boolean sendError(String errorMsg);
}
Import
import com.risingwave.java.binding.CdcSourceChannel;
// Internal dependency:
import java.lang.ref.Cleaner;
I/O Contract
Inputs
- pointer (long): A native pointer to a Rust-side CDC source sender channel, passed at construction time via
fromOwnedPointer. Ownership of the pointer is transferred to this object. - msg (byte[]): A serialized CDC message (protobuf bytes) to send through the channel.
- errorMsg (String): An error message string to report to the Rust engine.
Outputs
sendreturnsboolean:trueif the message was successfully sent to the channel,falseotherwise.sendErrorreturnsboolean:trueif the error was successfully reported to the channel,falseotherwise.
Side Effects
- Channel communication: Both
sendandsendErrordeliver messages to the Rust-side streaming engine through the native channel. - Automatic cleanup: A
Cleaneraction is registered at construction time that callsBinding.cdcSourceSenderClose(pointer)when the object becomes phantom-reachable, ensuring native resources are released even ifcloseis not explicitly called.
Usage Examples
Creating a channel and sending CDC events
// Create channel from a native pointer received via JNI callback
CdcSourceChannel channel = CdcSourceChannel.fromOwnedPointer(nativeChannelPtr);
// Send a serialized CDC change event
byte[] cdcEvent = serializeCdcEvent(changeRecord);
boolean sent = channel.send(cdcEvent);
if (!sent) {
// Channel may be closed or full
handleSendFailure();
}
Reporting an error
try {
// Process CDC events...
channel.send(eventBytes);
} catch (Exception e) {
// Report the error to the Rust engine
channel.sendError("CDC source error: " + e.getMessage());
}
Related Pages
- Binding - Declares the native
sendCdcSourceMsgToChannel,sendCdcSourceErrorToChannel, andcdcSourceSenderClosemethods - JniDbzSourceHandler RunJniDbzSourceThread - Debezium CDC source handler that uses CdcSourceChannel to push events