The 'project' Object |
Active Web |
This object is created by the Active Web servlet and is persistent for the lifetime of the servlet. This means that the object will remain after a script has finished and can be used by another script. If the script servlet is stopped and restarted then the project object is recreated.
Each project will have its own ‘project’ object, where a project is defined as a directory under the web application’s root directory.
The project object can have other properties added to it and these properties will then remain for the lifetime of the script server. Any property held by the project object can be set to expire after a specified time by using the Expire function.
Shown below is the project object prototype chain.
The project object is of class Project.
The project object can have any number of properties in addition to the ones shown below. All the predefined properties do not enumerate and are read only (they can not be changed or deleted).
Property |
Description |
name |
A string primitive giving the name of the project (e.g. "Testing"). |
path |
A string primitive giving the directory path of the project directory from the root of the filing system. This will include the project directory (e.g. " C:\Program Files\Northgate\Active Web 4.0\webapps\myWebApp\Testing"). |
prototype |
A reference to the String Prototype. This property does not enumerate and cannot be deleted, but it can be changed. |
Function |
Description |
expire(name, timeout) |
Set the lifetime of a property in the project object. When the property expires it will be removed from the project object. The name argument is the full reference name of a property that exists in the project object (e.g. project.myData.myProperty). The timeout argument is the property lifetime in minutes. |
reload() |
Reloads the project object with the properties from the project properties file (see above). This will not affect any other properties in the project object. |
Example
project.myData = "a string of info";
project.expire(project.myData, 10);
This example will expire the myData object in 10 minutes. If the following code is included in a script it will detect when the object expires and print a message.
if (project.myData == null) {
writeln(“myData has expired");
}
This prototype provides a locking mechanism for objects. The lock is applied to the this object using this prototype and lasts as long as the object is in the server. This prototype can be used by any object.
The lock is a synchronisation mechanism that allows the programmer to prevent more than one script from performing an action at any one time. The lock does not prevent access to the locked object, it is a signal between co-operating scripts that one of them has the lock.
Example
project.lock();
project.myCount++;
project.unlock();
This example will increment the count ‘myCount’ in the project object and protect it from mis-counting through having more than one script incrementing at the same time. If another script tries to run the same code it will block until the unlock is called. This does not prevent any other script from changing the project.myCount property.
A script locks is freed either by a script calling unlock (it does not have to be the same script that called lock; any script can unlock) or when the locking script completes its processing.
Property |
Description |
length |
The number of characters in the string. This property does not enumerate and cannot be changed or deleted. |
prototype |
A reference to the Object Prototype. This property does not enumerate and cannot be deleted but can be changed. |
Function |
Description |
lock() |
This function is used to synchronise multiple script processing. When this function is called the script will block if another script has called lock until that script calls unlock. |
unlock() |
This function is used to release the lock on the this object. If other scripts are waiting in the lock function then one of then will be released. There is no queuing order or guaranteed order of release for scripts waiting on an unlock. |
Topic ID: 150103