121 lines
3.3 KiB
Go
121 lines
3.3 KiB
Go
|
|
package notify
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"sort"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
type BulkSnapshot struct {
|
||
|
|
ID string
|
||
|
|
DataID uint64
|
||
|
|
Scope string
|
||
|
|
Range BulkRange
|
||
|
|
Metadata BulkMetadata
|
||
|
|
BindingOwner string
|
||
|
|
BindingAlive bool
|
||
|
|
BindingCurrent bool
|
||
|
|
BindingReason string
|
||
|
|
BindingError string
|
||
|
|
Dedicated bool
|
||
|
|
DedicatedAttached bool
|
||
|
|
SessionEpoch uint64
|
||
|
|
LogicalClientID string
|
||
|
|
TransportGeneration uint64
|
||
|
|
TransportAttached bool
|
||
|
|
TransportHasRuntimeConn bool
|
||
|
|
TransportCurrent bool
|
||
|
|
TransportDetachReason string
|
||
|
|
TransportDetachKind string
|
||
|
|
TransportDetachGeneration uint64
|
||
|
|
TransportDetachError string
|
||
|
|
TransportDetachedAt time.Time
|
||
|
|
ReattachEligible bool
|
||
|
|
LocalClosed bool
|
||
|
|
LocalReadClosed bool
|
||
|
|
RemoteClosed bool
|
||
|
|
PeerReadClosed bool
|
||
|
|
BufferedChunks int
|
||
|
|
BufferedBytes int
|
||
|
|
ReadTimeout time.Duration
|
||
|
|
WriteTimeout time.Duration
|
||
|
|
ChunkSize int
|
||
|
|
WindowBytes int
|
||
|
|
MaxInFlight int
|
||
|
|
BytesRead int64
|
||
|
|
BytesWritten int64
|
||
|
|
ReadCalls int64
|
||
|
|
WriteCalls int64
|
||
|
|
OpenedAt time.Time
|
||
|
|
LastReadAt time.Time
|
||
|
|
LastWriteAt time.Time
|
||
|
|
ResetError string
|
||
|
|
}
|
||
|
|
|
||
|
|
type clientBulkSnapshotReader interface {
|
||
|
|
clientBulkSnapshots() []BulkSnapshot
|
||
|
|
}
|
||
|
|
|
||
|
|
type serverBulkSnapshotReader interface {
|
||
|
|
serverBulkSnapshots() []BulkSnapshot
|
||
|
|
}
|
||
|
|
|
||
|
|
var (
|
||
|
|
errClientBulkSnapshotNil = errors.New("client bulk snapshot target is nil")
|
||
|
|
errServerBulkSnapshotNil = errors.New("server bulk snapshot target is nil")
|
||
|
|
errClientBulkSnapshotUnsupported = errors.New("client bulk snapshot target type is unsupported")
|
||
|
|
errServerBulkSnapshotUnsupported = errors.New("server bulk snapshot target type is unsupported")
|
||
|
|
)
|
||
|
|
|
||
|
|
func GetClientBulkSnapshots(c Client) ([]BulkSnapshot, error) {
|
||
|
|
if c == nil {
|
||
|
|
return nil, errClientBulkSnapshotNil
|
||
|
|
}
|
||
|
|
reader, ok := any(c).(clientBulkSnapshotReader)
|
||
|
|
if !ok {
|
||
|
|
return nil, errClientBulkSnapshotUnsupported
|
||
|
|
}
|
||
|
|
return reader.clientBulkSnapshots(), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetServerBulkSnapshots(s Server) ([]BulkSnapshot, error) {
|
||
|
|
if s == nil {
|
||
|
|
return nil, errServerBulkSnapshotNil
|
||
|
|
}
|
||
|
|
reader, ok := any(s).(serverBulkSnapshotReader)
|
||
|
|
if !ok {
|
||
|
|
return nil, errServerBulkSnapshotUnsupported
|
||
|
|
}
|
||
|
|
return reader.serverBulkSnapshots(), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (c *ClientCommon) clientBulkSnapshots() []BulkSnapshot {
|
||
|
|
return bulkSnapshotsFromRuntime(c.getBulkRuntime())
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *ServerCommon) serverBulkSnapshots() []BulkSnapshot {
|
||
|
|
return bulkSnapshotsFromRuntime(s.getBulkRuntime())
|
||
|
|
}
|
||
|
|
|
||
|
|
func bulkSnapshotsFromRuntime(runtime *bulkRuntime) []BulkSnapshot {
|
||
|
|
if runtime == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
return runtime.snapshots()
|
||
|
|
}
|
||
|
|
|
||
|
|
func sortBulkSnapshots(src []BulkSnapshot) {
|
||
|
|
sort.Slice(src, func(i, j int) bool {
|
||
|
|
if src[i].Scope != src[j].Scope {
|
||
|
|
return src[i].Scope < src[j].Scope
|
||
|
|
}
|
||
|
|
if src[i].ID != src[j].ID {
|
||
|
|
return src[i].ID < src[j].ID
|
||
|
|
}
|
||
|
|
if src[i].DataID != src[j].DataID {
|
||
|
|
return src[i].DataID < src[j].DataID
|
||
|
|
}
|
||
|
|
return src[i].TransportGeneration < src[j].TransportGeneration
|
||
|
|
})
|
||
|
|
}
|