github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/ctx_cluster.go (about)

     1  package kit
     2  
     3  import "github.com/clubpay/ronykit/kit/errors"
     4  
     5  var (
     6  	ErrClusterNotSet          = errors.New("cluster is not set")
     7  	ErrClusterMemberNotFound  = errors.New("cluster member not found")
     8  	ErrClusterMemberNotActive = errors.New("cluster member not active")
     9  )
    10  
    11  // ClusterStore returns a key-value store which is shared between different instances of the cluster.
    12  //
    13  // NOTE: If you don't set any Cluster for your EdgeServer, then this method will panic.
    14  // NOTE: If the cluster doesn't support key-value store, then this method will return nil.
    15  func (ctx *Context) ClusterStore() ClusterStore {
    16  	if ctx.sb == nil {
    17  		panic(ErrClusterNotSet)
    18  	}
    19  
    20  	s, ok := ctx.sb.cb.(ClusterWithStore)
    21  	if ok {
    22  		return s.Store()
    23  	}
    24  
    25  	return nil
    26  }
    27  
    28  // HasCluster returns true if the cluster is set for this EdgeServer.
    29  func (ctx *Context) HasCluster() bool {
    30  	return ctx.sb != nil
    31  }
    32  
    33  func (ctx *Context) ClusterID() string {
    34  	if ctx.sb == nil {
    35  		return ""
    36  	}
    37  
    38  	return ctx.sb.id
    39  }
    40  
    41  func (ctx *Context) ClusterMembers() ([]string, error) {
    42  	if ctx.sb == nil {
    43  		return nil, ErrClusterNotSet
    44  	}
    45  
    46  	return ctx.sb.cb.Subscribers()
    47  }