本文整理汇总了Java中com.google.common.base.Supplier类的典型用法代码示例。如果您正苦于以下问题:Java Supplier类的具体用法?Java Supplier怎么用?Java Supplier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Supplier类属于com.google.common.base包,在下文中一共展示了Supplier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForDNDeletions
import com.google.common.base.Supplier; //导入依赖的package包/类
/**
* Wait for the datanodes in the cluster to process any block
* deletions that have already been asynchronously queued.
*/
public static void waitForDNDeletions(final MiniDFSCluster cluster)
throws TimeoutException, InterruptedException {
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
public Boolean get() {
for (DataNode dn : cluster.getDataNodes()) {
if (DataNodeTestUtils.getPendingAsyncDeletions(dn) > 0) {
return false;
}
}
return true;
}
}, 1000, 10000);
}
示例2: waitForBlockReport
import com.google.common.base.Supplier; //导入依赖的package包/类
private void waitForBlockReport(
final DatanodeProtocolClientSideTranslatorPB mockNN1,
final DatanodeProtocolClientSideTranslatorPB mockNN2)
throws Exception {
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
public Boolean get() {
return get(mockNN1) || get(mockNN2);
}
private Boolean get(DatanodeProtocolClientSideTranslatorPB mockNN) {
try {
Mockito.verify(mockNN).blockReport(
Mockito.<DatanodeRegistration>anyObject(),
Mockito.eq(FAKE_BPID),
Mockito.<StorageBlockReport[]>anyObject(),
Mockito.<BlockReportContext>anyObject());
return true;
} catch (Throwable t) {
LOG.info("waiting on block report: " + t.getMessage());
return false;
}
}
}, 500, 10000);
}
示例3: initContributions
import com.google.common.base.Supplier; //导入依赖的package包/类
private Supplier<Map<String, WorkingSetManager>> initContributions() {
return memoize(() -> {
if (!isRunning()) {
return emptyMap();
}
final Builder<String, WorkingSetManager> builder = ImmutableMap.builder();
final IConfigurationElement[] elements = getExtensionRegistry()
.getConfigurationElementsFor(EXTENSION_POINT_ID);
for (final IConfigurationElement element : elements) {
try {
final WorkingSetManager manager = (WorkingSetManager) element
.createExecutableExtension(CLASS_ATTRIBUTE);
injector.injectMembers(manager);
builder.put(manager.getId(), manager);
} catch (final CoreException e) {
LOGGER.error("Error while trying to instantiate working set manager.", e);
}
}
return builder.build();
});
}
示例4: threadRenaming
import com.google.common.base.Supplier; //导入依赖的package包/类
/**
* Wraps the given callable such that for the duration of {@link Callable#call} the thread that is
* running will have the given name.
*
*
* @param callable The callable to wrap
* @param nameSupplier The supplier of thread names, {@link Supplier#get get} will be called once
* for each invocation of the wrapped callable.
*/
@GwtIncompatible // threads
static <T> Callable<T> threadRenaming(
final Callable<T> callable, final Supplier<String> nameSupplier) {
checkNotNull(nameSupplier);
checkNotNull(callable);
return new Callable<T>() {
@Override
public T call() throws Exception {
Thread currentThread = Thread.currentThread();
String oldName = currentThread.getName();
boolean restoreName = trySetName(nameSupplier.get(), currentThread);
try {
return callable.call();
} finally {
if (restoreName) {
boolean unused = trySetName(oldName, currentThread);
}
}
}
};
}
示例5: newGauge
import com.google.common.base.Supplier; //导入依赖的package包/类
/**
* Creates a new gauge metric.
*
* <p>Note that the order of the labels is significant.
*/
@Override
@CanIgnoreReturnValue
public <V> Metric<V> newGauge(
String name,
String description,
String valueDisplayName,
ImmutableSet<LabelDescriptor> labels,
Supplier<ImmutableMap<ImmutableList<String>, V>> metricCallback,
Class<V> valueClass) {
VirtualMetric<V> metric =
new VirtualMetric<>(
name, description, valueDisplayName, labels, metricCallback, valueClass);
registerMetric(name, metric);
logger.info("Registered new callback metric: " + name);
return metric;
}
示例6: saveAsset
import com.google.common.base.Supplier; //导入依赖的package包/类
/**
* Save an asset && create blob.
*
* @return blob content
*/
static Content saveAsset(final StorageTx tx,
final Asset asset,
final Supplier<InputStream> contentSupplier,
final String contentType,
@Nullable final AttributesMap contentAttributes) throws IOException
{
Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
AssetBlob assetBlob = tx.setBlob(
asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
);
asset.markAsDownloaded();
tx.saveAsset(asset);
return toContent(asset, assetBlob.getBlob());
}
示例7: testConfIsUnsetAsync
import com.google.common.base.Supplier; //导入依赖的package包/类
/**
* Ensure that {@link ReconfigurableBase#startReconfigurationTask} unsets the
* property in its parent's configuration when the new value is null.
* @throws IOException
*/
@Test (timeout=300000)
public void testConfIsUnsetAsync() throws ReconfigurationException,
IOException, TimeoutException, InterruptedException {
final String property = "FOO";
final String value1 = "value1";
final Configuration conf = new Configuration();
conf.set(property, value1);
final Configuration newConf = new Configuration();
final ReconfigurableBase reconfigurable = makeReconfigurable(
conf, newConf, Arrays.asList(property));
// Kick off a reconfiguration task and wait until it completes.
reconfigurable.startReconfigurationTask();
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
public Boolean get() {
return reconfigurable.getReconfigurationTaskStatus().stopped();
}
}, 100, 60000);
assertNull(reconfigurable.getConf().get(property));
}
示例8: getTarget
import com.google.common.base.Supplier; //导入依赖的package包/类
@Override
public FieldAccessTarget getTarget() {
Supplier<Optional<JavaField>> fieldSupplier = new Supplier<Optional<JavaField>>() {
@Override
public Optional<JavaField> get() {
return uniqueTargetIn(tryFindMatchingTargets(targetOwner.getAllFields(), record.target));
}
};
JavaClass fieldType = classes.getOrResolve(Type.getType(record.target.desc).getClassName());
return new FieldAccessTargetBuilder()
.withOwner(targetOwner)
.withName(record.target.name)
.withType(fieldType)
.withField(fieldSupplier)
.build();
}
示例9: waitForBlockReceived
import com.google.common.base.Supplier; //导入依赖的package包/类
private ReceivedDeletedBlockInfo[] waitForBlockReceived(
final ExtendedBlock fakeBlock,
final DatanodeProtocolClientSideTranslatorPB mockNN) throws Exception {
final String fakeBlockPoolId = fakeBlock.getBlockPoolId();
final ArgumentCaptor<StorageReceivedDeletedBlocks[]> captor =
ArgumentCaptor.forClass(StorageReceivedDeletedBlocks[].class);
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
public Boolean get() {
try {
Mockito.verify(mockNN).blockReceivedAndDeleted(
Mockito.<DatanodeRegistration>anyObject(),
Mockito.eq(fakeBlockPoolId),
captor.capture());
return true;
} catch (Throwable t) {
return false;
}
}
}, 100, 10000);
return captor.getValue()[0].getBlocks();
}
示例10: toTable
import com.google.common.base.Supplier; //导入依赖的package包/类
/**
* Returns a {@link Collector} that accumulates elements into a {@code Table} created using the
* specified supplier, whose cells are generated by applying the provided mapping functions to the
* input elements. Cells are inserted into the generated {@code Table} in encounter order.
*
* <p>If multiple input elements map to the same row and column, an {@code IllegalStateException}
* is thrown when the collection operation is performed.
*
* @since 21.0
*/
@Beta
public static <T, R, C, V, I extends Table<R, C, V>> Collector<T, ?, I> toTable(
java.util.function.Function<? super T, ? extends R> rowFunction,
java.util.function.Function<? super T, ? extends C> columnFunction,
java.util.function.Function<? super T, ? extends V> valueFunction,
java.util.function.Supplier<I> tableSupplier) {
return toTable(
rowFunction,
columnFunction,
valueFunction,
(v1, v2) -> {
throw new IllegalStateException("Conflicting values " + v1 + " and " + v2);
},
tableSupplier);
}
示例11: renamingDecorator
import com.google.common.base.Supplier; //导入依赖的package包/类
/**
* Creates an {@link Executor} that renames the {@link Thread threads} that its tasks run in.
*
* <p>The names are retrieved from the {@code nameSupplier} on the thread that is being renamed
* right before each task is run. The renaming is best effort, if a {@link SecurityManager}
* prevents the renaming then it will be skipped but the tasks will still execute.
*
*
* @param executor The executor to decorate
* @param nameSupplier The source of names for each task
*/
@GwtIncompatible // concurrency
static Executor renamingDecorator(final Executor executor, final Supplier<String> nameSupplier) {
checkNotNull(executor);
checkNotNull(nameSupplier);
if (isAppEngine()) {
// AppEngine doesn't support thread renaming, so don't even try
return executor;
}
return new Executor() {
@Override
public void execute(Runnable command) {
executor.execute(Callables.threadRenaming(command, nameSupplier));
}
};
}
示例12: waitFor
import com.google.common.base.Supplier; //导入依赖的package包/类
public static void waitFor(Supplier<Boolean> check,
int checkEveryMillis, int waitForMillis)
throws TimeoutException, InterruptedException
{
long st = Time.now();
do {
boolean result = check.get();
if (result) {
return;
}
Thread.sleep(checkEveryMillis);
} while (Time.now() - st < waitForMillis);
throw new TimeoutException("Timed out waiting for condition. " +
"Thread diagnostics:\n" +
TimedOutTestsListener.buildThreadDiagnosticString());
}
示例13: create
import com.google.common.base.Supplier; //导入依赖的package包/类
@Override protected Table<String, Integer, Character> create(
Object... data) {
Supplier<TreeMap<Integer, Character>> factory
= new Supplier<TreeMap<Integer, Character>>() {
@Override
public TreeMap<Integer, Character> get() {
return Maps.newTreeMap();
}
};
Map<String, Map<Integer, Character>> backingMap
= Maps.newLinkedHashMap();
Table<String, Integer, Character> table
= Tables.newCustomTable(backingMap, factory);
populate(table, data);
return table;
}
示例14: testRenaming_exceptionalReturn
import com.google.common.base.Supplier; //导入依赖的package包/类
@GwtIncompatible // threads
public void testRenaming_exceptionalReturn() throws Exception {
String oldName = Thread.currentThread().getName();
final Supplier<String> newName = Suppliers.ofInstance("MyCrazyThreadName");
class MyException extends Exception {}
Callable<Void> callable = new Callable<Void>() {
@Override public Void call() throws Exception {
assertEquals(Thread.currentThread().getName(), newName.get());
throw new MyException();
}
};
try {
Callables.threadRenaming(callable, newName).call();
fail();
} catch (MyException expected) {}
assertEquals(oldName, Thread.currentThread().getName());
}
示例15: VacuumToolApplication
import com.google.common.base.Supplier; //导入依赖的package包/类
@Autowired
VacuumToolApplication(
@Value("#{replicaHiveConf}") HiveConf conf,
@Value("#{replicaMetaStoreClientSupplier}") Supplier<CloseableMetaStoreClient> clientSupplier,
LegacyReplicaPathRepository legacyReplicaPathRepository,
HousekeepingService housekeepingService,
TableReplications replications,
@Value("${dry-run:false}") boolean isDryRun,
@Value("${partition-batch-size:1000}") short batchSize,
@Value("${expected-path-count:10000}") int expectedPathCount) {
this.conf = conf;
this.clientSupplier = clientSupplier;
this.legacyReplicaPathRepository = legacyReplicaPathRepository;
this.housekeepingService = housekeepingService;
this.isDryRun = isDryRun;
this.batchSize = batchSize;
this.expectedPathCount = expectedPathCount;
tableReplications = replications.getTableReplications();
vacuumEventId = "vacuum-" + DateTime.now(DateTimeZone.UTC);
}