public class Server extends Object implements Constants, de.sciss.app.EventManager.Processor
As of v0.29, the server must be started explicitly by calling start()
unless the server is booted. The call to start()
tells the OSCClient
to
start listening for incoming messages. For TCP connections, this will try to connect to the server.
Modifier and Type | Class and Description |
---|---|
static interface |
Server.CompletionAction
This interface is used to describe an action
to be executed after some process such as
booting the server has completed.
|
static class |
Server.Status
A static field only class
describing the snapshot of the server status
as delivered by
getStatus |
Modifier and Type | Field and Description |
---|---|
protected de.sciss.jcollider.Server.BootThread |
bootThread |
protected Buffer[] |
bufferArray |
protected OSCResponderNode |
bufInfoResponder |
protected de.sciss.net.OSCClient |
c |
static int |
DEFAULT_PORT
We just use the same default scsynth
server port (57110) here as assumed by sclang
|
protected Server |
enc_this |
protected static PrintStream |
printStream |
protected boolean |
serverBooting |
protected Server.Status |
status |
protected Object |
syncBootThread |
protected int |
waitingBufs |
protected boolean |
waitingForBufInfo |
kAddAfter, kAddBefore, kAddReplace, kAddToHead, kAddToTail, kAudioRate, kControlRate, kDemandRate, kDoneFree, kDoneFreeAll, kDoneFreeAllPred, kDoneFreeAllSucc, kDoneFreeGroup, kDoneFreePausePred, kDoneFreePauseSucc, kDoneFreePred, kDoneFreePredGroup, kDoneFreePredGroupDeep, kDoneFreeSucc, kDoneFreeSuccGroup, kDoneFreeSuccGroupDeep, kDoneNothing, kDonePause, kDumpBoth, kDumpHex, kDumpOff, kDumpText, kHeaderAIFF, kHeaderIRCAM, kHeaderNeXT, kHeaderRaw, kHeaderWAVE, kSampleALaw, kSampleDouble, kSampleFloat, kSampleInt16, kSampleInt24, kSampleInt32, kSampleInt8, kSampleMuLaw, kScalarRate
Constructor and Description |
---|
Server(String name)
Creates a representation for a
server which listens at the loopback
address (
127.0.0.1:57110 ). |
Server(String name,
InetSocketAddress addr)
Creates a server representation
for the default client (
0 ),
using default options. |
Server(String name,
InetSocketAddress addr,
ServerOptions options)
Creates a server representation
for the default client (
0 ). |
Server(String name,
InetSocketAddress addr,
ServerOptions options,
int clientID)
Creates a new
Server representation
object. |
Modifier and Type | Method and Description |
---|---|
protected void |
addBuf(Buffer buf)
For internal use by
Buffer objects. |
void |
addDoWhenBooted(Server.CompletionAction action)
Registers an action to be executed
after the boot process is complete.
|
void |
addListener(ServerListener l)
Registers a listener to be informed about
server status changes.
|
Group |
asTarget()
Returns a group representation of the
server, which at the moment is a synonym for
getDefaultGroup . |
void |
boot()
Starts booting a local server
and establishes the ping-thread when done
|
void |
boot(boolean startAliveThread)
Starts booting a local server.
|
protected void |
changed(int id) |
boolean |
didWeBootTheServer()
Returns
true if the
server was locally booted by this client. |
void |
dispose()
Disposes any resources
allocated by this representation.
|
void |
dumpIncomingOSC(int dumpMode)
Changes the way incoming messages are dumped
to the console.
|
void |
dumpOSC()
Sends a message to the server
requesting OSC dump (text format).
|
void |
dumpOSC(int dumpMode)
Sends a message to the server
requesting OSC dumping being turned on or off
|
de.sciss.net.OSCMessage |
dumpOSCMsg(int dumpMode)
Creates the OSC message which will ask the
server to turn on or off OSC dumping
|
void |
dumpOutgoingOSC(int dumpMode)
Changes the way outgoing messages are dumped
to the console.
|
protected void |
freeBuf(int idx)
For internal use by
Buffer objects. |
InetSocketAddress |
getAddr()
Returns the address which is
assumed to be the one at which
the server listens
|
protected BlockAllocator |
getAudioBusAllocator()
Automatic audio bus allocator
for package internal use only.
|
protected BlockAllocator |
getBufferAllocator()
Automatic buffer ID allocator
for package internal use only.
|
int |
getClientID()
Queries the client ID used
for allocating node IDs.
|
protected BlockAllocator |
getControlBusAllocator()
Automatic control bus allocator
for package internal use only.
|
Group |
getDefaultGroup()
Returns the "default" group
of the server.
|
int |
getDumpMode()
Queries the current OSC dumping mode.
|
protected OSCMultiResponder |
getMultiResponder() |
String |
getName()
Queries the server representation's name
|
ServerOptions |
getOptions()
Queries the options for booting the server.
|
static PrintStream |
getPrintStream()
Queries the currently used print stream for
outputting messages
|
static String |
getProgram()
Queries the application path
to scsynth.
|
double |
getSampleRate()
Queries the server's (audio) sampling rate.
|
Server.Status |
getStatus()
Queries the latest reported server status.
|
protected static void |
inform(String txt) |
void |
initTree()
After the server has been contacted,
calling this method will create the default group.
|
boolean |
isBooting()
Queries the booting state
|
boolean |
isLocal()
Returns
true if the
server has an address on the same
machine as the client. |
boolean |
isNotified()
Queries the server notification status.
|
boolean |
isRunning()
Queries the running state.
|
int |
nextNodeID()
Allocates a new free node ID for a group or synth.
|
void |
notify(boolean notified)
Sends a message to the server
requesting to be notified about server actions
such as nodes being added and deleted.
|
protected static void |
printError(String name,
Throwable t) |
void |
printOn(PrintStream stream)
Prints a textual representation of this
object onto the given stream
|
void |
processEvent(de.sciss.app.BasicEvent e)
This is used to dispatch
server events.
|
void |
quit()
Sends an asynchronous
/quit
to the server and cleans up the client's resources |
static void |
quitAll()
Synchronously quits all known servers.
|
boolean |
quitAndWait()
Synchronously quit the server.
|
de.sciss.net.OSCMessage |
quitMsg()
Constructs a quit message for the server
|
void |
removeDoWhenBooted(Server.CompletionAction action)
Unregisters an action from being executed
after the boot process.
|
void |
removeListener(ServerListener l)
Unregisters a listener from being informed about
server status changes.
|
void |
sendBundle(de.sciss.net.OSCBundle bndl)
Sends an OSC bundle for scheduling to the server
|
boolean |
sendBundleSync(de.sciss.net.OSCBundle bndl,
String cmdName,
float timeout)
Sends a bundle and waits for a
/done
reply for a given command name from the server. |
de.sciss.net.OSCMessage |
sendBundleSync(de.sciss.net.OSCBundle bndl,
String doneCmd,
String failCmd,
int[] doneArgIndices,
Object[] doneArgMatches,
int[] failArgIndices,
Object[] failArgMatches,
float timeout)
Sends a bundle and waits for a corresponding reply or failure message
from the server.
|
de.sciss.net.OSCMessage |
sendBundleSync(de.sciss.net.OSCBundle bndl,
String doneCmd,
String failCmd,
int argIdx,
Object argMatch,
float timeout)
Sends a bundle and waits for a corresponding reply or failure message
from the server.
|
void |
sendMsg(de.sciss.net.OSCMessage msg)
Sends an OSC message to the server
|
boolean |
sendMsgSync(de.sciss.net.OSCMessage msg,
float timeout)
Sends a message and waits for a corresponding
/done
reply from the server. |
de.sciss.net.OSCMessage |
sendMsgSync(de.sciss.net.OSCMessage msg,
String doneCmd,
String failCmd,
int[] doneArgIndices,
Object[] doneArgMatches,
int[] failArgIndices,
Object[] failArgMatches,
float timeout)
Sends a message and waits for a corresponding reply or failure message
from the server.
|
de.sciss.net.OSCMessage |
sendMsgSync(de.sciss.net.OSCMessage msg,
String doneCmd,
String failCmd,
int doneArgIdx,
Object doneArgMatch,
float timeout)
Sends a message and waits for a corresponding reply or failure message
from the server.
|
protected void |
setBooting(boolean serverBooting) |
static void |
setInform(boolean onOff)
Turns on or off verbose messaging
of the server representation.
|
static void |
setPrintStream(PrintStream printStream)
Changes the stream to which messages are
printed.
|
static void |
setProgram(String program)
Changes the path at which scsynth is supposed
to located on the local harddisk.
|
protected void |
setRunning(boolean serverRunning) |
void |
start() |
void |
startAliveThread()
Begins to ping the server in regular intervals
to detect a newly established connection, the
loss of the connection and the current server status.
|
void |
startAliveThread(float delay,
float period,
int deathBounces)
Starts the ping-thread with specified
initial delay and ping period.
|
protected void |
status() |
void |
stopAliveThread()
Stops the ping-thread.
|
boolean |
sync(float timeout)
Sends a
/sync message to the server and waits for a
corresponding /synced reply. |
boolean |
sync(de.sciss.net.OSCBundle bndl,
float timeout)
Attaches a
/sync message to the list of messages in a
bundle and sends the bundle to server, waiting for a
corresponding /synced reply. |
protected void |
waitForBufInfo()
For internal use by
Buffer objects. |
public static final int DEFAULT_PORT
protected volatile boolean serverBooting
protected Buffer[] bufferArray
protected OSCResponderNode bufInfoResponder
protected boolean waitingForBufInfo
protected int waitingBufs
protected static volatile PrintStream printStream
protected final de.sciss.net.OSCClient c
protected final Server.Status status
protected de.sciss.jcollider.Server.BootThread bootThread
protected final Server enc_this
protected final Object syncBootThread
public Server(String name, InetSocketAddress addr, ServerOptions options, int clientID) throws IOException
Server
representation
object. Note that this will neither "create"
a server, nor boot one, nor contact one. It simply
establishes means of communication to a server
at the given address. The caller is responsible for
contacting the server and, before starting to create
nodes and such, to initialize the default tree
using initTree
, and to ping the server
using startAliveThread
if one wishes
to be informed about server boots and quits.name
- the name of the server. this arbitrary but
must be unique since a set of created servers
is internally maintained. currently no check
on this uniqueness is performed. this is also
the name of the OSC thread and the one shown
in a server paneladdr
- the address at which scsynth responds. as
of this writing, the communication will use
the UDP protocoloptions
- an instance of ServerOptions
which needn't reflect the actual server settings
when contacting a remote server, but which are
used when booting a local server.clientID
- this is a concept taken from sclang, something about
which the server knows nothing. it merely conditions
the node ID allocator to occupy different value
ranges for up to 31 different clients, so they won't
conflict. beware, that as of this writing, there is
no mechanism to coordinate the use of buffers and
busses between different concurrent clients.
the ID can be something between 0
(default) and
NodeIDAllocator.getUserMax()
IOException
- if a networking error occursstartAliveThread()
,
boot()
,
initTree()
public Server(String name, InetSocketAddress addr, ServerOptions options) throws IOException
0
).IOException
public Server(String name, InetSocketAddress addr) throws IOException
0
),
using default options.IOException
ServerOptions()
public Server(String name) throws IOException
127.0.0.1:57110
).IOException
public InetSocketAddress getAddr()
protected OSCMultiResponder getMultiResponder()
public void start() throws IOException
IOException
public String getName()
Server
classpublic ServerOptions getOptions()
boot
method.public int getClientID()
Server
constructorpublic static String getProgram()
setProgram
before
trying to bootpublic static void setProgram(String program)
File
object. To convert from a file, use
File.getAbsolutePath()
.program
- full pathname to scsynth(.exe)File.getAbsolutePath()
public static void setInform(boolean onOff)
onOff
- true
means, be
a bit more verbosepublic static void setPrintStream(PrintStream printStream)
Server
will
print on System.err
. This is
a global method and affects all server instances.
This method is particularly important because
it's value will be read by the boot
method to determine the print stream to which
a locally booted server will print. Changing
the stream after the server was booted, will not
affect it's print out at all, so that needs to
be done in advance.printStream
- the new print stream to usepublic static PrintStream getPrintStream()
public boolean isBooting()
true
if the local server is being booted
at the moment, false
otherwise.isRunning()
protected void setBooting(boolean serverBooting)
public boolean isRunning()
addListener
method.true
if a connection is established
to a supercollider server. false
if the
server is not running or communication broke down.
note that this value will only be valid, when the
ping-thread is running, which is either started
automatically when booting the server (boot
)
or manually by invoking startAliveThread()
.addListener( ServerListener )
,
boot()
,
startAliveThread()
protected void setRunning(boolean serverRunning)
protected BlockAllocator getBufferAllocator()
protected BlockAllocator getAudioBusAllocator()
protected BlockAllocator getControlBusAllocator()
public double getSampleRate()
/status.reply
message from the server. This is only valid
when the server is running and the ping-thread
was started. To be automatically informed about
status changes, you can register a listener
using addListener
.addListener( ServerListener )
,
startAliveThread()
,
getStatus()
public Server.Status getStatus()
/status.reply
message. It's only valid when the server is
running and the ping-thread is running.Status
with fields
for number of UGens, Nodes etc.public int getDumpMode()
kDumpOff
,
kDumpText
, kDumpHex
or kDumpBoth
.Constants.kDumpText
public Group getDefaultGroup()
new Synth( defName, argNames, argValues, null )
.initTree
explicitly.initTree()
public Group asTarget()
getDefaultGroup
. This will change in
one of the next version to return the root node
(ID 0) however!!protected static void inform(String txt)
public void boot() throws IOException
IOException
public void boot(boolean startAliveThread) throws IOException
setProgram
before calling this method.
This method does nothing, when the booting process is assumed to be ongoing already, or when the server has already been successfully booted.
When booting is finished, the ping-thread is established
depending on the startAliveThread
flag,
the node tree is initialized (initTree
),
and all actions registered through addDoWhenBooted
are executed. Independantly, when the ping-thread receives
the first reply, the running status is updated, hence
informing all listeners registered using addListener
.
startAliveThread
- true
to start a ping-thread
once the server was booted. this is required
if you wish to read the running status using
isRunning()
or using listenersIOException
- if an error occurs when starting server,
particularly if the path to the server application
is wrong.IllegalStateException
- if you try to boot a remote serversetProgram( String )
,
isLocal()
,
isBooting()
,
isRunning()
,
addDoWhenBooted( Server.CompletionAction )
,
startAliveThread()
public void dumpOSC() throws IOException
IOException
- if the message failed to be sentpublic void dumpOSC(int dumpMode) throws IOException
dumpMode
- either of kDumpOff
(do not dump),
kDumpText
(dump text format),
kDumpHex
(hexadecimal printout),
kDumpBoth
(both text + hex)IOException
- if the message failed to be sentConstants.kDumpText
public de.sciss.net.OSCMessage dumpOSCMsg(int dumpMode)
dumpMode
- see dumpOSC( int )
for detailsdumpOSC( int )
public void dumpIncomingOSC(int dumpMode)
OSCResponderNode
s.dumpMode
- see dumpOSC( int )
for detailsdumpOSC( int )
public void dumpOutgoingOSC(int dumpMode)
sendMsg
or sendBundle
.dumpMode
- see dumpOSC( int )
for detailsdumpOSC( int )
public void notify(boolean notified) throws IOException
/tr
messages from a sendTrig
UGen.
The status of the notification flag is saved
internally, so when a local server is booted
and notification was turned on, a new
/notify
message is sent.
By default (when creating a new instance of
Server
), the notification flag
is true
.
notified
- true
to turn notification on,
false
to turn it offIOException
- if the message failed to be sentpublic boolean isNotified()
true
if notification is turned on.public void initTree() throws IOException
IOException
public void addDoWhenBooted(Server.CompletionAction action)
action
- action to be executed,
when the server running status
becomes true after the boot processpublic void removeDoWhenBooted(Server.CompletionAction action)
action
- action to be removedpublic void addListener(ServerListener l)
l
- listener to be addedpublic void removeListener(ServerListener l)
l
- listener to be removedprotected void changed(int id)
public boolean isLocal()
true
if the
server has an address on the same
machine as the client.public boolean didWeBootTheServer()
true
if the
server was locally booted by this client.true
if we booted
the server ourselves. this suggests
that we are also responsible for shutting
it down when quitting the clientpublic void startAliveThread() throws IOException
If the ping-thread is already running, this method does nothing.
IOException
- if a networking error occurspublic void startAliveThread(float delay, float period, int deathBounces) throws IOException
If the ping-thread is already running, this method does nothing.
delay
- delay in seconds after which
the first ping is send (defaults to 2 seconds)period
- period in seconds at which pings
are send (defaults to 0.7 seconds).
note that the behaviour of lost pings might
change in a future version. As of now, a lost
ping will result in server running status becoming
false and firing a corresponding server event to
registered listeners. The can be inappropriate
if the listener starts to dispose internals while
actually the server was just too slow and keeps
playing orphaned synths.IOException
- if a networking error occurspublic void stopAliveThread() throws IOException
System.exit
is called.IOException
- if a networking error occursprotected void status() throws IOException
IOException
public void sendMsg(de.sciss.net.OSCMessage msg) throws IOException
msg
- the message to sendIOException
- if sending the message fails.
this can happen because of a network error,
because of a malformed message or because of
a buffer overflow (message exceeding 8K)public void sendBundle(de.sciss.net.OSCBundle bndl) throws IOException
bndl
- the bundle to sendIOException
- if sending the bundle fails.
this can happen because of a network error,
because of a malformed bundle or its contained messages
or because of a buffer overflow (bundle exceeding 8K)public boolean sendMsgSync(de.sciss.net.OSCMessage msg, float timeout) throws IOException
/done
reply from the server.msg
- the message to sendtimeout
- the maximum amount of time in seconds to waittrue
if the successfull reply was
receivied within the timeout; false
if
no reply was received in time or a /fail
message was received.IOException
- if sending the message or receiving the reply failspublic de.sciss.net.OSCMessage sendMsgSync(de.sciss.net.OSCMessage msg, String doneCmd, String failCmd, int doneArgIdx, Object doneArgMatch, float timeout) throws IOException
msg
- the message to senddoneCmd
- the OSC command with which the server replies upon successfailCmd
- the OSC command with which the server replies upon failure (can be null
)doneArgIdx
- the OSC reply message argument index to matchdoneArgMatch
- the OSC reply message argument value to matchtimeout
- the maximum amount of time in seconds to waitnull
if
no reply was received in timeIOException
- if sending the message or receiving the reply failspublic de.sciss.net.OSCMessage sendMsgSync(de.sciss.net.OSCMessage msg, String doneCmd, String failCmd, int[] doneArgIndices, Object[] doneArgMatches, int[] failArgIndices, Object[] failArgMatches, float timeout) throws IOException
msg
- the message to senddoneCmd
- the OSC command with which the server replies upon successfailCmd
- the OSC command with which the server replies upon failure (can be null
)doneArgIndices
- the OSC reply message argument indices to match for successdoneArgMatches
- the OSC reply message argument values to match for successfailArgIndices
- the OSC reply message argument indices to match for failurefailArgMatches
- the OSC reply message argument values to match for failuretimeout
- the maximum amount of time in seconds to waitnull
if
no reply was received in timeIOException
- if sending the message or receiving the reply failspublic boolean sendBundleSync(de.sciss.net.OSCBundle bndl, String cmdName, float timeout) throws IOException
/done
reply for a given command name from the server.bndl
- the bundle to sendcmdName
- to name of the message command to be replied totimeout
- the maximum amount of time in seconds to waittrue
if the successfull reply was
receivied within the timeout; false
if
no reply was received in time or a /fail
message was received.IOException
- if sending the bundle or receiving the reply failspublic de.sciss.net.OSCMessage sendBundleSync(de.sciss.net.OSCBundle bndl, String doneCmd, String failCmd, int argIdx, Object argMatch, float timeout) throws IOException
bndl
- the bundle to senddoneCmd
- the OSC command with which the server replies upon successfailCmd
- the OSC command with which the server replies upon failure (can be null
)argIdx
- the OSC reply message argument index to matchargMatch
- the OSC reply message argument value to matchtimeout
- the maximum amount of time in seconds to waitnull
if
no reply was received in timeIOException
- if sending the bundle or receiving the reply failspublic de.sciss.net.OSCMessage sendBundleSync(de.sciss.net.OSCBundle bndl, String doneCmd, String failCmd, int[] doneArgIndices, Object[] doneArgMatches, int[] failArgIndices, Object[] failArgMatches, float timeout) throws IOException
bndl
- the bundle to senddoneCmd
- the OSC command with which the server replies upon successfailCmd
- the OSC command with which the server replies upon failure (can be null
)doneArgIndices
- the OSC reply message argument indices to matchdoneArgMatches
- the OSC reply message argument values to matchtimeout
- the maximum amount of time in seconds to waitnull
if
no reply was received in timeIOException
- if sending the bundle or receiving the reply failspublic boolean sync(float timeout) throws IOException
/sync
message to the server and waits for a
corresponding /synced
reply.timeout
- the maximum amount of time in seconds to waittrue
if the successfull reply was
receivied within the timeout.IOException
- if sending the message or receiving the reply failspublic boolean sync(de.sciss.net.OSCBundle bndl, float timeout) throws IOException
/sync
message to the list of messages in a
bundle and sends the bundle to server, waiting for a
corresponding /synced
reply.bndl
- the bundle to send. a /sync
message
is appended to this bundle. bndl
may
be null
, in this case the /sync
is send alone.timeout
- the maximum amount of time in seconds to waittrue
if the successfull reply was
receivied within the timeout.IOException
- if sending the message or receiving the reply failspublic int nextNodeID()
protected void addBuf(Buffer buf)
Buffer
objects.
Do not use yourself.protected void freeBuf(int idx)
Buffer
objects.
Do not use yourself.protected void waitForBufInfo() throws IOException
Buffer
objects.
Do not use yourself.IOException
public void printOn(PrintStream stream)
stream
- the stream to print onpublic void quit() throws IOException
/quit
to the server and cleans up the client's resourcesIOException
- if the message failed to be sent
or if cleanup failedpublic de.sciss.net.OSCMessage quitMsg()
public void dispose()
public boolean quitAndWait() throws IOException
/quit
message and waits for the reply. If no reply is received,
and the server was locally booted, terminates the server process.true
if the server has successfully quitIOException
- if the message failed to be sent
or if cleanup failedpublic static void quitAll()
Server
representation instance has been created.
Cathes all thrown exceptions.public void processEvent(de.sciss.app.BasicEvent e)
processEvent
in interface de.sciss.app.EventManager.Processor
Copyright © 2015–2022 SciJava. All rights reserved.