To provide a concrete introduction to the features and benefits of NetPebbles, we discuss here a simple example and describe how it executes. Ms. Sys Admin is a system administrator for a group of about a hundred PC users. The group uses Lotus Notes as the primary tool for communication. She is interested in tracking what versions of the Notes client is running on every PC to make sure they don't diverge too much. She attempted to do this by periodic e-mail. She quickly realized that some people did not reply to e-mail, some people did but were annoyed, some people provided wrong information, and some did not even know how to find the information. Ms. Sys Admin could use a small NetPebbles script that visits every workstation, downloads her own NotesSniffer component that simply records the Notes Client version, and returns to her workstation with the collected information. Figure 1 shows the corresponding script for the application.
Figure: A NetPebbles script and associated interfaces
used for the system administration example.
The application uses three components that implement the IDomainAdmin, IMachineAdmin and IReportGeneration interfaces, respectively. Methods for each interface are shown in Figure 1. The IDomainAdmin interface manages a group of machines in a domain. It allows one to create new domains, add and remove machines from a domain, and get a list of all machines in a domain. The IMachineAdmin interface is used to administer software on a machine. The interface allows one to add and remove software, get a list of all installed software, get the version for a software, and notify the users by writing to the console. The IReportGeneration interface is used to generate a report in a tabular form.
Variables are initialized in lines 1-3. In line 4, the createComponent function is called. The function's arguments are an interface that a component must implement, and a filter for component attributes. It searches the catalog of advertised components and locates a component that supports the IDomainName interface and manages the domain named ``dept231''. If the component properties allow the component to be downloaded then the runtime may download the component. Otherwise, the runtime moves the script to the site where the component is located. In either case, the createComponent() call returns an instance of the component. After the instance has been created, the script invokes the getAllMachines() method of the component to get a list containing all machines (IP addresses) in the domain for dept231. Note that the syntax of method invocation requires the complete signature of the method. This is because the language is typeless. For object-oriented languages like Java that allow method overloading, without a complete signature, it is impossible to determine which method to invoke. Line 8 declares another array to store the version numbers. The length function returns the number of elements in the data referred to by the variable.
Lines 10-18 contain a for loop that iterates through the set of machines. In line 11, the createComponent function creates an instance of a component that supports the IMachineAdmin interface. Note that the at keyword in the statement indicates to the runtime that the component should be created at a specific site. If the runtime is unable to create a component at that site then it is noted and script continues to execute. Line 16 defines a group and adds the instance to that group. A group is a language object that supports an unordered collection of identical objects. Operations such as add, and remove are supported on a group. A group allows the same method to be invoked on all the objects of the group using a single statement. In line 17, the getVersion() method returns the version number for ``Lotus Notes''. In line 19, the consoleWrite() method is called on all members of the group to notify client users about the activity. In lines 22-24, a report generation component is created at the system administrator's home machine to display the results.