com.ace.moab.api.vm
Class VMCollection

java.lang.Object
  extended by com.ace.moab.api.vm.VMCollection
All Implemented Interfaces:
java.lang.Iterable<VM>

public class VMCollection
extends java.lang.Object
implements java.lang.Iterable<VM>

This class represents a collection of VMs found in Moab. This groups multiple VMs into one object to allow group wide operations to be done on VMs such as adding and deleting and searching for VMs.

Author:
Brady Kimball

Constructor Summary
VMCollection()
          Initializes an empty collection of VMs.
VMCollection(java.util.Collection<VM> vmCollection)
          Initialize the collection of VMs based on the collection of VMs given.
 
Method Summary
 void addVM(VM vm)
          Adds a VM to the collection.
 VM findVM(java.lang.String vmID)
          Attempts to find a VM with the respective VM ID.
 java.util.List<java.lang.String> getFilteredNodeNames()
          Given the collection of VMs, this will returned the filtered node names.
 VM getIndex(int index)
           Returns the VM at the associated node index.
 VM getProcIndex(int procIndex)
          Gets the VM at the associated processor index.
 boolean isEmpty()
          Returns true if no VMs are in the collection.
 java.util.Iterator<VM> iterator()
          
 void removeVM(java.lang.String vmID)
          Attempts to remove a VM from the collection.
 void removeVM(VM vm)
          Attempts to remove a VM from the collection.
 int size()
          Returns the number of VMs in the collection.
 java.util.List<VM> toList()
          Converts the collection of VMs into a list of VM objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VMCollection

public VMCollection()
Initializes an empty collection of VMs.


VMCollection

public VMCollection(java.util.Collection<VM> vmCollection)
Initialize the collection of VMs based on the collection of VMs given. If the VMs passed in is null, an empty collection is initialized.

Parameters:
vmCollection - the VMs to store in the collection.
Method Detail

addVM

public void addVM(VM vm)
Adds a VM to the collection. If the VM already exists, then the add call is simply ignored.

Parameters:
vm - the VM to be added.

findVM

public VM findVM(java.lang.String vmID)
Attempts to find a VM with the respective VM ID. If the VM ID is null, null is returned. Similarly, if the VM cannot be found, null is returned.

Parameters:
vmID - the ID of the VM to search for.
Returns:
the respective VM object that matches the VM ID.

getIndex

public VM getIndex(int index)

Returns the VM at the associated node index. The node index starts at 1.

If no VM resides at the index, null is returned.

Parameters:
index - the node index of the VM to return.
Returns:
an associated VM at the specified node index; null, if no VM resides at the index.

removeVM

public void removeVM(VM vm)
Attempts to remove a VM from the collection. If the VM cannot be found, the removal request is simply ignored.

Parameters:
vm - the VM to be removed.

removeVM

public void removeVM(java.lang.String vmID)
Attempts to remove a VM from the collection. If the VM with the respective ID cannot be found, the removal request is simply ignored.

Parameters:
vmID - the ID of the VM to be removed.

toList

public java.util.List<VM> toList()
Converts the collection of VMs into a list of VM objects.

Returns:
a list of VMs in the collection.

iterator

public java.util.Iterator<VM> iterator()

Specified by:
iterator in interface java.lang.Iterable<VM>

isEmpty

public boolean isEmpty()
Returns true if no VMs are in the collection.

Returns:
if true, no VMs are in the collection.

size

public int size()
Returns the number of VMs in the collection.

Returns:
the number of VMs in the collection.

getFilteredNodeNames

public java.util.List<java.lang.String> getFilteredNodeNames()
Given the collection of VMs, this will returned the filtered node names. If all VMs reside on the same node, that node will be filtered out of the list.

Returns:
the node names filtered.

getProcIndex

public VM getProcIndex(int procIndex)
Gets the VM at the associated processor index. Any given VM can have any number of processors assigned to it. This method is useful for finding the VM associated with the nth processor.

The procIndex starts at 1.

For example, if this VM collection contains 3 VMs in this order:

If the caller wants the VM associated with the 5th processor (procIndex = 5), VM B would be returned. If the caller wants the VM associated with the 2nd processor (procIndex = 2) VM A would be returned.

Parameters:
procIndex - The processor index
Returns:
The VM at the associated processor index.


Copyright © 2001-2009 Cluster Resources, Inc. All Rights Reserved.