# The C# ClusterConnection Class

### For an overview see page C# Classes

## Class Definition

        public class ClusterConnection : Connection
        {
            // ===== CONSTRUCTOR =====
            public ClusterConnection(Database db);

            // ===== CLUSTER LIFECYCLE METHODS =====
            public void Listen();
            public void Barrier();
            public void Detach();
            public void Stop();

            // ===== CLUSTER INFORMATION METHODS =====
            public Database.ClusterInfo GetInfo();
            public Database.ClusterNodeInfo[] GetActiveNodes();

            // ===== WINDOW CONFIGURATION METHODS =====
            public void SetWindowParams(Database.ClusterWindow WindowParam);
            public Database.ClusterWindow GetWindowParams();

            // ===== DATA DISTRIBUTION METHODS =====
            public bool Scatter(Type[] classes, int[] nodeIds);
            public bool Scatter(Type[] classes);
            public bool Scatter();

            public bool Gather(Type[] classes, int[] nodeIds);
            public bool Gather(Type[] classes);
            public bool Gather();

            // ===== CLUSTER ATTACHMENT =====
            public void Attach(Database.ClusterParams clusterParams);
        }

## Member Descriptions

ClusterConnection(Database)
Creates a cluster connection instance for the specified database. The database must be configured for clustered operation. Use this connection to manage node participation in the eXtremeDB cluster.
Listen()
Starts listening for incoming connections from other cluster nodes. This node becomes available for cluster communication and data synchronization after this call.
Barrier()
Synchronizes this node with all other active cluster nodes. Blocks until all nodes reach the same synchronization point. Useful for coordinating schema changes or bulk operations across the cluster.
Detach()
Gracefully removes this node from the cluster. Pending operations are completed, data is synchronized if needed, and the node stops participating in cluster communication.
Stop()
Immediately stops cluster operations on this node. Use for emergency shutdown scenarios where graceful detachment is not possible. May result in data inconsistency if not followed by recovery procedures.
GetInfo()
Returns comprehensive cluster status information via the `Database.ClusterInfo` structure, including node count, replication state, and synchronization metrics.
GetActiveNodes()
Returns an array of `Database.ClusterNodeInfo` structures describing all currently active nodes in the cluster: node IDs, addresses, roles, and connection status.
SetWindowParams(Database.ClusterWindow)
Configures replication window parameters for this node: buffer sizes, commit batching, and synchronization intervals. Affects how changes are propagated to other cluster nodes.
GetWindowParams()
Returns the current replication window configuration for this node via the `Database.ClusterWindow` structure.
Scatter(Type[], int[])
Distributes instances of specified classes across designated cluster nodes. `classes` defines which data types to scatter; `nodeIds` specifies target nodes. Returns `true` on success.
Scatter(Type[]) / Scatter()
Overloads for simplified scattering: scatter specified classes across all nodes, or scatter all cluster-enabled classes using default distribution policy.
Gather(Type[], int[])
Collects instances of specified classes from designated cluster nodes to this node. Reverse operation of `Scatter()`. Useful for consolidation, backup, or migration scenarios.
Gather(Type[]) / Gather()
Overloads for simplified gathering: gather specified classes from all nodes, or gather all cluster-enabled classes using default collection policy.
Attach(Database.ClusterParams)
Joins this node to an existing cluster using the specified configuration parameters: peer addresses, replication mode, authentication, and failover settings.
Cluster Topology
eXtremeDB clusters support both horizontal sharding (via `Scatter/Gather`) and replication. Nodes can serve as masters, replicas, or hybrid roles depending on configuration.
Data Distribution Strategy
Use `Scatter()` to partition large datasets across nodes for scalability. Use `Gather()` for analytics, backups, or reorganization. Both operations preserve referential integrity within scattered classes.
Synchronization Guarantees
`Barrier()` ensures all nodes have processed transactions up to the call point. Combine with `GetInfo()` to verify cluster consistency before critical operations.
Graceful Shutdown
Preferred shutdown sequence: `Detach()` → wait for completion → `Stop()` (if needed) → close connection. This minimizes data loss and simplifies re-attachment.
Thread Safety
`ClusterConnection` instances are not thread-safe. Use one instance per thread. Cluster management operations should be coordinated externally to avoid conflicting topology changes.
Error Handling
Scatter/Gather operations return `false` on failure (e.g., node unreachable, insufficient resources). Check `GetInfo()` and node logs for detailed error diagnostics.
Configuration Persistence
Cluster parameters set via `Attach()` and `SetWindowParams()` apply to the current session. For persistent configuration, update the database schema or use external configuration management.