sdpws

package
v0.72.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the main driver for all interactions with a SDP/Gateway websocket.

Internally it holds a map of all active requests, which are identified by a UUID, to multiplex incoming responses to the correct caller. Note that the request methods block until the response is received, so to send multiple requests in parallel, call requestor methods in goroutines, e.g. using a conc Pool:

```

pool := pool.New().WithContext(ctx).WithCancelOnError().WithFirstError()
pool.Go(func() error {
     items, err := client.Query(ctx, q)
     if err != nil {
         return err
     }
     // do something with items
}
// ...
pool.Wait()

```

Alternatively, pass in a GatewayMessageHandler to receive all messages as they come in and send messages directly using `Send()` and then `Wait()` for all request IDs.

func Dial

func Dial(ctx context.Context, u string, httpClient *http.Client, handler GatewayMessageHandler) (*Client, error)

Dial connects to the given URL and returns a new Client. Pass nil as handler if you do not need per-message callbacks.

To stop the client, cancel the provided context:

``` ctx, cancel := context.WithCancel(context.Background()) defer cancel() client, err := sdpws.Dial(ctx, gatewayUrl, NewAuthenticatedClient(ctx, otelhttp.DefaultClient), nil) ```

func DialBatch added in v0.61.3

func DialBatch(ctx context.Context, u string, httpClient *http.Client, handler GatewayMessageHandler) (*Client, error)

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close closes the connection and returns any errors from the underlying connection.

func (*Client) Closed

func (c *Client) Closed() bool

func (*Client) Query

func (c *Client) Query(ctx context.Context, q *sdp.Query) ([]*sdp.Item, error)

Run a query and wait for it to complete, returning all of the items that were found.

func (*Client) SendQuery

func (c *Client) SendQuery(ctx context.Context, q *sdp.Query) error

Sends a query on the websocket connection without waiting for responses. Use the `Wait()` method to wait for completion of requests based on their UUID

func (*Client) SendStoreBookmark

func (c *Client) SendStoreBookmark(ctx context.Context, b *sdp.StoreBookmark) error

Sends a StoreBookmark request on the websocket connection without waiting for a response.

func (*Client) SendStoreSnapshot

func (c *Client) SendStoreSnapshot(ctx context.Context, s *sdp.StoreSnapshot) error

Sends a StoreSnapshot request on the websocket connection without waiting for a response.

func (*Client) StoreBookmark

func (c *Client) StoreBookmark(ctx context.Context, name, description string, isSystem bool) (uuid.UUID, error)

Store a bookmark and wait for it to complete, returning the UUID of the bookmark that was created.

func (*Client) StoreSnapshot

func (c *Client) StoreSnapshot(ctx context.Context, name, description string) (uuid.UUID, error)

Store a snapshot and wait for it to complete, returning the UUID of the snapshot that was created.

func (*Client) Wait

func (c *Client) Wait(ctx context.Context, reqIDs uuid.UUIDs) error

Wait blocks until all specified requests have been finished. Waiting on a closed client returns immediately with no error.

type GatewayMessageHandler

type GatewayMessageHandler interface {
	NewItem(context.Context, *sdp.Item)
	NewEdge(context.Context, *sdp.Edge)
	Status(context.Context, *sdp.GatewayRequestStatus)
	Error(context.Context, string)
	QueryError(context.Context, *sdp.QueryError)
	DeleteItem(context.Context, *sdp.Reference)
	DeleteEdge(context.Context, *sdp.Edge)
	UpdateItem(context.Context, *sdp.Item)
	SnapshotStoreResult(context.Context, *sdp.SnapshotStoreResult)
	SnapshotLoadResult(context.Context, *sdp.SnapshotLoadResult)
	BookmarkStoreResult(context.Context, *sdp.BookmarkStoreResult)
	BookmarkLoadResult(context.Context, *sdp.BookmarkLoadResult)
	QueryStatus(context.Context, *sdp.QueryStatus)
}

GatewayMessageHandler is an interface that can be implemented to handle messages from the gateway. The individual methods are calles when the sdpws client receives a message from the gateway. Methods are called in the same order as the messages are received from the gateway. The sdpws client guarantees that the methods are called in a single thread, so no locking is needed.

type LoggingGatewayMessageHandler

type LoggingGatewayMessageHandler struct {
	Level log.Level
}

func (*LoggingGatewayMessageHandler) BookmarkLoadResult

func (l *LoggingGatewayMessageHandler) BookmarkLoadResult(ctx context.Context, result *sdp.BookmarkLoadResult)

func (*LoggingGatewayMessageHandler) BookmarkStoreResult

func (l *LoggingGatewayMessageHandler) BookmarkStoreResult(ctx context.Context, result *sdp.BookmarkStoreResult)

func (*LoggingGatewayMessageHandler) DeleteEdge

func (l *LoggingGatewayMessageHandler) DeleteEdge(ctx context.Context, edge *sdp.Edge)

func (*LoggingGatewayMessageHandler) DeleteItem

func (l *LoggingGatewayMessageHandler) DeleteItem(ctx context.Context, reference *sdp.Reference)

