當前位置: 首頁>>代碼示例>>Java>>正文


Java Supplier類代碼示例

本文整理匯總了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);
  
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:HATestUtil.java

示例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);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:TestBPOfferService.java

示例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();
		});
	}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:26,代碼來源:WorkingSetManagerBrokerImpl.java

示例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);
        }
      }
    }
  };
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:31,代碼來源:Callables.java

示例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;
}
 
開發者ID:google,項目名稱:java-monitoring-client-library,代碼行數:23,代碼來源:MetricRegistryImpl.java

示例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());
}
 
開發者ID:sonatype-nexus-community,項目名稱:nexus-repository-r,代碼行數:21,代碼來源:RFacetUtils.java

示例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));
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:29,代碼來源:TestReconfiguration.java

示例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();
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:17,代碼來源:AccessRecord.java

示例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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:TestBPOfferService.java

示例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);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:26,代碼來源:Tables.java

示例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));
    }
  };
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:27,代碼來源:MoreExecutors.java

示例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());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:GenericTestUtils.java

示例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;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:17,代碼來源:NewCustomTableTest.java

示例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());
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:CallablesTest.java

示例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);
}
 
開發者ID:HotelsDotCom,項目名稱:circus-train,代碼行數:21,代碼來源:VacuumToolApplication.java


注:本文中的com.google.common.base.Supplier類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。