/[cvs]/nfo/perl/libs/App/Process.pm
ViewVC logotype

Annotation of /nfo/perl/libs/App/Process.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Wed Dec 3 00:21:38 2003 UTC (20 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.3: +10 -2 lines
+ minor fix to '_bootDatabases': instantiate the DSC-container if no ref to it exists

1 joko 1.1 ## ----------------------------------------------------------------------
2 joko 1.4 ## $Id: Process.pm,v 1.3 2003/06/06 03:14:16 joko Exp $
3 joko 1.1 ## ----------------------------------------------------------------------
4 joko 1.2 ## $Log: Process.pm,v $
5 joko 1.4 ## Revision 1.3 2003/06/06 03:14:16 joko
6     ## enhanced database connection bootstrapping:
7     ## - boot default ones
8     ## - boot-on-demand
9     ## - protection for multiple redundant connections
10     ##
11 joko 1.3 ## Revision 1.2 2003/03/27 15:43:05 joko
12     ## minor fix: new comment/remark
13     ##
14 joko 1.2 ## Revision 1.1 2003/02/20 18:41:48 joko
15     ## + initial commit
16     ##
17 joko 1.1 ## ----------------------------------------------------------------------
18    
19    
20 joko 1.3 =pod
21    
22     This could also be called App::Component, App::Bean or whatever.
23     Since it conducts various things of the OEF framework,
24     it should probably be better renamed to OEF::App::Xyz, hmmm!?
25     OEF::App::Bean? OEF::App::Bimbo? Yakka and Bimbo...
26    
27     =cut
28    
29    
30 joko 1.1 package App::Process;
31    
32     use strict;
33     use warnings;
34    
35     use base qw(
36     DesignPattern::Object
37     DesignPattern::Logger
38     );
39    
40     use Data::Dumper;
41    
42     use shortcuts qw( now );
43    
44    
45     # --------------------------------------------------- main ------------
46     DesignPattern::Object->log_basic("Package " . __PACKAGE__ . " loaded.");
47    
48    
49     sub constructor {
50     my $self = shift;
51    
52     $self->log( __PACKAGE__ . "->constructor", 'info');
53     #$self->log( "INIT", 'info');
54    
55     # trace
56     #print Dumper($self);
57     #exit;
58    
59     # just boot database called "oefcore"
60     # TODO: REVIEW: just boot if not booted yet.....
61     # FIXME: this is hardcoded!
62     #$self->{boot} = BizWorks::Boot->new( use_databases => [qw( oefcore )] );
63     #$self->{app}->{use_databases} =|| [qw( oefcore )];
64     $self->_bootDatabases();
65    
66     # if no "guid" is given ....
67     if (!$self->{guid}) {
68    
69     # ... create fresh task-object, ...
70     $self->{TASK} = Task->new(
71     stamp => now(),
72     #context => ,
73     );
74     $self->{app}->{storage}->{oefcore}->insert($self->{TASK});
75    
76     =pod
77     # ... create fresh report-object, ...
78     $self->{REPORT} = Report->new(
79     stamp => now(),
80     #context => ,
81     );
82     $self->{app}->{storage}->{oefcore}->insert($self->{REPORT});
83    
84     # ... link them together
85     =cut
86    
87     # ... and (finally) assign the Task's GUID to an object attribute here
88     $self->{guid} = $self->{TASK}->{guid};
89    
90     } else {
91    
92     # load context from (resumed) task
93     # FIXME: move this to OEF::Component::Task::Persistable
94     my $task = $self->{app}->{storage}->{oefcore}->getObjectByGuid($self->{guid}, { classname => 'Task' });
95     $self->{_context_raw} = $task->{context};
96    
97     }
98    
99    
100     }
101    
102    
103     sub _check {
104     my $self = shift;
105     if (!$self->getGuid()) {
106     return 1;
107     }
108     }
109    
110     sub perform {
111     my $self = shift;
112    
113     return if ($self->skip("task has no guid", $self->_check()));
114    
115     #print Dumper($self);
116     #exit;
117    
118     $self->log("task " . $self->getGuid() . " starting.");
119     $self->{TASK}->{begin} = now();
120     $self->run() if $self->can('run');
121     #$self->_run();
122     $self->{TASK}->{end} = now();
123     $self->log("task " . $self->getGuid() . " finished.");
124     }
125    
126     sub getGuid {
127     my $self = shift;
128     return $self->{guid};
129     }
130    
131     sub _bootDatabases {
132     my $self = shift;
133    
134 joko 1.3 # re-enabled as of 2003-05-16: Now accepts db-keys via method-args again!
135     my $dbkeys = shift;
136    
137     #my $dbkeys;
138 joko 1.1 my $dbcfg;
139 joko 1.2
140 joko 1.3 # A - Build list of db-keys to boot
141 joko 1.1
142 joko 1.3 # FIXME: CACHE THIS! JUST BOOT STORAGES INTO CONTAINER IF NOT ALREADY DONE!
143     # WATCH OUT FOR GLOBAL USED RESOURCES!
144 joko 1.4 if (not ref $self->{DSC} eq 'Data::Storage::Container') {
145     $self->{DSC} = DesignPattern::Object->fromPackage('Data::Storage::Container');
146     }
147 joko 1.3
148     # Check if database keys were specified explicitely
149     # as default inside the application container ...
150     # new of 2003-05-16: Just do this if no dbkeys have been passed in via args.
151     $dbkeys ||= $self->_get_dbkeys_app_defaults();
152 joko 1.1
153 joko 1.3 # ... if yes, just boot specified databases...
154 joko 1.1 if ($dbkeys) {
155 joko 1.3
156     $self->log("Using database(s): " . join(', ', @{$dbkeys}), 'info');
157 joko 1.1 foreach (@$dbkeys) {
158     $dbcfg->{$_} = $self->{app}->{config}->{databases}->{$_};
159     }
160    
161 joko 1.3 # ... otherwise boot all databases.
162 joko 1.1 } else {
163 joko 1.3 $self->log("Using all databases.", 'info');
164 joko 1.1 $dbcfg = $self->{app}->{config}->{databases};
165     }
166    
167 joko 1.3
168     # B - Propagate stuff to application -config and -resource slots etc.
169     # TODO: refactor: abstract this out
170    
171     # B.1 - Initialize config
172 joko 1.1 foreach (keys %$dbcfg) {
173 joko 1.3 $self->{DSC}->addConfig($_, $dbcfg->{$_});
174 joko 1.1 }
175    
176 joko 1.3 # B.2 - Initialize resources
177     $self->{DSC}->initLocators();
178     $self->{DSC}->initStorages();
179    
180     # B.3 - Establish symbols inside the application container
181     # as references to the storage handle instances inside the
182     # storage container singleton.
183     # In other words: spread the refs
184     # FIXME: This should be cleared up somehow! ;-)
185     foreach (keys %{$self->{DSC}->{storage}}) {
186     $self->{app}->{storage}->{$_} = $self->{DSC}->{storage}->{$_};
187     }
188    
189     }
190 joko 1.1
191 joko 1.3 sub _get_dbkeys_app_defaults {
192     my $self = shift;
193     my $dbkeys;
194     if (my $dbkey_raw = $self->{app}->{use_databases}) {
195     if (ref $dbkey_raw eq 'ARRAY') {
196     $dbkeys = $dbkey_raw;
197     } else {
198     #$self->{app}->{instance}->_bootDatabases();
199     my @dbkeys = split(/,\s|,/, $dbkey_raw);
200     #$self->_bootDatabases(\@dbkeys);
201     $dbkeys = \@dbkeys;
202     }
203 joko 1.1 }
204 joko 1.3 return $dbkeys;
205 joko 1.1 }
206    
207     sub _shutdownDatabases {
208     my $self = shift;
209     foreach my $dbkey (keys %{$self->{app}->{storage}}) {
210     #print "SHUTDOWN $dbkey", "\n";
211 joko 1.3 #print Dumper($self->{app}->{storage}->{$dbkey});
212     my $handle = $self->{app}->{storage}->{$dbkey};
213     #print ref $handle, "\n";
214     #next if not $handle or not ref $handle or ref($handle) =~ m/(ARRAY|HASH)/;
215     next if not $handle or not ref $handle or ref($handle) !~ m/(Data::Storage|DBI)/;
216     $handle->disconnect();
217 joko 1.1 }
218     }
219    
220 joko 1.3 #=pod
221 joko 1.1 sub DESTROY {
222     my $self = shift;
223     $self->_shutdownDatabases();
224     }
225 joko 1.3 #=cut
226    
227    
228     sub activate_resources {
229     my $self = shift;
230     my $args = shift;
231     $self->_bootDatabases($args);
232     }
233    
234     sub resource_is_active {
235     my $self = shift;
236     my $key = shift;
237     # FIXME: Enhance this!
238     #print "key: $key", "\n";
239     #print Dumper($self->{DSC}->{storage});
240     return 1 if exists $self->{DSC}->{storage}->{$key};
241     }
242 joko 1.1
243     1;
244     __END__

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed