###
### set_message_listener.jacl
###
###
###
###
###

proc set_message_listener {snames} {


###
### set up globals
###

global AdminConfig
global AdminControl
global AdminApp


set cells [$AdminConfig list Cell]

foreach cell $cells {
     set cname [$AdminConfig showAttribute $cell name]
     set nodes [$AdminConfig list Node $cell]

     puts " "
     puts "Cell: $cname         "

     foreach node $nodes {

        set nname [$AdminConfig showAttribute $node name]
        puts " "
        puts "Node: $nname            "


        foreach sname $snames {


            puts " "
            puts "Server: $sname"

            set serverid [$AdminConfig getid /Cell:$cname/Node:$nname/Server:$sname/]

            if {[llength $serverid] == 0} {
               puts "Serverid null - returning "
               continue 
            }

            ### 
            ### Identify the message listener service belonging to the server 
            ### 

            set mls [$AdminConfig list MessageListenerService $serverid]


            ### 
            ### Add listener ports.  
            ### 
            ### 
            ### Insert code from get_message_listener.sh below.
            ### 
            ### 

$AdminConfig create ListenerPort $mls {{destinationJNDIName prefix/jms/QueueB}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ErrorBizDocMessageEJBPort}{destinationJNDIName prefix/jms/QueueC}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ErrorMessageEJBPort}{destinationJNDIName prefix/jms/QueueD}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name JobExecMessageEJBPort}{destinationJNDIName prefix/jms/CashQueue}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name CashMessageEJBPort}{destinationJNDIName prefix/jms/QueueF}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ReceiveInvoiceMessageEJBPort}{destinationJNDIName prefix/jms/ReceiveNonCashDocumentQueue}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ReceiveNonCashDocumentMessageEJBPort}{destinationJNDIName prefix/jms/QueueH}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ReceivePaymentMessageEJBPort}{destinationJNDIName prefix/jms/ReceiveDocumentQueue}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ReceiveDocumentMessageEJBPort}{destinationJNDIName prefix/jms/ReceiveDocumentPurgeQueue}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ReceiveDocumentPurgeMessageEJBPort}{destinationJNDIName prefix/jms/QueueK}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ReceiveVendorMessageEJBPort}{destinationJNDIName prefix/jms/QueueL}{maxMessages 1}{maxRetries 0}{maxSessions 5}{name ReceiveVoidCheckMessageEJBPort}{destinationJNDIName prefix/jms/QueueA}{maxMessages 1}{maxRetries 0}{maxSessions 1}{name CollabJobExecMessageEJBPort}}


        }
    }
}

$AdminConfig save

}



###
### Main
###
### Test servers: nap_1_1 nap_2_1 
###


if { !($argc == 1) } {
   puts ""
   puts "Usage: , "
   puts " "
   puts "wsadmin.sh -username system -password password -f set_message_listener.jacl \"server1 server2 ...\""
} else { 
   set xservers      [lindex $argv 0]  
   set_message_listener $xservers 
}