Merge branch '8784-dir-listings'
[arvados.git] / services / ws / session.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "database/sql"
9
10         "git.curoverse.com/arvados.git/sdk/go/arvados"
11 )
12
13 type session interface {
14         // Receive processes a message received from the client. If a
15         // non-nil error is returned, the connection will be
16         // terminated.
17         Receive([]byte) error
18
19         // Filter returns true if the event should be queued for
20         // sending to the client. It should return as fast as
21         // possible, and must not block.
22         Filter(*event) bool
23
24         // EventMessage encodes the given event (from the front of the
25         // queue) into a form suitable to send to the client. If a
26         // non-nil error is returned, the connection is terminated. If
27         // the returned buffer is empty, nothing is sent to the client
28         // and the event is not counted in statistics.
29         //
30         // Unlike Filter, EventMessage can block without affecting
31         // other connections. If EventMessage is slow, additional
32         // incoming events will be queued. If the event queue fills
33         // up, the connection will be dropped.
34         EventMessage(*event) ([]byte, error)
35 }
36
37 type sessionFactory func(wsConn, chan<- interface{}, *sql.DB, permChecker, *arvados.Client) (session, error)