YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.snapcast.SnapcastSession Class Reference

Everything that belongs to one snapserver: the control connection (SnapcastRpc), the model that follows the server's notifications (SnapcastModelUpdater) and the control calls (SnapcastOperations). More...

Inheritance diagram for de.yaacc.snapcast.SnapcastSession:
Inheritance graph
Collaboration diagram for de.yaacc.snapcast.SnapcastSession:
Collaboration graph

Public Member Functions

 SnapcastSession (ServerKey key, SnapcastTransport transport, SnapcastRpc.Config config, MonotonicClock clock, RetryScheduler scheduler)
 
ServerKey getKey ()
 
SnapcastOperations getOperations ()
 The calls that change the server.
 
SnapcastServerStatus getStatus ()
 The last status that was read; null before the first one.
 
boolean isOnline ()
 True while the control connection is up.
 
boolean hasGivenUp ()
 True when the reconnects stopped after too many failures; retry() starts them again.
 
SnapcastException.Kind getLastErrorKind ()
 The kind of the last connection or read failure; null when the last read or connection succeeded.
 
int getLastErrorCode ()
 The JSON-RPC code of the last failure (401 or 403 when the server wants authorization), else 0.
 
InetAddress getPeerAddress ()
 The address of the control connection, or null without one.
 
long getConnectionGeneration ()
 A number that changes with every new control connection of this link and never goes back; 0 for a fake.
 
void addListener (Listener listener)
 
void removeListener (Listener listener)
 
void start ()
 Opens the connection (does nothing when started already).
 
void retry ()
 Connects now if the link waits for a retry or gave up.
 
void close ()
 Releases the connection and every thread.
 

Detailed Description

Everything that belongs to one snapserver: the control connection (SnapcastRpc), the model that follows the server's notifications (SnapcastModelUpdater) and the control calls (SnapcastOperations).

It exposes the current immutable SnapcastServerStatus, tells its listeners when the status or the connection changed, and releases every thread on close(). Pure Java (the transport is injected).

How it follows the usage notes of the control library.

  • The RPC gets a listener executor of its own that does nothing but the deliveries; the status reads run on a separate worker, so a read that waits for its delivery can never wait for a task queued behind it.
  • The re-read requester of the updater runs on the listener thread; here it only hands the read to the worker.
  • A fresh status is read when the connection comes up (onConnected), on the worker. A re-read that fails (a timeout, a connection problem; not an error the server answered) is requested again through the updater, which keeps its limit of one per second and ten per minute; a held-back request is delivered by a one-second tick that runs only while the connection is up. After {@value MAX_READ_RETRIES} failures in a row it gives up until the next doubt or connection.
  • retry() (the receivers page became visible) is the only caller of SnapcastRpc.retry(); it resets the failure count of the reconnects, so it is never called by a loop here.
  • Every change of our own through getOperations() goes through callOrdered, so the model follows it in line order; the listeners are told after it.

Threads: the reader and the writer of the RPC, one listener thread, one worker and (without an injected scheduler) one timer thread. Names and ids in the status are display text of the server, never an identity.

Constructor & Destructor Documentation

◆ SnapcastSession()

de.yaacc.snapcast.SnapcastSession.SnapcastSession ( ServerKey key,
SnapcastTransport transport,
SnapcastRpc.Config config,
MonotonicClock clock,
RetryScheduler scheduler )
Parameters
transportopens the control connection (for the app: a SocketTransport to an address that was resolved with a time limit)
configthe limits of the connection
schedulerruns the reconnect timers and the tick; null: an own timer thread
Here is the call graph for this function:

Member Function Documentation

◆ addListener()

void de.yaacc.snapcast.SnapcastSession.addListener ( Listener listener)

◆ close()

void de.yaacc.snapcast.SnapcastSession.close ( )

Releases the connection and every thread.

The listeners are told once, before they are dropped, that the link is offline (isOnline() is false in the call): whoever depends on the link (a feed that writes to the server of this link) learns that it is gone and stops (security review W1: removing a server must end a running feed). The call is made on the calling thread and holds no lock of this class; a listener that fails is skipped.

Implements de.yaacc.snapcast.SnapcastServerLink.

◆ getConnectionGeneration()

long de.yaacc.snapcast.SnapcastSession.getConnectionGeneration ( )

A number that changes with every new control connection of this link and never goes back; 0 for a fake.

Implements de.yaacc.snapcast.SnapcastServerLink.

◆ getKey()

ServerKey de.yaacc.snapcast.SnapcastSession.getKey ( )

◆ getOperations()

SnapcastOperations de.yaacc.snapcast.SnapcastSession.getOperations ( )

The calls that change the server.

They block: make them on a worker, never on the main thread.

Implements de.yaacc.snapcast.SnapcastServerLink.

◆ getPeerAddress()

InetAddress de.yaacc.snapcast.SnapcastSession.getPeerAddress ( )

The address of the control connection, or null without one.

The feed of a stream connects to this address and to no other. It is an address of the local network: never log it.

Implements de.yaacc.snapcast.SnapcastServerLink.

◆ getStatus()

SnapcastServerStatus de.yaacc.snapcast.SnapcastSession.getStatus ( )

The last status that was read; null before the first one.

It is kept while the server is offline.

Implements de.yaacc.snapcast.SnapcastServerLink.

◆ isOnline()

boolean de.yaacc.snapcast.SnapcastSession.isOnline ( )

True while the control connection is up.

Implements de.yaacc.snapcast.SnapcastServerLink.

◆ removeListener()

void de.yaacc.snapcast.SnapcastSession.removeListener ( Listener listener)

◆ retry()

void de.yaacc.snapcast.SnapcastSession.retry ( )

Connects now if the link waits for a retry or gave up.

Implements de.yaacc.snapcast.SnapcastServerLink.

◆ start()

void de.yaacc.snapcast.SnapcastSession.start ( )

Opens the connection (does nothing when started already).

Implements de.yaacc.snapcast.SnapcastServerLink.


The documentation for this class was generated from the following file: