本文整理汇总了Java中java.util.concurrent.ConcurrentMap.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentMap.forEach方法的具体用法?Java ConcurrentMap.forEach怎么用?Java ConcurrentMap.forEach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ConcurrentMap
的用法示例。
在下文中一共展示了ConcurrentMap.forEach方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConnectionFromDB
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
public Map<UUID, DockerConnection> getConnectionFromDB() throws IOException {
Map<UUID, DockerConnection> listOfConnections = new HashMap<>();
File database = new File("./connections.db");
DB db = DBMaker
.fileDB(database)
.transactionEnable()
.closeOnJvmShutdown()
.fileChannelEnable()
.make();
ConcurrentMap mapa = db.hashMap("map").createOrOpen();
mapa.forEach((uuid, connection) -> {
listOfConnections.put((UUID) uuid, (DockerConnection) connection);
});
db.close();
return listOfConnections;
}
示例2: testMap
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
private void testMap(ConcurrentMap<Integer, Integer> map, Consumer<ConcurrentMap<Integer, Integer>> action)
throws InterruptedException {
// put 0's
fillMap(map, 0);
// To start working simultaneously
CyclicBarrier threadStarted = new CyclicBarrier(2);
// This task puts 1's into map
CompletableFuture<Void> putter = CompletableFuture.runAsync(
awaitOn(threadStarted, () -> fillMap(map, 1)),
executorService);
// This task performs the map action to remove all 0's from map
CompletableFuture<Void> remover = CompletableFuture.runAsync(
awaitOn(threadStarted, () -> action.accept(map)),
executorService);
// Wait for both tasks to complete
CompletableFuture.allOf(putter, remover).join();
assertEquals(map.size(), SIZE, "Map size incorrect");
map.forEach((k, v) -> assertEquals(v, (Integer)1));
}
示例3: testRead
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
public void testRead() {
final Origin orgin = Instance.singleton(EndPointOrigin.class);
final ConcurrentMap<String, Record> records = orgin.getRegistryData();
records.forEach((key, value) -> {
System.out.println(key);
System.out.println(value.toJson().encodePrettily());
});
}
示例4: reduce
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
/**
* Merge two map
*
* @param from
* @param to
* @param <K>
* @param <T>
* @param <V>
* @return
*/
public static <K, T, V> ConcurrentMap<K, V> reduce(
final ConcurrentMap<K, T> from,
final ConcurrentMap<T, V> to) {
final ConcurrentMap<K, V> result = new ConcurrentHashMap<>();
from.forEach((key, middle) -> {
final V value = to.get(middle);
if (null != value) {
result.put(key, value);
}
});
return result;
}
示例5: exec
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
/**
* @param map
* @param fnEach
* @param <K>
* @param <V>
*/
static <K, V> void exec(final ConcurrentMap<K, V> map,
final BiConsumer<K, V> fnEach) {
map.forEach((key, value) -> {
if (null != key && null != value) {
fnEach.accept(key, value);
}
});
}
示例6: EtcdData
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
private EtcdData(final Class<?> clazz) {
this.clazz = clazz;
this.logger = Annal.get(clazz);
// Read configuration
final JsonObject config = NODE.read();
if (config.containsKey(KEY)) {
final JsonObject root = config.getJsonObject(KEY);
// Verify the data
Fn.flingUp(() -> Fn.shuntZero(() -> Ruler.verify(KEY, root), root),
LOGGER);
if (root.containsKey(TIMEOUT)) {
this.timeout = root.getLong(TIMEOUT);
}
if (root.containsKey(MICRO)) {
this.application = root.getString(MICRO);
}
// Nodes
if (root.containsKey(NODES)) {
this.config.addAll(root.getJsonArray(NODES));
}
LOGGER.info(Info.ETCD_TIMEOUT,
this.application, this.timeout, this.config.size());
}
Fn.flingUp(this.config.isEmpty(), this.logger,
EtcdConfigEmptyException.class, this.clazz);
final Set<URI> uris = new HashSet<>();
final ConcurrentMap<Integer, String> networks
= new ConcurrentHashMap<>();
Observable.fromIterable(this.config)
.filter(Objects::nonNull)
.map(item -> (JsonObject) item)
.filter(item -> item.containsKey(PORT) && item.containsKey(HOST))
.map(item -> {
final Integer port = item.getInteger(PORT);
final String host = item.getString(HOST);
networks.put(port, host);
return "http://" + host + ":" + port;
})
.map(URI::create)
.subscribe(uris::add);
// Network checking
networks.forEach((port, host) ->
Fn.flingUp(!Net.isReach(host, port), LOGGER,
EtcdNetworkException.class, getClass(), host, port));
LOGGER.info(Info.ETCD_NETWORK);
this.client = new EtcdClient(uris.toArray(new URI[]{}));
}
示例7: each
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
public static void each(
final BiConsumer<String, VertxOptions> consumer) {
final ConcurrentMap<String, VertxOptions> vertxOptions
= ZeroGrid.getVertxOptions();
vertxOptions.forEach(consumer);
}
示例8: getControllers
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
private List<Controller> getControllers(Uuid bridgeUuid) {
DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
if (dbSchema == null) {
return null;
}
OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
OvsdbConstant.BRIDGE);
if (rowStore == null) {
log.debug("There is no bridge table");
return null;
}
Row bridgeRow = rowStore.getRow(bridgeUuid.value());
Bridge bridge = (Bridge) TableGenerator.
getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
//FIXME remove log
log.warn("type of controller column", bridge.getControllerColumn()
.data().getClass());
Set<Uuid> controllerUuids = (Set<Uuid>) ((OvsdbSet) bridge
.getControllerColumn().data()).set();
// Set<String> controllerUuidStrings = (Set<String>) bridge.getControllerColumn().data();
OvsdbRowStore controllerRowStore = getRowStore(OvsdbConstant.DATABASENAME,
OvsdbConstant.CONTROLLER);
if (controllerRowStore == null) {
log.debug("There is no controller table");
return null;
}
List<Controller> ovsdbControllers = new ArrayList<>();
ConcurrentMap<String, Row> controllerTableRows = controllerRowStore.getRowStore();
controllerTableRows.forEach((key, row) -> {
if (!controllerUuids.contains(Uuid.uuid(key))) {
return;
}
Controller controller = (Controller) TableGenerator
.getTable(dbSchema, row, OvsdbTable.CONTROLLER);
ovsdbControllers.add(controller);
});
return ovsdbControllers;
}
示例9: main
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
/**
* The main method.
*
* @param args
* the arguments
* @throws ParseException
* the parse exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void main(final String args[]) throws ParseException, IOException {
// Parse CLI options
final Options options = getCmdOptions();
final CommandLine cmd = parseCmdOptions(options, args);
if (cmd == null || cmd.hasOption("h")) {
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("metarecsys", options);
System.exit(0);
}
final Path runsFolder = Paths.get(cmd.getOptionValue(RUN_OPTION));
final Path outputFolder = Paths.get(cmd.getOptionValue(OUT_OPTION));
final int maxRank = Integer.parseInt(cmd.getOptionValue(MAX_OPTION, DEFAULT_MAX_RANK));
// Build metarecsys algorithms
final List<RankAggregation> algs = Arrays.stream(cmd.getOptionValues(ALG_OPTION))
.map(name -> RankAggregation.build(name, maxRank)).collect(Collectors.toList());
// For each normalisation algorithm
for (final String norm : cmd.getOptionValues(NORM_OPTION)) {
// Read runs by fold
final ConcurrentMap<Integer, List<RunFile>> runsByFold = RunFile.readRuns(runsFolder,
maxRank, NormalisationAlgorithm.build(norm));
// For each metarecsys algorithm
for (final RankAggregation alg : algs) {
// For each fold
runsByFold.forEach((fold, runs) -> {
alg.computeAllCombinations(fold, runs, outputFolder);
});
}
}
RankAggregation.finishPool();
Logger.getGlobal().info("Finished!");
}