I'd like to propose moving NotificationCenter into common and using that for Server to announce that it has created new allocators or if it has died.
This means that Buffer can register for these notifications (which are rare) rather than respond to every server.changed (which happens ever 0.4 secs).
It also means that other classes can cleanly subscribe (I wrote a BusReleasePool that needs to know)
Server.changed(\serverAdded) could also be changed to a notification. not sure who is using this
it works, its more light weight. cool ?
Index: /Users/crucial/sc/SCClassLibrary/Common/Control/Server.sc
===================================================================
--- /Users/crucial/sc/SCClassLibrary/Common/Control/Server.sc (revision 7495)
+++ /Users/crucial/sc/SCClassLibrary/Common/Control/Server.sc (working copy)
@@ -37,7 +37,7 @@
*initClass {
default = this.new.blockAllocClass_(ContiguousBlockAllocator);
-// default = this.new.blockAllocClass_(PowerOfTwoAllocator);
+ //default = this.new.blockAllocClass_(PowerOfTwoAllocator);
}
*new {
@@ -134,7 +134,7 @@
Server : Model {
classvar <>local, <>internal, <>default, <>named, <>set, <>program;
- var <name, <addr, <clientID=0;
+ var <name, <>addr, <clientID=0;
var <isLocal, <inProcess;
var <serverRunning = false, <serverBooting=false, bootNotifyFirst=false;
var <>options,<>latency = 0.2,<dumpMode=0, <notified=true;
@@ -188,6 +188,7 @@
audioBusAllocator = options.blockAllocClass.new(options.numAudioBusChannels,
options.firstPrivateBus);
bufferAllocator = options.blockAllocClass.new(options.numBuffers);
+ NotificationCenter.notify(this,\newAllocators);
}
nextNodeID {
^nodeAllocator.alloc
@@ -201,6 +202,7 @@
*initClass {
Class.initClassTree(ServerOptions);
+ Class.initClassTree(NotificationCenter);
named = IdentityDictionary.new;
set = Set.new;
internal = Server.new(\internal, NetAddr.new);
@@ -299,7 +301,17 @@
} {
if (val != serverRunning) {
serverRunning = val;
- if (serverRunning.not) { recordNode = nil };
+ if (serverRunning.not) {
+ AppClock.sched(5.0, {
+ // still down after 5 seconds, assume server is really dead
+ // if you explicitly shut down the server then newAllocators
+ // and the \newAllocators notification will happen immediately
+ if(serverRunning.not) {
+ NotificationCenter.notify(this,\didQuit);
+ };
+ recordNode = nil;
+ })
+ };
{ this.changed(\serverRunning); }.defer;
}
};
@@ -409,7 +421,7 @@
resetBufferAutoInfo {
this.deprecated(thisMethod, Meta_Buffer.findRespondingMethodFor(\clearServerCaches));
- Buffer.clearServerCaches(this);
+ //Buffer.clearServerCaches(this);
}
cachedBuffersDo { |func| Buffer.cachedBuffersDo(this, func) }
@@ -460,7 +472,7 @@
serverBooting = true;
if(startAliveThread, { this.startAliveThread });
this.newAllocators;
- Buffer.clearServerCaches(this);
+ //Buffer.clearServerCaches(this);
bootNotifyFirst = true;
this.doWhenBooted({
if(notified, {
@@ -546,7 +558,7 @@
volume.free
});
this.newAllocators;
- Buffer.clearServerCaches(this);
+ //Buffer.clearServerCaches(this);
}
*quitAll {
Index: /Users/crucial/sc/SCClassLibrary/Common/Control/Buffer.sc
===================================================================
--- /Users/crucial/sc/SCClassLibrary/Common/Control/Buffer.sc (revision 7495)
+++ /Users/crucial/sc/SCClassLibrary/Common/Control/Buffer.sc (working copy)
@@ -525,9 +525,13 @@
}
uncache {
serverCaches[server].removeAt(bufnum);
- // the 2 items would be the responder and server quit updater
- // thus if the size == 2, there are no cached buffers
- if(serverCaches[server].size == 2) {
+ // the 1 item would be the responder
+ // if there is more than 1 item then the rest are cached buffers
+ // else we can remove.
+ // cx: tho i don't see why its important. it will just have to be added
+ // back when the next buffer is added and the responder is removed when
+ // the server reboots
+ if(serverCaches[server].size == 1) {
Buffer.clearServerCaches(server);
}
}
@@ -543,7 +547,13 @@
buffer.queryDone;
};
}).add;
- serverCaches[server][\serverQuitUpdater] = Updater(server, { |svr, what|
+ NotificationCenter.register(server,\newAllocators,this,{
+ this.clearServerCaches(server);
+ });
+ // listening for server death may not be so important
+ // the most important thing was newAllocators
+ // which happens when you quit or boot the server
+ /*serverCaches[server][\serverQuitUpdater] = Updater(server, { |svr, what|
if(what == \serverRunning and: { svr.serverRunning.not }) {
AppClock.sched(5.0, {
// still down after 5 seconds, assume server is really dead
@@ -552,13 +562,13 @@
};
})
};
- });
+ });*/
}
}
*clearServerCaches { |server|
if(serverCaches[server].notNil) {
serverCaches[server][\responder].remove;
- serverCaches[server][\serverQuitUpdater].remove;
+ //serverCaches[server][\serverQuitUpdater].remove;
serverCaches.removeAt(server);
}
}