use of org.netxms.client.objects.AbstractObject in project netxms by netxms.
the class NXCSession method getTopLevelObjects.
/**
* Get list of top-level objects matching given class filter. Class filter
* may be null to ignore object class.
*
* @param classFilter To filter the classes
* @return List of all top matching level objects (either without parents or with
* inaccessible parents)
*/
public AbstractObject[] getTopLevelObjects(Set<Integer> classFilter) {
HashSet<AbstractObject> list = new HashSet<AbstractObject>();
synchronized (objectList) {
for (AbstractObject object : objectList.values()) {
if ((classFilter != null) && !classFilter.contains(object.getObjectClass()))
continue;
if (!object.hasParents()) {
list.add(object);
} else {
boolean hasParents = false;
Iterator<Long> it = object.getParents();
while (it.hasNext()) {
Long parent = it.next();
if (classFilter != null) {
AbstractObject p = objectList.get(parent);
if ((p != null) && classFilter.contains(p.getObjectClass())) {
hasParents = true;
break;
}
} else {
if (objectList.containsKey(parent)) {
hasParents = true;
break;
}
}
}
if (!hasParents)
list.add(object);
}
}
}
return list.toArray(new AbstractObject[list.size()]);
}
use of org.netxms.client.objects.AbstractObject in project netxms by netxms.
the class NXCSession method removeOrphanedObjects.
/**
* Remove orphaned objects (with last parent left)
*
* @param parent
*/
private void removeOrphanedObjects(AbstractObject parent) {
Iterator<Long> it = parent.getChildren();
while (it.hasNext()) {
AbstractObject object = objectList.get(it.next());
if ((object != null) && (object.getParentCount() == 1)) {
objectList.remove(object.getObjectId());
objectListGUID.remove(object.getGuid());
if (object instanceof Zone)
zoneList.remove(((Zone) object).getUIN());
removeOrphanedObjects(object);
}
}
}
use of org.netxms.client.objects.AbstractObject in project netxms by netxms.
the class NXCSession method handover.
/**
* Handover object cache to new session. After call to this method,
* object cache of this session invalidated and should not be used.
*
* @param target target session object
*/
public void handover(NXCSession target) {
target.objectList = objectList;
target.objectListGUID = objectListGUID;
target.zoneList = zoneList;
for (AbstractObject o : objectList.values()) {
o.setSession(target);
}
objectList = null;
objectListGUID = null;
zoneList = null;
}
use of org.netxms.client.objects.AbstractObject in project netxms by netxms.
the class ObjectTest method testObjectIsParent.
public void testObjectIsParent() throws Exception {
final NXCSession session = connect();
session.syncObjects();
AbstractObject object = session.findObjectById(2);
assertFalse(object.isChildOf(1));
object = session.findObjectById(TestConstants.NODE_ID);
assertTrue(object.isChildOf(1));
session.disconnect();
}
use of org.netxms.client.objects.AbstractObject in project netxms by netxms.
the class ObjectTest method testObjectTree.
public void testObjectTree() throws Exception {
final NXCSession session = connect();
session.syncObjects();
AbstractObject object = session.findObjectById(1, EntireNetwork.class);
assertNotNull(object);
assertEquals(1, object.getObjectId());
printObject(object, 0);
session.disconnect();
}
Aggregations