func (*LoggingGatewayMessageHandler) Error

func (l *LoggingGatewayMessageHandler) Error(ctx context.Context, errorMessage string)

func (*LoggingGatewayMessageHandler) NewEdge

func (l *LoggingGatewayMessageHandler) NewEdge(ctx context.Context, edge *sdp.Edge)

func (*LoggingGatewayMessageHandler) NewItem

func (l *LoggingGatewayMessageHandler) NewItem(ctx context.Context, item *sdp.Item)

func (*LoggingGatewayMessageHandler) QueryError

func (l *LoggingGatewayMessageHandler) QueryError(ctx context.Context, queryError *sdp.QueryError)

func (*LoggingGatewayMessageHandler) QueryStatus

func (l *LoggingGatewayMessageHandler) QueryStatus(ctx context.Context, status *sdp.QueryStatus)

func (*LoggingGatewayMessageHandler) SnapshotLoadResult

func (l *LoggingGatewayMessageHandler) SnapshotLoadResult(ctx context.Context, result *sdp.SnapshotLoadResult)

func (*LoggingGatewayMessageHandler) SnapshotStoreResult

func (l *LoggingGatewayMessageHandler) SnapshotStoreResult(ctx context.Context, result *sdp.SnapshotStoreResult)

func (*LoggingGatewayMessageHandler) Status

func (l *LoggingGatewayMessageHandler) Status(ctx context.Context, status *sdp.GatewayRequestStatus)

func (*LoggingGatewayMessageHandler) UpdateItem

func (l *LoggingGatewayMessageHandler) UpdateItem(ctx context.Context, item *sdp.Item)

type NoopGatewayMessageHandler

type NoopGatewayMessageHandler struct{}

func (*NoopGatewayMessageHandler) BookmarkLoadResult

func (l *NoopGatewayMessageHandler) BookmarkLoadResult(ctx context.Context, result *sdp.BookmarkLoadResult)

func (*NoopGatewayMessageHandler) BookmarkStoreResult

func (l *NoopGatewayMessageHandler) BookmarkStoreResult(ctx context.Context, result *sdp.BookmarkStoreResult)

func (*NoopGatewayMessageHandler) DeleteEdge

func (l *NoopGatewayMessageHandler) DeleteEdge(ctx context.Context, edge *sdp.Edge)

func (*NoopGatewayMessageHandler) DeleteItem

func (l *NoopGatewayMessageHandler) DeleteItem(ctx context.Context, reference *sdp.Reference)

func (*NoopGatewayMessageHandler) Error

func (l *NoopGatewayMessageHandler) Error(ctx context.Context, errorMessage string)

func (*NoopGatewayMessageHandler) NewEdge

func (l *NoopGatewayMessageHandler) NewEdge(ctx context.Context, edge *sdp.Edge)

func (*NoopGatewayMessageHandler) NewItem

func (l *NoopGatewayMessageHandler) NewItem(ctx context.Context, item *sdp.Item)

func (*NoopGatewayMessageHandler) QueryError

func (l *NoopGatewayMessageHandler) QueryError(ctx context.Context, queryError *sdp.QueryError)

func (*NoopGatewayMessageHandler) QueryStatus

func (l *NoopGatewayMessageHandler) QueryStatus(ctx context.Context, status *sdp.QueryStatus)

func (*NoopGatewayMessageHandler) SnapshotLoadResult

func (l *NoopGatewayMessageHandler) SnapshotLoadResult(ctx context.Context, result *sdp.SnapshotLoadResult)

func (*NoopGatewayMessageHandler) SnapshotStoreResult

func (l *NoopGatewayMessageHandler) SnapshotStoreResult(ctx context.Context, result *sdp.SnapshotStoreResult)

func (*NoopGatewayMessageHandler) Status

func (l *NoopGatewayMessageHandler) Status(ctx context.Context, status *sdp.GatewayRequestStatus)

func (*NoopGatewayMessageHandler) UpdateItem

func (l *NoopGatewayMessageHandler) UpdateItem(ctx context.Context, item *sdp.Item)

type StoreEverythingHandler added in v0.71.0

type StoreEverythingHandler struct {
	Items []*sdp.Item
	Edges []*sdp.Edge

	NoopGatewayMessageHandler
}

A handler that stores all the items and edges it receives

func (*StoreEverythingHandler) NewEdge added in v0.71.0

func (s *StoreEverythingHandler) NewEdge(ctx context.Context, edge *sdp.Edge)

func (*StoreEverythingHandler) NewItem added in v0.71.0

func (s *StoreEverythingHandler) NewItem(ctx context.Context, item *sdp.Item)

type WaitForAllQueriesHandler added in v0.71.0

type WaitForAllQueriesHandler struct {
	// A callback that will be called when all queries are done
	DoneCallback func()

	StoreEverythingHandler
}

A Handler that waits for all queries to be done then calls a callback

func (*WaitForAllQueriesHandler) Status added in v0.71.0

func (w *WaitForAllQueriesHandler) Status(ctx context.Context, status *sdp.GatewayRequestStatus)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL