Re: Now URL connection delegate isn't called at all
Re: Now URL connection delegate isn't called at all
- Subject: Re: Now URL connection delegate isn't called at all
- From: Steve Sisak <email@hidden>
- Date: Thu, 22 Mar 2012 22:58:25 -0400
At 3:23 PM -0700 3/21/12, Jens Alfke wrote:
I've created a global NSOperationQueue to serialize access to the
code that runs TouchDB, a NoSQL database, since the code is not
thread-safe.
This code ends up starting asynchronous NSURLConnections to
communicate with other servers.
OK, this is very similar to what I've been doing lately -- the
difference being I'm doing multi-threaded access to QuickTime and
pulling in data over HTTP connections, which appears to be very
structurally similar to what you're doing.
Here are a couple suggestions:
1) If you haven't already, read Technote 2125
<http://developer.apple.com/library/mac/#technotes/tn2125/_index.html>
While it's specific to QuickTime, the rules and techniques would
apply exactly to what you're doing -- only instead only touching a
movie from a single thread, you're only touching a database from a
single thread.
2) look at (and steal code from) LinkedImageFetcher:
<http://developer.apple.com/library/mac/#samplecode/LinkedImageFetcher/>
Specifically, you want to steal the Core Code directory.
The key pieces are:
QWatchedOperationQueue is a subclass of NSOperationQueue which takes
pains to always do notification on a RunLoop that you specify.
QHTTPOperation is a wrapper for for NSURLConnection which does all
the right stuff and communicates with QWatchedOperationQueue -- you
should be able to either steal it or clone it and change the scheme.
Create a service thread for your database instance, point a
QWatchedOperationQueue at it, and do all your database access from
that thread, either directly or via
-performSelector:onThread:withObject:waitUntilDone: or a subclass of
QRunLoopOperation.
I've been doing some _very_ heavy lifting with this architecture, and
it's been rock solid.
I've got a utility thread class I can ship you if you like -- you can
either start the thread explicitly or as a side effect of calling
-runLoop or -thread on the object, which solved the chicken-and-egg
problem.
HTH,
-Steve
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden