/[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.5 - (hide annotations)
Sat Jun 19 01:51:21 2004 UTC (19 years, 11 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +6 -1 lines
don't do any "Task"-handling (would require db "oefcore")

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

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