Skip to content

Commit b6e2d28

Browse files
author
Tim Middleton
authored
Minor examples updates (#21)
* Minor examples updates * godoc updates
1 parent ed00cf0 commit b6e2d28

File tree

20 files changed

+460
-682
lines changed

20 files changed

+460
-682
lines changed

coherence/cache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type NamedMap[K comparable, V any] interface {
9898

9999
// EntrySet returns a channel from which all entries can be obtained.
100100
// Note: the entries are paged internally to avoid excessive memory usage, but you need to be
101-
// carefull when running this operation against NamedMaps with large number of entries.
101+
// careful when running this operation against NamedMaps with large number of entries.
102102
EntrySet(ctx context.Context) <-chan *StreamedEntry[K, V]
103103

104104
// Get returns the value to which the specified key is mapped. V will be nil if there was no previous value.
@@ -125,7 +125,7 @@ type NamedMap[K comparable, V any] interface {
125125

126126
// KeySet returns a channel from which keys of all entries can be obtained.
127127
// Note: the entries are paged internally to avoid excessive memory usage, but you need to be
128-
// carefull when running this operation against NamedMaps with large number of entries.
128+
// careful when running this operation against NamedMaps with large number of entries.
129129
KeySet(ctx context.Context) <-chan *StreamedKey[K]
130130

131131
// Name returns the name of the NamedMap.
@@ -183,7 +183,7 @@ type NamedMap[K comparable, V any] interface {
183183

184184
// Values return a view of all values contained in this NamedMap.
185185
// Note: the entries are paged internally to avoid excessive memory usage, but you need to be
186-
// carefull when running this operation against NamedMaps with large number of entries.
186+
// careful when running this operation against NamedMaps with large number of entries.
187187
Values(ctx context.Context) <-chan *StreamedValue[V]
188188

189189
getBaseClient() *baseClient[K, V]

coherence/common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222
)
2323

2424
const (
25-
envHostName = "COHERENCE_SERVER_HOST_NAME"
26-
envGRPCPort = "COHERENCE_SERVER_GRPC_PORT"
25+
envHostName = "COHERENCE_SERVER_ADDRESS"
2726
envTLSCertPath = "COHERENCE_TLS_CERTS_PATH"
2827
envTLSClientCert = "COHERENCE_TLS_CLIENT_CERT"
2928
envTLSClientKey = "COHERENCE_TLS_CLIENT_KEY"

coherence/doc.go

Lines changed: 111 additions & 177 deletions
Large diffs are not rendered by default.

coherence/event.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ type MapEvent[K comparable, V any] interface {
192192
Type() MapEventType
193193
}
194194

195-
// mapEvent struct containing data members to satisfy the MapEvent contract.
195+
// mapEvent struct containing data members to satisfy the [MapEvent] contract.
196196
type mapEvent[K comparable, V any] struct {
197197
// source the source of the event
198198
source NamedMap[K, V]
@@ -219,7 +219,7 @@ type mapEvent[K comparable, V any] struct {
219219
newValue *V
220220
}
221221

222-
// newMapEvent creates and returns a pointer to a new mapEvent.
222+
// newMapEvent creates and returns a pointer to a new [M apEvent].
223223
func newMapEvent[K comparable, V any](source NamedMap[K, V], response *proto.MapEventResponse) *mapEvent[K, V] {
224224
return &mapEvent[K, V]{
225225
source: source,
@@ -280,17 +280,17 @@ func (e *mapEvent[K, V]) NewValue() (*V, error) {
280280
return e.newValue, nil
281281
}
282282

283-
// Type returns the MapEventType for this MapEvent.
283+
// Type returns the MapEventType for this [MapEvent].
284284
func (e *mapEvent[K, V]) Type() MapEventType {
285285
return e.eventType
286286
}
287287

288-
// Source returns the source of this MapEvent.
288+
// Source returns the source of this [MapEvent].
289289
func (e *mapEvent[K, V]) Source() NamedMap[K, V] {
290290
return e.source
291291
}
292292

293-
// String returns the string representation of this MapEvent.
293+
// String returns the string representation of this [MapEvent].
294294
func (e *mapEvent[K, V]) String() string {
295295
source := e.source
296296
key, keyErr := e.Key()
@@ -334,44 +334,44 @@ func (sl *sessionLifecycleListener) getEmitter() *eventEmitter[SessionLifecycleE
334334
return sl.emitter
335335
}
336336

337-
// NewSessionLifecycleListener creates and returns a pointer to a new SessionLifecycleListener instance.
337+
// NewSessionLifecycleListener creates and returns a pointer to a new [SessionLifecycleListener] instance.
338338
func NewSessionLifecycleListener() SessionLifecycleListener {
339339
return &sessionLifecycleListener{newEventEmitter[SessionLifecycleEventType, SessionLifecycleEvent]()}
340340
}
341341

342-
// on registers a callback for the specified MapEventType
342+
// on registers a callback for the specified [MapEventType].
343343
func (sl *sessionLifecycleListener) on(event SessionLifecycleEventType, callback func(SessionLifecycleEvent)) SessionLifecycleListener {
344344
sl.emitter.on(event, callback)
345345
return sl
346346
}
347347

348-
// OnConnected registers a callback that will be notified when a Session is connected.
348+
// OnConnected registers a callback that will be notified when a [Session] is connected.
349349
func (sl *sessionLifecycleListener) OnConnected(callback func(SessionLifecycleEvent)) SessionLifecycleListener {
350350
return sl.on(Connected, callback)
351351
}
352352

353-
// OnDisconnected registers a callback that will be notified when a Session is disconnected.
353+
// OnDisconnected registers a callback that will be notified when a [Session] is disconnected.
354354
func (sl *sessionLifecycleListener) OnDisconnected(callback func(SessionLifecycleEvent)) SessionLifecycleListener {
355355
return sl.on(Disconnected, callback)
356356
}
357357

358-
// OnReconnected registers a callback that will be notified when a Session is reconnected.
358+
// OnReconnected registers a callback that will be notified when a [Session] is reconnected.
359359
func (sl *sessionLifecycleListener) OnReconnected(callback func(SessionLifecycleEvent)) SessionLifecycleListener {
360360
return sl.on(Reconnected, callback)
361361
}
362362

363-
// OnClosed registers a callback that will be notified when a Session is closed.
363+
// OnClosed registers a callback that will be notified when a [Session] is closed.
364364
func (sl *sessionLifecycleListener) OnClosed(callback func(SessionLifecycleEvent)) SessionLifecycleListener {
365365
return sl.on(Closed, callback)
366366
}
367367

368-
// OnAny registers a callback that will be notified when a Session is connected, disconnected, reconnected or closed.
368+
// OnAny registers a callback that will be notified when a [Session] is connected, disconnected, reconnected or closed.
369369
func (sl *sessionLifecycleListener) OnAny(callback func(SessionLifecycleEvent)) SessionLifecycleListener {
370370
return sl.on(Closed, callback).OnConnected(callback).OnDisconnected(callback).OnReconnected(callback)
371371
}
372372

373373
// MapLifecycleListener allows registering callbacks to be notified when lifecycle events
374-
// (truncated or released) occur against a NamedMap or NamedCache.
374+
// (truncated or released) occur against a [NamedMap] or [NamedCache].
375375
type MapLifecycleListener[K comparable, V any] interface {
376376
OnAny(callback func(MapLifecycleEvent[K, V])) MapLifecycleListener[K, V]
377377
OnDestroyed(callback func(MapLifecycleEvent[K, V])) MapLifecycleListener[K, V]
@@ -388,7 +388,7 @@ func (l *mapLifecycleListener[K, V]) getEmitter() *eventEmitter[MapLifecycleEven
388388
return l.emitter
389389
}
390390

391-
// NewMapLifecycleListener creates and returns a pointer to a new MapLifecycleListener instance.
391+
// NewMapLifecycleListener creates and returns a pointer to a new [MapLifecycleListener] instance.
392392
func NewMapLifecycleListener[K comparable, V any]() MapLifecycleListener[K, V] {
393393
return &mapLifecycleListener[K, V]{newEventEmitter[MapLifecycleEventType, MapLifecycleEvent[K, V]]()}
394394
}
@@ -399,28 +399,28 @@ func (l *mapLifecycleListener[K, V]) on(event MapLifecycleEventType, callback fu
399399
return l
400400
}
401401

402-
// OnDestroyed registers a callback that will be notified when a NamedMap is destroyed.
402+
// OnDestroyed registers a callback that will be notified when a [NamedMap] is destroyed.
403403
func (l *mapLifecycleListener[K, V]) OnDestroyed(callback func(MapLifecycleEvent[K, V])) MapLifecycleListener[K, V] {
404404
return l.on(Destroyed, callback)
405405
}
406406

407-
// OnTruncated registers a callback that will be notified when a NamedMap is truncated.
407+
// OnTruncated registers a callback that will be notified when a [NamedMap] is truncated.
408408
func (l *mapLifecycleListener[K, V]) OnTruncated(callback func(MapLifecycleEvent[K, V])) MapLifecycleListener[K, V] {
409409
return l.on(Truncated, callback)
410410
}
411411

412-
// OnReleased registers a callback that will be notified when a NamedMap is released.
412+
// OnReleased registers a callback that will be notified when a [NamedMap] is released.
413413
func (l *mapLifecycleListener[K, V]) OnReleased(callback func(MapLifecycleEvent[K, V])) MapLifecycleListener[K, V] {
414414
return l.on(Released, callback)
415415
}
416416

417-
// OnAny registers a callback that will be notified when any NamedMap event occurs.
417+
// OnAny registers a callback that will be notified when any [NamedMap] event occurs.
418418
func (l *mapLifecycleListener[K, V]) OnAny(callback func(MapLifecycleEvent[K, V])) MapLifecycleListener[K, V] {
419419
return l.OnTruncated(callback).OnDestroyed(callback).OnReleased(callback)
420420
}
421421

422422
// MapListener allows registering callbacks to be notified when mutations events
423-
// occur within a NamedMap or NamedCache.
423+
// occur within a [NamedMap] or [NamedCache].
424424
type MapListener[K comparable, V any] interface {
425425
OnInserted(callback func(MapEvent[K, V])) MapListener[K, V]
426426
OnUpdated(callback func(MapEvent[K, V])) MapListener[K, V]
@@ -429,12 +429,12 @@ type MapListener[K comparable, V any] interface {
429429
dispatch(event MapEvent[K, V])
430430
}
431431

432-
// mapListener struct containing data members to satisfy the MapListener contract.
432+
// mapListener struct containing data members to satisfy the [MapListener] contract.
433433
type mapListener[K comparable, V any] struct {
434434
emitter *eventEmitter[MapEventType, MapEvent[K, V]]
435435
}
436436

437-
// NewMapListener creates and returns a pointer to a new MapListener instance.
437+
// NewMapListener creates and returns a pointer to a new [MapListener] instance.
438438
func NewMapListener[K comparable, V any]() MapListener[K, V] {
439439
return &mapListener[K, V]{newEventEmitter[MapEventType, MapEvent[K, V]]()}
440440
}
@@ -444,7 +444,7 @@ func (l *mapListener[K, V]) dispatch(event MapEvent[K, V]) { //nolint
444444
l.emitter.emit(event.Type(), event)
445445
}
446446

447-
// on registers a callback for the specified MapEventType
447+
// on registers a callback for the specified [MapEventType].
448448
func (l *mapListener[K, V]) on(event MapEventType, callback func(MapEvent[K, V])) MapListener[K, V] {
449449
l.emitter.on(event, callback)
450450
return l
@@ -483,9 +483,9 @@ type listenerGroup[K comparable, V any] struct {
483483
postUnsubscribe func()
484484
}
485485

486-
// addListener registers the specified MapListener to this group. The lite
486+
// addListener registers the specified [MapListener] to this group. The lite
487487
// flag is a hint to the Coherence cluster that an event may omit the old
488-
// and new values when emitting a MapEvent.
488+
// and new values when emitting a [MapEvent].
489489
func (lg *listenerGroup[K, V]) addListener(ctx context.Context, listener MapListener[K, V], lite bool) error {
490490
prevLiteStatus, hasKey := lg.listeners[listener]
491491
if hasKey && prevLiteStatus == lite {
@@ -541,7 +541,7 @@ func (lg *listenerGroup[K, V]) removeListener(ctx context.Context, listener MapL
541541
return nil
542542
}
543543

544-
// notify notifies all listeners of the provided MapEvent.
544+
// notify notifies all listeners of the provided [MapEvent].
545545
func (lg *listenerGroup[K, V]) notify(event MapEvent[K, V]) {
546546
if len(lg.listeners) > 0 {
547547
for l := range lg.listeners {
@@ -566,7 +566,7 @@ func (lg *listenerGroup[K, V]) write(request *proto.MapListenerRequest) error {
566566
}
567567

568568
// subscribe this group. The lite flag is a hint to the Coherence cluster
569-
// that an event may omit the old and new values when emitting a MapEvent.
569+
// that an event may omit the old and new values when emitting a [MapEvent].
570570
func (lg *listenerGroup[K, V]) subscribe(ctx context.Context, lite bool) error {
571571
lg.request.Lite = lite
572572
lg.request.Subscribe = true
@@ -708,7 +708,7 @@ type pendingListenerOp[K comparable, V any] struct {
708708
}
709709

710710
// newMapEventManager creates/initializes and returns a pointer to a new
711-
// mapEventManager
711+
// mapEventManager.
712712
func newMapEventManager[K comparable, V any](namedMap *NamedMap[K, V], bc baseClient[K, V], session *Session) (*mapEventManager[K, V], error) {
713713
manager := mapEventManager[K, V]{
714714
bc: bc,
@@ -744,7 +744,7 @@ func (m *mapEventManager[K, V]) close() {
744744
m.namedMap = nil
745745
}
746746

747-
// addLifecycleListener adds the specified MapLifecycleListener.
747+
// addLifecycleListener adds the specified [MapLifecycleListener].
748748
func (m *mapEventManager[K, V]) addLifecycleListener(listener MapLifecycleListener[K, V]) {
749749
for _, e := range m.lifecycleListeners {
750750
if *e == listener {
@@ -754,7 +754,7 @@ func (m *mapEventManager[K, V]) addLifecycleListener(listener MapLifecycleListen
754754
m.lifecycleListeners = append(m.lifecycleListeners, &listener)
755755
}
756756

757-
// removeLifecycleListener removes the specified MapLifecycleListener.
757+
// removeLifecycleListener removes the specified [MapLifecycleListener].
758758
func (m *mapEventManager[K, V]) removeLifecycleListener(listener MapLifecycleListener[K, V]) {
759759
idx := -1
760760
listeners := m.lifecycleListeners
@@ -770,7 +770,7 @@ func (m *mapEventManager[K, V]) removeLifecycleListener(listener MapLifecycleLis
770770
}
771771
}
772772

773-
// addKeyListener adds a new key-based MapListener. The lite flag is a hint
773+
// addKeyListener adds a new key-based [MapListener]. The lite flag is a hint
774774
// to the Coherence cluster that an event may omit the old and new
775775
// values when emitting a MapEvent.
776776
func (m *mapEventManager[K, V]) addKeyListener(ctx context.Context, listener MapListener[K, V], key K, lite bool) error {
@@ -796,7 +796,7 @@ func (m *mapEventManager[K, V]) removeKeyListener(ctx context.Context, listener
796796
return nil
797797
}
798798

799-
// addFilterListener adds a new filter-based MapListener. The lite flag is a hint
799+
// addFilterListener adds a new filter-based [MapListener]. The lite flag is a hint
800800
// to the Coherence cluster that an event may omit the old and new
801801
// values when emitting a MapEvent.
802802
func (m *mapEventManager[K, V]) addFilterListener(ctx context.Context, listener MapListener[K, V], filter filters.Filter, lite bool) error {
@@ -946,7 +946,7 @@ func (m *mapEventManager[K, V]) ensureStream() (*eventStream, error) {
946946
return m.eventStream, nil
947947
}
948948

949-
// newSubscribeRequest creates/initializes and returns a proto.MapListenerRequest.
949+
// newSubscribeRequest creates/initializes and returns a [proto.MapListenerRequest].
950950
func (m *mapEventManager[K, V]) newSubscribeRequest(requestType string) proto.MapListenerRequest {
951951
return proto.MapListenerRequest{
952952
Subscribe: true,

0 commit comments

Comments
 (0)