Author: spadkins
Date: Tue Mar 21 09:45:08 2006
New Revision: 3705
Modified:
p5ee/trunk/App-Context/lib/App/Context.pm
Log:
add response(), renew_process_resources(), fork()
Modified: p5ee/trunk/App-Context/lib/App/Context.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context.pm (original)
+++ p5ee/trunk/App-Context/lib/App/Context.pm Tue Mar 21 09:45:08 2006
@@ -2014,6 +2014,91 @@
&App::sub_exit() if ($App::trace);
}
+=head2 fork()
+
+ * Signature: $pid = $self->fork()
+ * Param: void
+ * Return: $pid integer
+ * Throws: App::Exception
+ * Since: 0.01
+
+ Sample Usage:
+
+ $self->fork();
+
+The fork() method is called in a child process just after
+it has been fork()ed.
+This causes connections to databases, etc. to be closed gracefully and new
+connections to be created if necessary.
+
+Call this after a fork() in the child process.
+It will renew the resources which cannot be shared between a parent and
+a child process.
+
+Currently, this is primarily for database connections.
+For most databases, the child needs its own connection.
+
+=cut
+
+sub fork {
+ &App::sub_entry if ($App::trace);
+ my ($self) = @_;
+ my $pid = fork();
+ if (!$pid) { # in the child process
+ $self->renew_process_resources();
+ }
+ &App::sub_exit($pid) if ($App::trace);
+ return($pid);
+}
+
+#############################################################################
+# renew_process_resources()
+#############################################################################
+
+=head2 renew_process_resources()
+
+ * Signature: $self->renew_process_resources()
+ * Param: void
+ * Return: void
+ * Throws: App::Exception
+ * Since: 0.01
+
+ Sample Usage:
+
+ $self->renew_process_resources();
+
+The renew_process_resources() method is called in a child process just after
+it has been fork()ed.
+This causes connections to databases, etc. to be closed gracefully and new
+connections to be created if necessary.
+
+Call this after a fork() in the child process.
+It will renew the resources which cannot be shared between a parent and
+a child process.
+
+Currently, this is primarily for database connections.
+For most databases, the child needs its own connection.
+
+=cut
+
+sub renew_process_resources {
+ my $self = shift;
+ my ($conf, $repdef, $repname, $instance);
+ my ($class, $method, $args, $argidx, $repcache);
+
+ $self->dbgprint("Context->renew_process_resources()")
+ if ($App::DEBUG && $self->dbg(1));
+
+ $repcache = $self->{session}{cache}{Repository};
+ if (defined $repcache && ref($repcache) eq "HASH") {
+ foreach $repname (keys %$repcache) {
+ $instance = $repcache->{$repname};
+ $instance->_renew_process_resources();
+ delete $repcache->{$repname};
+ }
+ }
+}
+
#############################################################################
# shutdown()
#############################################################################
@@ -2057,5 +2142,49 @@
}
}
+#############################################################################
+# response()
+#############################################################################
+
+=head2 response()
+
+ * Signature: $context->response()
+ * Param: void
+ * Return: void
+ * Throws: App::Exception
+ * Since: 0.01
+
+ Sample Usage:
+
+ $context->response();
+
+The response() method gets the current Response being handled in the Context.
+
+=cut
+
+sub response {
+ &App::sub_entry if ($App::trace);
+ my $self = shift;
+
+ my $response = $self->{response};
+ if (!defined $response) {
+
+ #################################################################
+ # RESPONSE
+ #################################################################
+
+ my $response_class = $self->get_option("response_class", "App::Response");
+
+ eval {
+ $response = App->new($response_class, "new", $self, $self->{options});
+ };
+ $self->{response} = $response;
+ $self->add_message("Context::response(): $@") if ($@);
+ }
+
+ &App::sub_exit($response) if ($App::trace);
+ return($response);
+}
+
1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.