From 43ff520ad942a665c6711bbdf1afc0b6e61a43d6 Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 30 Jun 2004 21:46:12 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@129 d1b88da0-ebda-0310-925b-ed51d893ca5b --- OGoContentStore/ChangeLog | 2 + OGoContentStore/OCSChannelManager.h | 6 +- OGoContentStore/OCSChannelManager.m | 167 ++++++++++++++++++++-- SOGo/UI/Scheduler/ChangeLog | 2 + SOGo/UI/Scheduler/UIxCalMonthOverview.wox | 63 ++++---- SOGo/UI/Scheduler/UIxCalWeekOverview.wox | 120 +++++++++------- 6 files changed, 265 insertions(+), 95 deletions(-) diff --git a/OGoContentStore/ChangeLog b/OGoContentStore/ChangeLog index d23be329..8c983633 100644 --- a/OGoContentStore/ChangeLog +++ b/OGoContentStore/ChangeLog @@ -1,5 +1,7 @@ 2004-06-30 Helge Hess + * OCSChannelManager.m: implemented pooling + * OCSFolder.m: added quick fetches * GNUmakefile.preamble: fix link path diff --git a/OGoContentStore/OCSChannelManager.h b/OGoContentStore/OCSChannelManager.h index c95ccc99..c888ec35 100644 --- a/OGoContentStore/OCSChannelManager.h +++ b/OGoContentStore/OCSChannelManager.h @@ -31,12 +31,16 @@ This object manages the connection pooling. */ -@class NSURL, NSMutableDictionary; +@class NSURL, NSMutableDictionary, NSMutableArray, NSTimer; @class EOAdaptorChannel, EOAdaptor; @interface OCSChannelManager : NSObject { NSMutableDictionary *urlToAdaptor; + + NSMutableArray *availableChannels; + NSMutableArray *busyChannels; + NSTimer *gcTimer; } + (id)defaultChannelManager; diff --git a/OGoContentStore/OCSChannelManager.m b/OGoContentStore/OCSChannelManager.m index 881f9c30..2b568c99 100644 --- a/OGoContentStore/OCSChannelManager.m +++ b/OGoContentStore/OCSChannelManager.m @@ -37,22 +37,32 @@ @interface OCSChannelHandle : NSObject { @public + NSURL *url; EOAdaptorChannel *channel; NSDate *creationTime; NSDate *lastReleaseTime; NSDate *lastAcquireTime; } +- (EOAdaptorChannel *)channel; +- (BOOL)canHandleURL:(NSURL *)_url; +- (NSTimeInterval)age; + @end @implementation OCSChannelManager -static BOOL debugOn = YES; +static BOOL debugOn = YES; +static BOOL debugPools = YES; +static int ChannelExpireAge = 180; + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; debugOn = [ud boolForKey:@"OCSChannelManagerDebugEnabled"]; + ChannelExpireAge = [[ud objectForKey:@"OCSChannelExpireAge"] intValue]; + if (ChannelExpireAge < 1) + ChannelExpireAge = 180; } + (NSString *)adaptorNameForURLScheme:(NSString *)_scheme { @@ -69,13 +79,20 @@ static BOOL debugOn = YES; - (id)init { if ((self = [super init])) { - self->urlToAdaptor = [[NSMutableDictionary alloc] initWithCapacity:4]; + self->urlToAdaptor = [[NSMutableDictionary alloc] initWithCapacity:4]; + self->availableChannels = [[NSMutableArray alloc] initWithCapacity:16]; + self->busyChannels = [[NSMutableArray alloc] initWithCapacity:16]; } return self; } - (void)dealloc { - [self->urlToAdaptor release]; + if (self->gcTimer) [self->gcTimer invalidate]; + [self->gcTimer release]; + + [self->busyChannels release]; + [self->availableChannels release]; + [self->urlToAdaptor release]; [super dealloc]; } @@ -157,6 +174,34 @@ static BOOL debugOn = YES; /* channels */ +- (OCSChannelHandle *)findBusyChannelHandleForChannel:(EOAdaptorChannel *)_ch { + NSEnumerator *e; + OCSChannelHandle *handle; + + e = [self->busyChannels objectEnumerator]; + while ((handle = [e nextObject])) { + if ([handle channel] == _ch) + return handle; + } + return nil; +} +- (OCSChannelHandle *)findAvailChannelHandleForURL:(NSURL *)_url { + NSEnumerator *e; + OCSChannelHandle *handle; + + e = [self->availableChannels objectEnumerator]; + while ((handle = [e nextObject])) { + if ([handle canHandleURL:_url]) + return handle; + + if (debugPools) { + [self logWithFormat:@"DBPOOL: cannot use handle (%@ vs %@)", + [_url absoluteString], [handle->url absoluteString]]; + } + } + return nil; +} + - (EOAdaptorChannel *)_createChannelForURL:(NSURL *)_url { EOAdaptor *adaptor; EOAdaptorContext *adContext; @@ -179,23 +224,89 @@ static BOOL debugOn = YES; - (EOAdaptorChannel *)acquireOpenChannelForURL:(NSURL *)_url { // TODO: naive implementation, add pooling! EOAdaptorChannel *channel; + OCSChannelHandle *handle; + NSCalendarDate *now; + + now = [NSCalendarDate date]; + + /* look for cached handles */ + + if ((handle = [self findAvailChannelHandleForURL:_url]) != nil) { + // TODO: check age? + [self->busyChannels addObject:handle]; + [self->availableChannels removeObject:handle]; + ASSIGN(handle->lastAcquireTime, now); + + if (debugPools) + [self logWithFormat:@"DBPOOL: reused cached DB channel!"]; + return [[handle channel] retain]; + } + + if (debugPools) { + [self logWithFormat:@"DBPOOL: create new DB channel for URL: %@", + [_url absoluteString]]; + } + + /* create channel */ if ((channel = [self _createChannelForURL:_url]) == nil) - return channel; + return nil; if ([channel isOpen]) - return [channel retain]; - - if (![channel openChannel]) { + ; + else if (![channel openChannel]) { [self logWithFormat:@"could not open channel %@ for URL: %@", channel, _url]; return nil; } + /* create handle for channel */ + + handle = [[OCSChannelHandle alloc] init]; + handle->url = [_url retain]; + handle->channel = [channel retain]; + handle->creationTime = [now retain]; + handle->lastAcquireTime = [now retain]; + + [self->busyChannels addObject:handle]; + [handle release]; + return [channel retain]; } - (void)releaseChannel:(EOAdaptorChannel *)_channel { - // TODO: naive implementation, add pooling! + OCSChannelHandle *handle; + + if ((handle = [self findBusyChannelHandleForChannel:_channel]) != nil) { + NSCalendarDate *now; + + now = [NSCalendarDate date]; + + handle = [handle retain]; + ASSIGN(handle->lastReleaseTime, now); + + [self->busyChannels removeObject:handle]; + + if ([[handle channel] isOpen] && [handle age] < ChannelExpireAge) { + // TODO: consider age + [self->availableChannels addObject:handle]; + if (debugPools) { + [self logWithFormat: + @"DBPOOL: keeping channel (age %ds, #%d): %@", + (int)[handle age], [self->availableChannels count], + [handle->url absoluteString]]; + } + [_channel release]; + [handle release]; + return; + } + + [self logWithFormat: + @"DBPOOL: freeing old channel (age %ds)", (int)[handle age]]; + + /* not reusing channel */ + [handle release]; handle = nil; + } + if ([_channel isOpen]) [_channel closeChannel]; @@ -271,6 +382,46 @@ static BOOL debugOn = YES; return self->channel; } +- (BOOL)canHandleURL:(NSURL *)_url { + if (_url == nil) { + [self logWithFormat:@"MISMATCH: no url .."]; + return NO; + } + if (_url == self->url) + return YES; + + if (![[self->url host] isEqual:[_url host]]) { + [self logWithFormat:@"MISMATCH: different host .."]; + return NO; + } + if (![[self->url ocsDatabaseName] isEqualToString:[_url ocsDatabaseName]]) { + [self logWithFormat:@"MISMATCH: different db .."]; + return NO; + } + if (![[self->url user] isEqual:[_url user]]) { + [self logWithFormat:@"MISMATCH: different user .."]; + return NO; + } + if ([[self->url port] intValue] != [[_url port] intValue]) { + [self logWithFormat:@"MISMATCH: different port (%@ vs %@) ..", + [self->url port], [_url port]]; + return NO; + } + + return YES; +} + +- (NSTimeInterval)age { + return [[NSCalendarDate calendarDate] + timeIntervalSinceDate:self->creationTime]; +} + +/* NSCopying */ + +- (id)copyWithZone:(NSZone *)_zone { + return [self retain]; +} + /* description */ - (NSString *)description { diff --git a/SOGo/UI/Scheduler/ChangeLog b/SOGo/UI/Scheduler/ChangeLog index 8ce1d802..a29b19b7 100644 --- a/SOGo/UI/Scheduler/ChangeLog +++ b/SOGo/UI/Scheduler/ChangeLog @@ -1,5 +1,7 @@ 2004-06-30 Helge Hess + * UIxCalWeekOverview.wox, UIxCalMonthOverview.wox: some minor tweaks + * UIxAppointmentView.wox: made the attendee emails clickable * UIxCalView.m: removed -fetchGIDs, moved -fetchCoreInfos to client diff --git a/SOGo/UI/Scheduler/UIxCalMonthOverview.wox b/SOGo/UI/Scheduler/UIxCalMonthOverview.wox index 4abc89bc..dd690808 100644 --- a/SOGo/UI/Scheduler/UIxCalMonthOverview.wox +++ b/SOGo/UI/Scheduler/UIxCalMonthOverview.wox @@ -82,47 +82,48 @@ > - + - + - + - - + + - + - - - - -
- - [new] - -
+ + + + +
+ + [new] + +
- - + + diff --git a/SOGo/UI/Scheduler/UIxCalWeekOverview.wox b/SOGo/UI/Scheduler/UIxCalWeekOverview.wox index b07f74e8..53d61a90 100644 --- a/SOGo/UI/Scheduler/UIxCalWeekOverview.wox +++ b/SOGo/UI/Scheduler/UIxCalWeekOverview.wox @@ -47,34 +47,47 @@ -- 2.39.5
- - +
- - - + + +
OverviewChartListOverviewChartList - Columns + Columns
- - - - - -
- printview - - proposal -
+ + + + + +
+ printview + + proposal +
@@ -88,47 +101,44 @@ const:titleStyle="weekoverview_title" contentStyle="contentStyle" > - - - - - - -
- - -
- [new] -
-
- - - - - - - - - - + + + + + + +
+ + +
+ [new] +
+
+ + + + + + + + + + - + - +