Here are the examples of the java api class org.apache.accumulo.core.client.impl.TabletLocator taken from open source projects.
1. AccumuloMRUtils#getTabletLocator()
Project: geowave
File: AccumuloMRUtils.java
File: AccumuloMRUtils.java
/** * Initializes an Accumulo {@link TabletLocator} based on the configuration. * * @param instance * the accumulo instance * @param tableName * the accumulo table name * @return an Accumulo tablet locator * @throws TableNotFoundException * if the table name set on the configuration doesn't exist * */ protected static TabletLocator getTabletLocator(final Object clientContextOrInstance, final String tableId) throws TableNotFoundException { TabletLocator tabletLocator = null; // @formatter:off /*if[accumulo.api=1.6] tabletLocator = TabletLocator.getLocator( (Instance) clientContextOrInstance, new Text( tableId)); else[accumulo.api=1.6]*/ tabletLocator = TabletLocator.getLocator((ClientContext) clientContextOrInstance, new Text(tableId)); // @formatter:on return tabletLocator; }
2. AccumuloMRUtils#populateIntermediateSplits()
Project: geowave
File: AccumuloMRUtils.java
File: AccumuloMRUtils.java
private static TreeSet<IntermediateSplitInfo> populateIntermediateSplits(final TreeSet<IntermediateSplitInfo> splits, final AccumuloOperations operations, final PrimaryIndex index, final List<DataAdapter<Object>> adapters, final Map<PrimaryIndex, RowRangeHistogramStatistics<?>> statsCache, final AdapterStore adapterStore, final DataStatisticsStore statsStore, final Integer maxSplits, final DistributableQuery query, final String[] authorizations) throws IOException { if ((query != null) && !query.isSupported(index)) { return splits; } Range fullrange; try { fullrange = getRangeMax(index, adapterStore, statsStore, authorizations); } catch (final Exception e) { fullrange = new Range(); LOGGER.warn("Cannot ascertain the full range of the data", e); } final String tableName = AccumuloUtils.getQualifiedTableName(operations.getGeoWaveNamespace(), index.getId().getString()); final NumericIndexStrategy indexStrategy = index.getIndexStrategy(); final TreeSet<Range> ranges; if (query != null) { final List<MultiDimensionalNumericData> indexConstraints = query.getIndexConstraints(indexStrategy); if ((maxSplits != null) && (maxSplits > 0)) { ranges = AccumuloUtils.byteArrayRangesToAccumuloRanges(DataStoreUtils.constraintsToByteArrayRanges(indexConstraints, indexStrategy, maxSplits)); } else { ranges = AccumuloUtils.byteArrayRangesToAccumuloRanges(DataStoreUtils.constraintsToByteArrayRanges(indexConstraints, indexStrategy, -1)); } if (ranges.size() == 1) { final Range range = ranges.first(); if (range.isInfiniteStartKey() || range.isInfiniteStopKey()) { ranges.remove(range); ranges.add(fullrange.clip(range)); } } } else { ranges = new TreeSet<Range>(); ranges.add(fullrange); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Protected range: " + fullrange); } } // get the metadata information for these ranges final Map<String, Map<KeyExtent, List<Range>>> tserverBinnedRanges = new HashMap<String, Map<KeyExtent, List<Range>>>(); TabletLocator tl; try { final Instance instance = operations.getInstance(); final String tableId = Tables.getTableId(instance, tableName); Credentials credentials = new Credentials(operations.getUsername(), new PasswordToken(operations.getPassword())); // @formatter:off /*if[accumulo.api=1.6] tl = getTabletLocator( instance, tableId); Object clientContextOrCredentials = credentials; else[accumulo.api=1.6]*/ ClientContext clientContext = new ClientContext(instance, credentials, new ClientConfiguration()); tl = getTabletLocator(clientContext, tableId); Object clientContextOrCredentials = clientContext; /*end[accumulo.api=1.6]*/ // @formatter:on // its possible that the cache could contain complete, but // old information about a tables tablets... so clear it tl.invalidateCache(); final List<Range> rangeList = new ArrayList<Range>(ranges); final Random r = new Random(); while (!binRanges(rangeList, clientContextOrCredentials, tserverBinnedRanges, tl)) { if (!(instance instanceof MockInstance)) { if (!Tables.exists(instance, tableId)) { throw new TableDeletedException(tableId); } if (Tables.getTableState(instance, tableId) == TableState.OFFLINE) { throw new TableOfflineException(instance, tableId); } } tserverBinnedRanges.clear(); LOGGER.warn("Unable to locate bins for specified ranges. Retrying."); UtilWaitThread.sleep(100 + r.nextInt(101)); // sleep randomly between 100 and 200 ms tl.invalidateCache(); } } catch (final Exception e) { throw new IOException(e); } final HashMap<String, String> hostNameCache = new HashMap<String, String>(); for (final Entry<String, Map<KeyExtent, List<Range>>> tserverBin : tserverBinnedRanges.entrySet()) { final String tabletServer = tserverBin.getKey(); final String ipAddress = tabletServer.split(":", 2)[0]; String location = hostNameCache.get(ipAddress); if (location == null) { final InetAddress inetAddress = InetAddress.getByName(ipAddress); location = inetAddress.getHostName(); hostNameCache.put(ipAddress, location); } for (final Entry<KeyExtent, List<Range>> extentRanges : tserverBin.getValue().entrySet()) { final Range keyExtent = extentRanges.getKey().toDataRange(); final Map<PrimaryIndex, List<RangeLocationPair>> splitInfo = new HashMap<PrimaryIndex, List<RangeLocationPair>>(); final List<RangeLocationPair> rangeList = new ArrayList<RangeLocationPair>(); for (final Range range : extentRanges.getValue()) { final Range clippedRange = keyExtent.clip(range); final double cardinality = getCardinality(getHistStats(index, adapters, adapterStore, statsStore, statsCache, authorizations), clippedRange); if (!(fullrange.beforeStartKey(clippedRange.getEndKey()) || fullrange.afterEndKey(clippedRange.getStartKey()))) { rangeList.add(new RangeLocationPair(clippedRange, location, cardinality < 1 ? 1.0 : cardinality)); } else { LOGGER.info("Query split outside of range"); } if (LOGGER.isTraceEnabled()) { LOGGER.warn("Clipped range: " + rangeList.get(rangeList.size() - 1).getRange()); } } if (!rangeList.isEmpty()) { splitInfo.put(index, rangeList); splits.add(new IntermediateSplitInfo(splitInfo)); } } } return splits; }