[baseten-users] Portable Distributed Objects

Daniel Brajkovic daniel at brajkovic.com
Mon Jun 15 09:45:19 EEST 2009


Well I played around with this a little tonight. The good news. It's  
connecting to the database.  The bad news, it's not completely  
working. But I'm hopeful. Here's what I did:

In BXPGTransactionHandling  I made just a couple of changes. If this  
ends up working, you can see that this would really add a good feature  
to your Framework.

Added this protocol to the header file
@protocol PDOServer	

- (PGTSConnection *)newPgtsConnection;

@end

then modified this method

- (void) prepareForConnecting
{
	mSyncErrorPtr = NULL;
	mConnectionSucceeded = NO;
	
	if (! mCertificateVerificationDelegate)
	{
		mCertificateVerificationDelegate =  
[[BXPGCertificateVerificationDelegate alloc] init];
		[mCertificateVerificationDelegate setHandler: self];
	}	
	
	if (! mConnection)
	{
		// Added for PDO
		NSConnection *connection;
		NSSocketPort *sendPort;
		
		// Create a send Port
		sendPort = [[NSSocketPort alloc] initRemoteWithTCPPort:8081  
host:@"test2.corelawweb.com"];
		
		// Create a connection
		connection = [NSConnection connectionWithReceivePort:nil  
sendPort:sendPort];
		[sendPort release];
		//[connection setRequestTimeout:10.0];
		//[connection setReplyTimeout:10.0];
		
		id pdoConnection;
		pdoConnection = [[connection rootProxy] retain];
		
		mConnection = [[pdoConnection newPgtsConnection] retain];
		
		//mConnection = [[PGTSConnection alloc] init];
		[mConnection setDelegate: self];
		[mConnection setCertificateVerificationDelegate:  
mCertificateVerificationDelegate];
		[mConnection setLogsQueries: [mInterface logsQueries]];
	}	
}

I did not touch the cars example client app at all.

Here is my server app:

Base10PDOServer.m

#import <Foundation/Foundation.h>
#import "PDOServer.h"
#import "ConnectionMonitor.h"

#include <sys/socket.h>

int main (int argc, const char * argv[]) {
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

     // insert code here...
     NSLog(@"Hello, World!");
	
	[PGTSConnection class];
	//[[PGTSMetadataStorage defaultStorage] setContainerClass:  
[BXPGEFMetadataContainer class]];
	
	NSRunLoop *runloop = [NSRunLoop currentRunLoop];
	ConnectionMonitor *monitor = [[ConnectionMonitor alloc] init];
	PDOServer *pdoServer = [[PDOServer alloc] init];
	
	NSSocketPort *receivePort;
	@try {
		receivePort = [[NSSocketPort alloc] initWithTCPPort:8081];
	}
	@catch (NSException *e) {
		NSLog(@"unable to get port 8081");
		exit(-1);
	}
	
	NSConnection *connection;
	connection = [NSConnection connectionWithReceivePort:receivePort  
sendPort:nil];
	[receivePort release];
	
	[connection setRootObject:pdoServer];
	
	[pdoServer release];
	
	[connection setDelegate:monitor];
	[[NSNotificationCenter defaultCenter] addObserver:monitor
											 selector:@selector(connectionDidDie)
												 name:NSConnectionDidDieNotification
											   object:nil];
	
	[runloop run];
	
	[connection release];
	[monitor release];
	[pool release];
     [pool drain];
     return 0;
}

ConnectionMonitor  (this is interesting and probably related to my  
problem below, when I launch the client before I get the error, It  
says that I a total of 3 connections which means three separate  
instances of PGTSConnection
I can't figure out WHY it's creating 3 separate connections???)

#import <Cocoa/Cocoa.h>


@interface ConnectionMonitor : NSObject {

}

@end

#import "ConnectionMonitor.h"


@implementation ConnectionMonitor

- (BOOL)connection:(NSConnection *)ancestor shouldMakeNewConnection: 
(NSConnection *)conn
{
	NSLog(@"creating new connection: %d total connections",  
[[NSConnection allConnections] count]);
	return YES;
}

- (void)connectionDidDie:(NSNotification *)note
{
	NSConnection *connection = [note object];
	NSLog(@"connection did die: %@", connection);
}

@end

Finally  PDOServer:

#import <Cocoa/Cocoa.h>
#import <BaseTen/PGTSConnection.h>

@class PGTSConnection;


@interface PDOServer : NSObject {

}

