/**
   * Create a GridMaster node.
   *
   * @param nodeID the GridNodeID for the GridMaster.
   * @param desc The GridNode Name for the GridMaster.
   */
  private void createGridMasterNode(String nodeID, String desc) throws Throwable {
    // create
    GridNode gmNode = new GridNode();
    gmNode.setID(nodeID);
    gmNode.setName(desc);
    gmNode.setState(GridNode.STATE_GM);
    gmNode.setCategory(DelegateHelper.getProperties().getGmCategory());

    Long uid = ServiceLookupHelper.getGridNodeManager().createGridNode(gmNode);

    // add uid to gms
    _ctx.getConnectionSetupResult().getAvailableGridMastersUIDs().add(uid);
  }
  /** Remove the existing setup: GridMaster nodes, Channels, and JmsRouters. */
  private void clearExistingSetup() throws Throwable {
    // retrieve GridMaster nodes
    Collection gmNodes = getGridMasterNodes();

    IGridNodeManagerObj mgr = ServiceLookupHelper.getGridNodeManager();
    for (Iterator i = gmNodes.iterator(); i.hasNext(); ) {
      GridNode node = (GridNode) i.next();

      // delete GridMaster channel for each GridMaster node
      deleteChannel(node.getID());
      // delete each GridMaster node
      mgr.deleteGridNode((Long) node.getKey());
    }

    // delete existing JmsRouters
    deleteJmsRouters();

    // delete master channel
    // deleteChannel(_ctx.getGridNodeID().toString());

    _ctx.getConnectionSetupResult().getGridMasterTopics().clear();
    _ctx.getConnectionSetupResult().getAvailableGridMastersUIDs().clear();
    _ctx.getConnectionSetupResult().getAvailableRouterUIDs().clear();
  }