function void ListAllAgentIds()
Object osAgents
Object osNext
String path
List children
List descendants
Integer i
List usedIds = {}
//get root "Agents" node by looping through the children
//of AgentController's parent and finding the "Agents" ospace
//(probably a better way do do this)
children = OS.Children( $llagent.AgentController.OSParent )
for i = 1 to Length(children)
osNext = children[ i ]
if (osNext.OSName == "Agents")
osAgents = osNext
children = Undefined
break
end
end
//build list of all agents with valid agent id.
//might as well echo the id and full path to the agent
//while i am at it.
descendants = $kernel.OSpaceUtils.GetDescendants(osAgents)
for i = 1 to Length(descendants)
osNext = descendants[ i ]
if ((IsDefined(osNext.fAgentId)) && (osNext.fAgentId != 0))
usedIds = {@usedIds, osNext.fAgentId}
echo(osNext.fAgentId, " ", GetAgentPath(osNext))
end
end
descendants = Undefined
//sort used agent ids
usedIds = List.Sort(usedIds)
//print out used ids
for i = 1 to Length(usedIds)
echo(usedIds[ i ])
end
end
function String GetAgentPath(Object osAgent)
Object osNext
String path
Boolean done
osNext = osAgent
done = false
while(!done)
done = (osNext.OSName == "Agents")
if (Length(path) > 0)
path = Str.Format("%1:%2", osNext.OSName, path)
else
path = osNext.OSName
end
osNext = osNext.OSParent
end
return path
end
Comments