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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Thu Mar 27 15:43:05 2003 UTC (21 years, 1 month ago) by joko
Branch: MAIN
Changes since 1.1: +7 -2 lines
minor fix: new comment/remark

1 ## ----------------------------------------------------------------------
2 ## $Id: Process.pm,v 1.1 2003/02/20 18:41:48 joko Exp $
3 ## ----------------------------------------------------------------------
4 ## $Log: Process.pm,v $
5 ## Revision 1.1 2003/02/20 18:41:48 joko
6 ## + initial commit
7 ##
8 ## ----------------------------------------------------------------------
9
10
11 package App::Process;
12
13 use strict;
14 use warnings;
15
16 use base qw(
17 DesignPattern::Object
18 DesignPattern::Logger
19 );
20
21 use Data::Dumper;
22
23 use shortcuts qw( now );
24
25
26 # --------------------------------------------------- main ------------
27 DesignPattern::Object->log_basic("Package " . __PACKAGE__ . " loaded.");
28
29
30 sub constructor {
31 my $self = shift;
32
33 $self->log( __PACKAGE__ . "->constructor", 'info');
34 #$self->log( "INIT", 'info');
35
36 # trace
37 #print Dumper($self);
38 #exit;
39
40 # just boot database called "oefcore"
41 # TODO: REVIEW: just boot if not booted yet.....
42 # FIXME: this is hardcoded!
43 #$self->{boot} = BizWorks::Boot->new( use_databases => [qw( oefcore )] );
44 #$self->{app}->{use_databases} =|| [qw( oefcore )];
45 $self->_bootDatabases();
46
47 # if no "guid" is given ....
48 if (!$self->{guid}) {
49
50 # ... create fresh task-object, ...
51 $self->{TASK} = Task->new(
52 stamp => now(),
53 #context => ,
54 );
55 $self->{app}->{storage}->{oefcore}->insert($self->{TASK});
56
57 =pod
58 # ... create fresh report-object, ...
59 $self->{REPORT} = Report->new(
60 stamp => now(),
61 #context => ,
62 );
63 $self->{app}->{storage}->{oefcore}->insert($self->{REPORT});
64
65 # ... link them together
66 =cut
67
68 # ... and (finally) assign the Task's GUID to an object attribute here
69 $self->{guid} = $self->{TASK}->{guid};
70
71 } else {
72
73 # load context from (resumed) task
74 # FIXME: move this to OEF::Component::Task::Persistable
75 my $task = $self->{app}->{storage}->{oefcore}->getObjectByGuid($self->{guid}, { classname => 'Task' });
76 $self->{_context_raw} = $task->{context};
77
78 }
79
80
81 }
82
83
84 sub _check {
85 my $self = shift;
86 if (!$self->getGuid()) {
87 return 1;
88 }
89 }
90
91 sub perform {
92 my $self = shift;
93
94 return if ($self->skip("task has no guid", $self->_check()));
95
96 #print Dumper($self);
97 #exit;
98
99 $self->log("task " . $self->getGuid() . " starting.");
100 $self->{TASK}->{begin} = now();
101 $self->run() if $self->can('run');
102 #$self->_run();
103 $self->{TASK}->{end} = now();
104 $self->log("task " . $self->getGuid() . " finished.");
105 }
106
107 sub getGuid {
108 my $self = shift;
109 return $self->{guid};
110 }
111
112 sub _bootDatabases {
113 my $self = shift;
114 #print Dumper($self->{config}->{databases});
115
116 #print Dumper($self);
117 #exit;
118
119 #my $dbkeys = shift;
120 my $dbkeys;
121
122 my $dbcfg;
123
124 # CACHE THIS! JUST BOOT STORAGES INTO CONTAINER IF NOT ALREADY DONE!
125 my $container = DesignPattern::Object->fromPackage('Data::Storage::Container');
126
127 if (my $dbkey_raw = $self->{app}->{use_databases}) {
128 if (ref $dbkey_raw eq 'ARRAY') {
129 $dbkeys = $dbkey_raw;
130 } else {
131 #$self->{app}->{instance}->_bootDatabases();
132 my @dbkeys = split(/,\s|,/, $dbkey_raw);
133 #$self->_bootDatabases(\@dbkeys);
134 $dbkeys = \@dbkeys;
135 }
136 }
137
138 # just boot specified databases
139 if ($dbkeys) {
140 $self->log("Using Database(s): " . join(', ', @{$dbkeys}), 'info');
141 foreach (@$dbkeys) {
142 $dbcfg->{$_} = $self->{app}->{config}->{databases}->{$_};
143 }
144
145 # boot all databases
146 } else {
147 $dbcfg = $self->{app}->{config}->{databases};
148 }
149
150 foreach (keys %$dbcfg) {
151 $container->addConfig($_, $dbcfg->{$_});
152 }
153
154 $container->initLocators();
155 $container->initStorages();
156
157 foreach (keys %{$container->{storage}}) {
158 $self->{app}->{storage}->{$_} = $container->{storage}->{$_};
159 }
160
161 # trace
162 #print Dumper($self);
163
164 }
165
166 sub _shutdownDatabases {
167 my $self = shift;
168 foreach my $dbkey (keys %{$self->{app}->{storage}}) {
169 #print "SHUTDOWN $dbkey", "\n";
170 $self->{app}->{storage}->{$dbkey}->disconnect();
171 }
172 }
173
174 =pod
175 sub DESTROY {
176 my $self = shift;
177 $self->_shutdownDatabases();
178 }
179 =cut
180
181 1;
182 __END__

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