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