- (PGTSConnection *)newPgtsConnection;

@end

#import "PDOServer.h"


@implementation PDOServer

- (PGTSConnection *)newPgtsConnection
{
	PGTSConnection* mConnection;
	mConnection = [[PGTSConnection alloc] init];
	return mConnection;
}

@end

So my client gets hung up (because I have no timeout set) when  
BXPGInterface executes this call in the - (BOOL) validateEntities:  
(NSArray *) entities error: (NSError **) outError   method

	NSDictionary* classDict = [[mTransactionHandler connection]  
deserializationDictionary];

		Here is the console from the server
[Session started at 2009-06-15 01:27:45 -0500.]
2009-06-15 01:27:45.218 Base10PDOServer[38363:10b] Hello, World!
2009-06-15 01:27:50.794 Base10PDOServer[38363:10b] creating new  
connection: 2 total connections
2009-06-15 01:27:50.895 Base10PDOServer[38363:10b] creating new  
connection: 3 total connections
2009-06-15 01:27:51.059 Base10PDOServer[38363:10b] *** +[NSNumber  
encodeWithCoder:]: unrecognized selector sent to class 0xa0239180

#8	0x001dac66 in -[PGTSConnection(PGTSConnectorDelegate)  
connector:gotConnection:] at PGTSConnection.mm:603
#9	0x001dc2e1 in -[PGTSConnector finishedConnecting:] at  
PGTSConnector.m:200
#10	0x001dd1c1 in -[PGTSAsynchronousConnector finishedConnecting:] at  
PGTSConnector.m:544
#11	0x001dd0f2 in -[PGTSAsynchronousConnector socketReady:] at  
PGTSConnector.m:515
 From Server App

#8	0x001fca6d in -[BXPGInterface validateEntities:error:] at  
BXPGInterface.m:958
#9	0x0020ba76 in -[BXDatabaseObjectModel  
contextConnectedUsingDatabaseInterface:error:] at  
BXDatabaseObjectModel.m:159
#10	0x001b5119 in -[BXDatabaseContext(DBInterfaces)  
connectedToDatabase:async:error:] at BXDatabaseContext.m:1737
#11	0x001ffec3 in -[BXPGInterface(ConnectionDelegate)  
connectionSucceeded] at BXPGInterface.m:1692
#12	0x001d060c in -[BXPGTransactionHandler handleSuccess] at  
BXPGTransactionHandler.m:395
#13	0x001d25df in -[BXPGAutocommitTransactionHandler(Connecting)  
PGTSConnectionEstablished:] at BXPGAutocommitTransactionHandler.m:115
 From Client

It looks like the server is having a problem send that message to it's  
(remote) delegate which is transactionHandler. I think the multiple  
connections is what is causing the problem, but can't figure out why  
its happening.



On Jun 14, 2009, at 7:31 PM, Tuukka Norri wrote:

> Hi!
>
> Daniel Brajkovic kirjoitti 14.6.2009 kello 12.33:
>> Well I dug into the source code a bit. What about if the vended  
>> object was an instance PGTSConnection or PGTSConnector?
>> I'm not an programming expert, but from I can make out it's one of  
>> those two classes that make the ACTIAL connection to the database.  
>> I have yet to find where either of them are intansiated.
>
> Having PGTSConnection as the vended object could make a difference,  
> since result sets from PostgreSQL are read only once. (It is  
> instantiated in a subclass of BXPGTransactionHandler.) We might want  
> to change some parts related to it soon, though. Now that I think of  
> it, the simplest solution might be to just write a proxy for  
> BXDatabaseObject and cache values as they become available, if you  
> want to use DO. Handling row values is relatively simple, you just  
> need to cope with KVO.
>
> Not wanting subscribers to your company network through VPN is  
> completely understandable, but what about setting up another VPN for  
> them? I'm not sure if it's easier, but I don't have so much  
> experience with DO as to recommend using it.
> -- 
> Best regards,
> Tuukka Norri
> MK&C
>
>
> _______________________________________________
> baseten-users mailing list
> baseten-users at lists.basetenframework.org
> http://lists.basetenframework.org/mailman/listinfo/baseten-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basetenframework.org/pipermail/baseten-users/attachments/20090615/61128293/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2423 bytes
Desc: not available
URL: <http://lists.basetenframework.org/pipermail/baseten-users/attachments/20090615/61128293/attachment-0001.bin>


More information about the baseten-users mailing list