本文整理汇总了Java中javaslang.control.Try.CheckedSupplier方法的典型用法代码示例。如果您正苦于以下问题:Java Try.CheckedSupplier方法的具体用法?Java Try.CheckedSupplier怎么用?Java Try.CheckedSupplier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javaslang.control.Try
的用法示例。
在下文中一共展示了Try.CheckedSupplier方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: map
import javaslang.control.Try; //导入方法依赖的package包/类
@Override
public <N extends Number, T> N map(
final Try.CheckedSupplier<T> supplier,
final Function<T, N> func,
final N defaultValue) {
return Try.of(supplier).map(func).getOrElse(defaultValue);
}
示例2: NetworkInterfaces
import javaslang.control.Try; //导入方法依赖的package包/类
NetworkInterfaces(
final UnitConversionService units,
final CachingService caching,
final Sigar sigar,
final AnnotationMBeanExporter server) throws SigarException, JMException {
super();
for(final String iface : ImmutableSet.copyOf(sigar.getNetInterfaceList())) {
final NetInterfaceConfig config = sigar.getNetInterfaceConfig(iface);
final Try.CheckedSupplier<NetInterfaceStat> stats = caching
.cache(() -> sigar.getNetInterfaceStat(iface));
final String name = config.getName();
final NetworkInterfaceMetrics info = SigarNetworkInterfaceMetrics
.builder()
.name(name)
.stats(stats)
.units(units)
.build();
server.registerManagedResource(info, new ObjectName(format(OBJECT_NAME, ObjectName.quote(name))));
}
}
示例3: FileSystems
import javaslang.control.Try; //导入方法依赖的package包/类
FileSystems(
final UnitConversionService units,
final CachingService caching,
final Sigar sigar,
final AnnotationMBeanExporter server) throws SigarException, JMException {
final Set<String> seenFs = new HashSet<>();
for(final FileSystem fs : sigar.getFileSystemList()) {
final String devName = fs.getDevName();
if(seenFs.contains(devName)) {
continue;
}
seenFs.add(devName);
final Try.CheckedSupplier<FileSystemUsage> supplier = caching
.cache(() -> sigar.getFileSystemUsage(fs.getDirName()));
final SigarFileSystemMetrics filesystem = SigarFileSystemMetrics
.builder()
.units(units)
.usage(supplier)
.devName(devName)
.dirName(fs.getDirName())
.options(fs.getOptions())
.sysTypeName(fs.getSysTypeName())
.build();
final FilesystemType type = FilesystemType.values()[fs.getType()];
final ObjectName objectName = new ObjectName(format(OBJECT_NAME, type, ObjectName.quote(devName)));
server.registerManagedResource(filesystem, objectName);
}
}
示例4: map
import javaslang.control.Try; //导入方法依赖的package包/类
<N extends Number, T> N map(
Try.CheckedSupplier<T> supplier,
Function<T, N> func,
final N defaultValue);
示例5: memory
import javaslang.control.Try; //导入方法依赖的package包/类
@Bean
Try.CheckedSupplier<Mem> memory(
final Sigar sigar,
final CachingService caching) {
return caching.cache(sigar::getMem);
}
示例6: cpu
import javaslang.control.Try; //导入方法依赖的package包/类
@Bean
Try.CheckedSupplier<Cpu> cpu(
final Sigar sigar,
final CachingService caching) {
return caching.cache(sigar::getCpu);
}
示例7: cpuPerc
import javaslang.control.Try; //导入方法依赖的package包/类
@Bean
Try.CheckedSupplier<CpuPerc> cpuPerc(
final Sigar sigar,
final CachingService caching) {
return caching.cache(sigar::getCpuPerc);
}
示例8: cpuInfo
import javaslang.control.Try; //导入方法依赖的package包/类
@Bean
Try.CheckedSupplier<CpuInfo[]> cpuInfo(
final Sigar sigar,
final CachingService caching) {
return caching.cache(sigar::getCpuInfoList);
}
示例9: loadAverage
import javaslang.control.Try; //导入方法依赖的package包/类
@Bean
Try.CheckedSupplier<double[]> loadAverage(
final Sigar sigar,
final CachingService caching) {
return caching.cache(sigar::getLoadAverage);
}
示例10: tcp
import javaslang.control.Try; //导入方法依赖的package包/类
@Bean
Try.CheckedSupplier<Tcp> tcp(
final Sigar sigar,
final CachingService caching) {
return caching.cache(sigar::getTcp);
}
示例11: testCircuitBreakerWithTimeout
import javaslang.control.Try; //导入方法依赖的package包/类
@Test
public void testCircuitBreakerWithTimeout() {
CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
.failureRateThreshold(25)
.waitDurationInOpenState(Duration.ofMillis(1000))
.ringBufferSizeInHalfOpenState(1)
.ringBufferSizeInClosedState(2)
.build();
CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("test");
Try.CheckedSupplier<String> decoratedSupplier = CircuitBreaker
.decorateCheckedSupplier(circuitBreaker, () -> "This can be any method which returns: 'Hello");
Observable.interval(500,TimeUnit.MILLISECONDS).map(i -> {
return Try.of(() -> {
Thread.sleep(1000);
return "result"+i;
} ).recover(throwable -> "recovered"+i);
}).timeout(500,TimeUnit.MILLISECONDS)
.lift(CircuitBreakerOperator.of(circuitBreaker))
.subscribe(System.out::println);
LockSupport.park();
}
示例12: cache
import javaslang.control.Try; //导入方法依赖的package包/类
<R> Try.CheckedSupplier<R> cache(Try.CheckedSupplier<R> func);