Database Reference
In-Depth Information
Receiving Requests from Clients
Working with distributed objects is deceptively easy. Other than the minor
alterations to the method signatures, there are no changes to the methods
and how they are handled. However, whenever we write a method that is
going to be accessed via distributed objects, we need to remember it is not
being called locally; therefore, we need to keep a few things in mind.
• The server configuration we have built in this example has one incoming
socket: it can process only one request at a time. If a request takes too
long (demonstrated in a moment), all the other clients wait in line,
including calls from the same client.
• Although we can pass objects by reference to the client, if those objects
get passed back to the server by reference, it can cause confusion. This
is especially true when dealing with NSManagedObject objects. Therefore,
whenever we receive an NSManagedObject from the client, we resolve a local
reference and perform any actions on the local reference instead of trying
to use the client reference a second time on the server.
-ping Implementation
The first method I always implement when building a distributed object
application is -ping . I use this method to test the connectivity between the
client and the server. Since this method does nothing other than print out a
console message, I am guaranteed that no other programming errors will be
introduced while I test the connectivity.
DistributedCDServer/AppDelegate.m
- (oneway void )ping
{
NSLog(@ "%@:%s received" , [self class], __PRETTY_FUNCTION__);
}
-allObjects Implementation
This is one of those methods that is at risk of taking too long.
DistributedCDServer/AppDelegate.m
- (byref NSArray*)allObjects
{
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@ "Test"
inManagedObjectContext:context];
[request setEntity:entity];
 
 
 
Search WWH ::




Custom Search