InfoCenter Home > 6.6.0.2.2.3.3: Example use of wscp and TclThe wscp interface consists of wscp operations and built-in Tcl commands. Tcl provides a portable method of controlling and extending wscp administrative operations. You can use native Tcl commands for creating and executing new commands (the proc and eval commands), conditionalizing and controlling the flow of execution (if statements and loops), and handling errors and exceptions (the catch command). The Tcl foreach looping command iterates over all elements in a list. In the following example, the foreach command is used to iterate over all instances of ApplicationServer objects in a domain and then stop each server object. The square brackets ([ ]) invoke command substitution--the result of the ApplicationServer list operation (a list of server names) is used as the list argument to the foreach command. In turn, each ApplicationServer server name is substituted for the variable $ejbserver. wscp> foreach ejbserver [ApplicationServer list] \ {puts "stopping $ejbserver..."; ApplicationServer stop $ejbserver} As part of many server administration tasks, you often need to monitor the values of one or more server attributes. To do so, you can create and run a procedure that displays the attributes of interest. The following is an example procedure called showServerStatus, which displays the current state for each application server in a domain. As written, the showServerStatus procedure displays the Name and CurrentState attributes of all application servers. You can modify the procedure to display additional or different attributes. proc showServerStatus {} { puts "\nStatus of servers in the domain:\n" foreach ejbserver [ApplicationServer list] { set serverInfo($ejbserver) [ApplicationServer show $ejbserver -attribute \ {Name CurrentState}] puts $serverInfo($ejbserver) } } The following example demonstrates output of the showServerStatus procedure: wscp> showServerStatus Status of servers in the domain: {Name {Default Server}} {CurrentState {Initialization Failed}} {Name {Appl EJB Server}} {CurrentState Running} {Name {Model EJB Server}} {CurrentState Stopped} {Name {Model EJB Server2}} {CurrentState Stopped} {Name {Bean EJB Server}} {CurrentState Running} {Name {My Server}} {CurrentState Stopped} {Name {Test Server}} {CurrentState Stopped} The following procedure displays the attributes of a specified object instance, formatting them so that the attributes are displayed one per line, without enclosing braces. proc display {type name} { set attrs [$type show $name] foreach attr $attrs { puts $attr } } The following example demonstrates output from the display procedure. The procedure is used display the attributes of the DataSource object named testDataSource: wscp> display DataSource /JDBCDriver:OracleJDBC/DataSource:testDataSource/ Name testDataSource FullName /JDBCDriver:OracleJDBC/DataSource:testDataSource/ ConfigProperties {URL jdbc:oracle:thin:@wssol:1521:oraejs} ConnTimeout 300 DatabaseName WAS DisableAutoConnectionCleanup False IdleTimeout 1800 JNDIname testDataSource MaxPoolSize 30 MinPoolSize 3 OrphanTimeout 1800 StatementCacheSize 100 |
| ||
|