本文整理汇总了Java中com.google.common.base.Supplier.get方法的典型用法代码示例。如果您正苦于以下问题:Java Supplier.get方法的具体用法?Java Supplier.get怎么用?Java Supplier.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Supplier
的用法示例。
在下文中一共展示了Supplier.get方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: getInstance
import com.google.common.base.Supplier; //导入方法依赖的package包/类
static <T extends Completable> T getInstance(Class<T> type, Supplier<T> supplier) {
ClassToInstanceMap<Completable> components = state().components;
@Nullable T instance = components.getInstance(type);
if (instance == null) {
instance = supplier.get();
components.putInstance(type, instance);
}
return instance;
}
示例3: CompactStriped
import com.google.common.base.Supplier; //导入方法依赖的package包/类
private CompactStriped(int stripes, Supplier<L> supplier) {
super(stripes);
Preconditions.checkArgument(stripes <= Ints.MAX_POWER_OF_TWO, "Stripes must be <= 2^30)");
this.array = new Object[mask + 1];
for (int i = 0; i < array.length; i++) {
array[i] = supplier.get();
}
}
示例4: assertChecksum
import com.google.common.base.Supplier; //导入方法依赖的package包/类
private static void assertChecksum(Supplier<Checksum> supplier, String input) {
byte[] bytes = HashTestUtils.ascii(input);
Checksum checksum = supplier.get();
checksum.update(bytes, 0, bytes.length);
long value = checksum.getValue();
String toString = "name";
HashFunction func = new ChecksumHashFunction(supplier, 32, toString);
assertEquals(toString, func.toString());
assertEquals(value, func.hashBytes(bytes).padToLong());
}
示例5: waitFor
import com.google.common.base.Supplier; //导入方法依赖的package包/类
/**
* Wait for <code>check</code> to return true for each
* <code>checkEveryMillis</code> ms. In the main loop, this method will log
* the message "waiting in main loop" for each <code>logInterval</code> times
* iteration to confirm the thread is alive.
* @param check user defined checker
* @param checkEveryMillis interval to call <code>check</code>
* @param logInterval interval to log for each
*/
public void waitFor(Supplier<Boolean> check, int checkEveryMillis,
int logInterval) throws InterruptedException {
Preconditions.checkNotNull(check, "check should not be null");
Preconditions.checkArgument(checkEveryMillis >= 0,
"checkEveryMillis should be positive value");
Preconditions.checkArgument(logInterval >= 0,
"logInterval should be positive value");
int loggingCounter = logInterval;
do {
if (LOG.isDebugEnabled()) {
LOG.debug("Check the condition for main loop.");
}
boolean result = check.get();
if (result) {
LOG.info("Exits the main loop.");
return;
}
if (--loggingCounter <= 0) {
LOG.info("Waiting in main loop.");
loggingCounter = logInterval;
}
Thread.sleep(checkEveryMillis);
} while (true);
}
示例6: registerType
import com.google.common.base.Supplier; //导入方法依赖的package包/类
public static void registerType(String type, Supplier<Identifier> constructor) {
if (constructor == null) throw new NullPointerException("constructor");
if (constructor.get() == null) throw new NullPointerException("constructor.get()");
registeredIdentifiers.put(type, constructor);
}
示例7: MapDbAppStorage
import com.google.common.base.Supplier; //导入方法依赖的package包/类
protected MapDbAppStorage(String fileSystemName, Supplier<DB> db) {
this.fileSystemName = Objects.requireNonNull(fileSystemName);
this.db = db.get();
rootNodeVar = this.db.atomicVar("rootNode", NodeInfoSerializer.INSTANCE)
.createOrOpen();
childNodesMap = this.db
.hashMap("childNodes", UuidSerializer.INSTANCE, UuidListSerializer.INSTANCE)
.createOrOpen();
childNodeMap = this.db
.hashMap("childNode", NamedLinkSerializer.INSTANCE, UuidSerializer.INSTANCE)
.createOrOpen();
parentNodeMap = this.db
.hashMap("parentNode", UuidSerializer.INSTANCE, UuidSerializer.INSTANCE)
.createOrOpen();
nodeInfoMap = this.db
.hashMap("nodeInfo", UuidSerializer.INSTANCE, NodeInfoSerializer.INSTANCE)
.createOrOpen();
dataMap = this.db
.hashMap("data", NamedLinkSerializer.INSTANCE, Serializer.BYTE_ARRAY)
.createOrOpen();
dataNamesMap = this.db
.hashMap("dataNames", UuidSerializer.INSTANCE, StringSetSerializer.INSTANCE)
.createOrOpen();
timeSeriesNamesMap = this.db
.hashMap("timeSeriesNamesMap", UuidSerializer.INSTANCE, StringSetSerializer.INSTANCE)
.createOrOpen();
timeSeriesMetadataMap = this.db
.hashMap("timeSeriesMetadataMap", NamedLinkSerializer.INSTANCE, TimeSeriesMetadataSerializer.INSTANCE)
.createOrOpen();
timeSeriesLastChunkMap = this.db
.hashMap("timeSeriesLastChunkMap", TimeSeriesKeySerializer.INSTANCE, Serializer.INTEGER)
.createOrOpen();
doubleTimeSeriesChunksMap = this.db
.hashMap("doubleTimeSeriesChunksMap", TimeSeriesChunkKeySerializer.INSTANCE, DoubleArrayChunkSerializer.INSTANCE)
.createOrOpen();
stringTimeSeriesChunksMap = this.db
.hashMap("stringTimeSeriesChunksMap", TimeSeriesChunkKeySerializer.INSTANCE, StringArrayChunkSerializer.INSTANCE)
.createOrOpen();
dependencyNodesMap = this.db
.hashMap("dependencyNodes", UuidSerializer.INSTANCE, NamedLinkListSerializer.INSTANCE)
.createOrOpen();
dependencyNodesByNameMap = this.db
.hashMap("dependencyNodesByName", NamedLinkSerializer.INSTANCE, UuidListSerializer.INSTANCE)
.createOrOpen();
backwardDependencyNodesMap = this.db
.hashMap("backwardDependencyNodes", UuidSerializer.INSTANCE, UuidListSerializer.INSTANCE)
.createOrOpen();
}
示例8: content
import com.google.common.base.Supplier; //导入方法依赖的package包/类
@GET
@Path("content")
public Response content(
@QueryParam("r") String repositoryName,
@QueryParam("g") String groupId,
@QueryParam("a") String artifactId,
@QueryParam("v") String version,
@QueryParam("c") String classifier,
@QueryParam("p") @DefaultValue("jar") String extension
) {
// default version
if ("LATEST".equals(version)) {
version = null;
}
version = Optional.ofNullable(version).orElse(latestVersion(
repositoryName, groupId, artifactId, classifier, extension
));
// valid params
if (isBlank(repositoryName) || isBlank(groupId) || isBlank(artifactId) || isBlank(version)) {
return NOT_FOUND;
}
Repository repository = repositoryManager.get(repositoryName);
if (null == repository || !repository.getFormat().getValue().equals("maven2")) {
return NOT_FOUND;
}
StorageFacet facet = repository.facet(StorageFacet.class);
Supplier<StorageTx> storageTxSupplier = facet.txSupplier();
log.debug("rundeck download repository: {}", repository);
final StorageTx tx = storageTxSupplier.get();
tx.begin();
Bucket bucket = tx.findBucket(repository);
log.debug("rundeck download bucket: {}", bucket);
if (null == bucket) {
return commitAndReturn(NOT_FOUND, tx);
}
String fileName = artifactId + "-" + version + (isBlank(classifier) ? "" : ("-" + classifier)) + "." + extension;
String path = groupId.replace(".", "/") +
"/" + artifactId +
"/" + version +
"/" + fileName;
Asset asset = tx.findAssetWithProperty("name", path, bucket);
log.debug("rundeck download asset: {}", asset);
if (null == asset) {
return commitAndReturn(NOT_FOUND, tx);
}
asset.markAsDownloaded();
tx.saveAsset(asset);
Blob blob = tx.requireBlob(asset.requireBlobRef());
Response.ResponseBuilder ok = Response.ok(blob.getInputStream());
ok.header("Content-Type", blob.getHeaders().get("BlobStore.content-type"));
ok.header("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
return commitAndReturn(ok.build(), tx);
}