$count = $session->countLeafInstances( $class )

The countLeafInstances() function counts the number of leaf objects that exist for a specified class, those that would be returned by a call to getLeafInstances().

 $n = $session->countLeafInstances( "Router" );