Database Reference
In-Depth Information
In this previous example method, we deal with a more complicated situation.
During the development of this method, I started by passing an NSFetchRequest
between the server and clients. This resulted in some terminal errors within
the Core Data stack, which led me to this solution instead. Based on these
experiments, it is clear to me that passing around the NSManagedObjectContext
itself results in some risky situations and should be avoided. However,
NSPredicate objects can be passed around without any issue. Therefore, in this
method, we accept the name of the entity and the NSPredicate to use in the
NSFetchRequest . From this, we build the NSFetchRequest and execute it against the
local NSManagedObjectContext . If there is an error, we print it to the console and
return nil . Otherwise, we return the resulting array.
11.2
Building the Client
The client side of this application is both more complicated and easier than
the server side. Configuring Bonjour and setting up the distributed objects
is a bit more complicated than it is on the server. However, once the distribut-
ed object is configured, the rest of the setup is significantly easier.
In this example, we are going to build a client designed to stress test the
server, as opposed to being truly functional in a user perspective. Our client
is going to connect to the first server it finds, and once the connection is
complete, it will run NSTimer objects to fire against each of the methods on the
server in quick succession. With this type of client, we can stress test the
server with multiple clients and look for race conditions and threading/locking
issues.
Configuring the Xcode Project
Unlike the server, the client is going to start with a Cocoa non-Core Data
application. Because the server is maintaining the Core Data repository, the
client does not need to be configured as a Core Data application. However,
like the server, our user interface is a single window with a single table dis-
playing the results of one of the method calls to the server. See Figure 42,
The distributed client user interface , on page 200 .
Once the DistributedCDClient project has been created, we need to copy the PPDis-
tributedProtocol.h file from the server into the project. Normally I would just
reference the file directly from the server project so that both are using the
same file, but the example has a copy in each project to prevent any errors
in the referencing. Next we need create a new class called AppDelegate and add
it to the project. Once the AppDelegate has been added to the project, we will
need to configure the user interface.
 
 
Search WWH ::




Custom Search