Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Risingwavelabs Risingwave CdcSourceChannel

From Leeroopedia
Revision as of 16:30, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Risingwavelabs_Risingwave_CdcSourceChannel.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

  • send returns boolean: true if the message was successfully sent to the channel, false otherwise.
  • sendError returns boolean: true if the error was successfully reported to the channel, false otherwise.

Side Effects

  • Channel communication: Both send and sendError deliver messages to the Rust-side streaming engine through the native channel.
  • Automatic cleanup: A Cleaner action is registered at construction time that calls Binding.cdcSourceSenderClose(pointer) when the object becomes phantom-reachable, ensuring native resources are released even if close is 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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment