apm_load_any_changed_libraries (public)

 apm_load_any_changed_libraries [ -version_files version_files ] \
    [ errorVarName ]

Defined in packages/acs-tcl/tcl/apm-procs.tcl

In the running interpreter, reloads files marked for reload by apm_mark_version_for_reload. If any watches are set, examines watched files to see whether they need to be reloaded as well. This is intended to be called only by the request processor (since it should be invoked before any filters or registered procedures are applied).

Switches:
-version_files (optional)
Parameters:
errorVarName (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-admin/www/apm/version-reload.tcl packages/acs-admin/ www/apm/version-reload.tcl apm_load_any_changed_libraries apm_load_any_changed_libraries packages/acs-admin/www/apm/version-reload.tcl->apm_load_any_changed_libraries rp_filter rp_filter (private) rp_filter->apm_load_any_changed_libraries apm_get_changed_watched_files apm_get_changed_watched_files (private) apm_load_any_changed_libraries->apm_get_changed_watched_files apm_package_reload_cmds apm_package_reload_cmds (private) apm_load_any_changed_libraries->apm_package_reload_cmds

Testcases:
No testcase defined.
Source code:
    set files $version_files

    if {$errorVarName ne ""} {
        upvar $errorVarName errors
    } else {
        array set errors [list]
    }

    if {$::apm::reloading eq "blueprint"} {
        #ns_log notice "### blueprint_reloading: apm_load_any_changed_libraries [time {apm_get_changed_watched_files}]"

        #
        # Add the watched files, but don't load these if these are
        # already included.
        #
        foreach file [apm_get_changed_watched_files] {
            if {$file ni $files} {
                lappend files $file
            }
        }
        if {[llength $files] > 0} {
            ns_log notice "### blueprint_reloading: [llength $files] files $files"
            #::xo::broadcast send {ns_ictl markfordelete}
            #
            # Transform files into reload-cmds
            #
            set cmds [apm_package_reload_cmds $files]
            #
            # Execute these cmds in a fresh interp to produce a new
            # blueprint.
            #
            set before [list epoch [ns_ictl epoch] size [string length [ns_ictl get]]]
            ns_log notice "### blueprint_reloading: before $before cmds:\n[join $cmds \;\n]"

            ns_eval [join $cmds \;]
            #
            # The current thread has still the old blueprint. If we
            # would modify the naviserver sources, it would be simple
            # the show the diffs. here, it is more involved. The see
            # the effect in size on the blueprint, we have to run the
            # change statistics in a fresh thread.  Let us hope that
            # the ns_job thread update is not deferred by "ns_ictl
            # maxconcurrentupdates", so we report as well the
            # epoch. If there is a new epoch shown, one can be sure
            # that we see the updated size. Otherwise, one will see
            # this on the next reload in the log file.
            #
            ns_job queue ns_eval_q:[ns_info server] [subst -nocommands {
                #
                # Warning: Avoid dollar-substitution here, unless
                # wanted at job registration time.
                #
                set blueprint [ns_ictl get]
                set after [list epoch [ns_ictl epoch] size [string length [set blueprint]]]
                set diff [expr {[dict get [set after] size] - [dict get {$before} size]}]
                ns_log notice "### blueprint_reloading: after [set after] diff [set diff]"
                if {0 && [set diff] != 0} {
                    set F [open /tmp/__blueprint.[clock seconds] w]
                    puts [set F] [set blueprint]
                    close [set F]
                }
            }]
        }
    }

    if {$::apm::reloading eq "classic"} {

        #ns_log notice "### classic_reloading: apm_load_any_changed_libraries"

        #
        # Determine the current reload level in this interpreter by
        # calling apm_reload_level_in_this_interpreter. If this fails, we
        # define the reload level to be zero.
        #
        if { [catch { set reload_level [apm_reload_level_in_this_interpreter] } error] } {
            proc apm_reload_level_in_this_interpreter {} { return 0 }
            set reload_level 0
        }

        #
        # Check watched files, adding them to files_to_reload if they have
        # changed.
        #
        set files_to_reload [apm_get_changed_watched_files]

        #
        # If there are any changed watched files, stick another entry on
        # the reload queue.
        #
        if { [llength $files_to_reload] > 0 } {
            ns_log Notice "apm_load_any_changed_libraries: Reloading [join $files_to_reload {, }]"
            set new_level [nsv_incr apm_properties reload_level]
            nsv_set apm_reload $new_level $files_to_reload
        }

        set changed_reload_level_p 0

        # Keep track of which files we've reloaded in this loop so we never
        # reload the same one twice.
        while { $reload_level < [nsv_get apm_properties reload_level] } {
            incr reload_level
            set changed_reload_level_p 1
            # If there's no entry in apm_reload for that reload level, back out.
            if { ![nsv_exists apm_reload $reload_level] } {
                incr reload_level -1
                break
            }
            set reload_cmds [apm_package_reload_cmds [nsv_get apm_reload $reload_level]]
            foreach cmd $reload_cmds {
                if {$cmd ne ""} {
                    ns_log notice "### apm classic reload level $reload_level: cmd $cmd"
                    {*}$cmd
                }
            }
        }

        # We changed the reload level in this interpreter, so redefine the
        # apm_reload_level_in_this_interpreter proc.
        #
        if { $changed_reload_level_p } {
            proc apm_reload_level_in_this_interpreter {} "return $reload_level"
        }
    }
Generic XQL file:
packages/acs-tcl/tcl/apm-procs.xql

PostgreSQL XQL file:
packages/acs-tcl/tcl/apm-procs-postgresql.xql

Oracle XQL file:
packages/acs-tcl/tcl/apm-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: