List of usage examples for java.util.concurrent ConcurrentMap get
V get(Object key);
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
@GET @Path("/apps") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AppsInfo getApps(@Context HttpServletRequest hsr, @QueryParam("state") String stateQuery, @QueryParam("states") Set<String> statesQuery, @QueryParam("finalStatus") String finalStatusQuery, @QueryParam("user") String userQuery, @QueryParam("queue") String queueQuery, @QueryParam("limit") String count, @QueryParam("startedTimeBegin") String startedBegin, @QueryParam("startedTimeEnd") String startedEnd, @QueryParam("finishedTimeBegin") String finishBegin, @QueryParam("finishedTimeEnd") String finishEnd, @QueryParam("applicationTypes") Set<String> applicationTypes, @QueryParam("applicationTags") Set<String> applicationTags) { boolean checkCount = false; boolean checkStart = false; boolean checkEnd = false; boolean checkAppTypes = false; boolean checkAppStates = false; boolean checkAppTags = false; long countNum = 0; // set values suitable in case both of begin/end not specified long sBegin = 0; long sEnd = Long.MAX_VALUE; long fBegin = 0; long fEnd = Long.MAX_VALUE; init();// w w w. j a va 2 s. c om if (count != null && !count.isEmpty()) { checkCount = true; countNum = Long.parseLong(count); if (countNum <= 0) { throw new BadRequestException("limit value must be greater then 0"); } } if (startedBegin != null && !startedBegin.isEmpty()) { checkStart = true; sBegin = Long.parseLong(startedBegin); if (sBegin < 0) { throw new BadRequestException("startedTimeBegin must be greater than 0"); } } if (startedEnd != null && !startedEnd.isEmpty()) { checkStart = true; sEnd = Long.parseLong(startedEnd); if (sEnd < 0) { throw new BadRequestException("startedTimeEnd must be greater than 0"); } } if (sBegin > sEnd) { throw new BadRequestException("startedTimeEnd must be greater than startTimeBegin"); } if (finishBegin != null && !finishBegin.isEmpty()) { checkEnd = true; fBegin = Long.parseLong(finishBegin); if (fBegin < 0) { throw new BadRequestException("finishTimeBegin must be greater than 0"); } } if (finishEnd != null && !finishEnd.isEmpty()) { checkEnd = true; fEnd = Long.parseLong(finishEnd); if (fEnd < 0) { throw new BadRequestException("finishTimeEnd must be greater than 0"); } } if (fBegin > fEnd) { throw new BadRequestException("finishTimeEnd must be greater than finishTimeBegin"); } Set<String> appTypes = parseQueries(applicationTypes, false); if (!appTypes.isEmpty()) { checkAppTypes = true; } Set<String> appTags = parseQueries(applicationTags, false); if (!appTags.isEmpty()) { checkAppTags = true; } // stateQuery is deprecated. if (stateQuery != null && !stateQuery.isEmpty()) { statesQuery.add(stateQuery); } Set<String> appStates = parseQueries(statesQuery, true); if (!appStates.isEmpty()) { checkAppStates = true; } GetApplicationsRequest request = GetApplicationsRequest.newInstance(); if (checkStart) { request.setStartRange(sBegin, sEnd); } if (checkEnd) { request.setFinishRange(fBegin, fEnd); } if (checkCount) { request.setLimit(countNum); } if (checkAppTypes) { request.setApplicationTypes(appTypes); } if (checkAppTags) { request.setApplicationTags(appTags); } if (checkAppStates) { request.setApplicationStates(appStates); } if (queueQuery != null && !queueQuery.isEmpty()) { ResourceScheduler rs = rm.getResourceScheduler(); if (rs instanceof CapacityScheduler) { CapacityScheduler cs = (CapacityScheduler) rs; // validate queue exists try { cs.getQueueInfo(queueQuery, false, false); } catch (IOException e) { throw new BadRequestException(e.getMessage()); } } Set<String> queues = new HashSet<String>(1); queues.add(queueQuery); request.setQueues(queues); } if (userQuery != null && !userQuery.isEmpty()) { Set<String> users = new HashSet<String>(1); users.add(userQuery); request.setUsers(users); } List<ApplicationReport> appReports = null; try { appReports = rm.getClientRMService().getApplications(request, false).getApplicationList(); } catch (YarnException e) { LOG.error("Unable to retrieve apps from ClientRMService", e); throw new YarnRuntimeException("Unable to retrieve apps from ClientRMService", e); } final ConcurrentMap<ApplicationId, RMApp> apps = rm.getRMContext().getRMApps(); AppsInfo allApps = new AppsInfo(); for (ApplicationReport report : appReports) { RMApp rmapp = apps.get(report.getApplicationId()); if (rmapp == null) { continue; } if (finalStatusQuery != null && !finalStatusQuery.isEmpty()) { FinalApplicationStatus.valueOf(finalStatusQuery); if (!rmapp.getFinalApplicationStatus().toString().equalsIgnoreCase(finalStatusQuery)) { continue; } } AppInfo app = new AppInfo(rm, rmapp, hasAccess(rmapp, hsr), WebAppUtils.getHttpSchemePrefix(conf)); allApps.add(app); } return allApps; }
From source file:org.rifidi.edge.rest.SensorManagerServiceRestletImpl.java
static Series<Header> getMessageHeaders(Message message) { ConcurrentMap<String, Object> attrs = message.getAttributes(); Series<Header> headers = (Series<Header>) attrs.get(HEADERS_KEY); if (headers == null) { headers = new Series<Header>(Header.class); Series<Header> prev = (Series<Header>) attrs.putIfAbsent(HEADERS_KEY, headers); if (prev != null) { headers = prev;//from w w w . ja v a2s . c o m } } return headers; }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
private void assertA1B2C3(final ConcurrentMap<URI, Set<URI>> nextImportsMap) { Assert.assertEquals(5, nextImportsMap.size()); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testVersionUriA1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testVersionUriB1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testVersionUriB2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testVersionUriC1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testVersionUriC3)); Assert.assertEquals(0, nextImportsMap.get(OntologyConstant.testVersionUriA1).size()); Assert.assertEquals(1, nextImportsMap.get(OntologyConstant.testVersionUriB1).size()); Assert.assertEquals(1, nextImportsMap.get(OntologyConstant.testVersionUriB2).size()); Assert.assertEquals(2, nextImportsMap.get(OntologyConstant.testVersionUriC1).size()); Assert.assertEquals(2, nextImportsMap.get(OntologyConstant.testVersionUriC3).size()); Assert.assertTrue(// www . ja va 2 s. co m nextImportsMap.get(OntologyConstant.testVersionUriB1).contains(OntologyConstant.testVersionUriA1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testVersionUriB2).contains(OntologyConstant.testVersionUriA1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testVersionUriC1).contains(OntologyConstant.testVersionUriA1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testVersionUriC1).contains(OntologyConstant.testVersionUriB1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testVersionUriC3).contains(OntologyConstant.testVersionUriA1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testVersionUriC3).contains(OntologyConstant.testVersionUriB2)); }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
@Test public void testImportsOrderZeroLevels() throws Exception { final Model model = new LinkedHashModel(); OntologyUtils.ontologyIDsToModel(Arrays.asList(OntologyConstant.testOntologyID), model); final Set<URI> schemaOntologyUris = new HashSet<URI>(); final Set<URI> schemaVersionUris = new HashSet<URI>(); schemaOntologyUris.add(OntologyConstant.testOntologyUri1); schemaVersionUris.add(OntologyConstant.testVersionUri1); final ConcurrentMap<URI, Set<URI>> importsMap = new ConcurrentHashMap<URI, Set<URI>>(); // Expected output solution from importsMap after calling orderImports // importsMap.put(testVersionUri1, new HashSet<URI>()); final List<URI> orderImports = OntologyUtils.orderImports(model, schemaOntologyUris, schemaVersionUris, importsMap, false);//from w w w .j a v a2 s . co m Assert.assertEquals(1, orderImports.size()); Assert.assertEquals(OntologyConstant.testVersionUri1, orderImports.get(0)); Assert.assertEquals(1, importsMap.size()); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testVersionUri1)); final Set<URI> importsRoot = importsMap.get(OntologyConstant.testVersionUri1); Assert.assertNotNull(importsRoot); Assert.assertEquals(0, importsRoot.size()); }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
@Test public void testImportsOrderOneLevel() throws Exception { final Model model = new LinkedHashModel(); OntologyUtils.ontologyIDsToModel(Arrays.asList(OntologyConstant.testOntologyID), model); model.add(OntologyConstant.testVersionUri1, OWL.IMPORTS, OntologyConstant.testImportOntologyUri1); model.add(OntologyConstant.testImportOntologyUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri1, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri1); model.add(OntologyConstant.testImportVersionUri1, RDF.TYPE, OWL.ONTOLOGY); final Set<URI> schemaOntologyUris = new HashSet<URI>(); final Set<URI> schemaVersionUris = new HashSet<URI>(); schemaOntologyUris.add(OntologyConstant.testOntologyUri1); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri1); schemaVersionUris.add(OntologyConstant.testVersionUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri1); final ConcurrentMap<URI, Set<URI>> importsMap = new ConcurrentHashMap<URI, Set<URI>>(); // Expected output solution from importsMap after calling orderImports // importsMap.put(testVersionUri1, // Collections.singleton(OntologyConstant.testImportVersionUri1)); // importsMap.put(testImportVersionUri1, new HashSet<URI>()); final List<URI> orderImports = OntologyUtils.orderImports(model, schemaOntologyUris, schemaVersionUris, importsMap, false);/*from w w w. j av a2 s . c om*/ Assert.assertEquals(2, orderImports.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri1, orderImports.get(0)); Assert.assertEquals(OntologyConstant.testVersionUri1, orderImports.get(1)); Assert.assertEquals(2, importsMap.size()); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testVersionUri1)); final Set<URI> imports1 = importsMap.get(OntologyConstant.testImportVersionUri1); Assert.assertNotNull(imports1); Assert.assertEquals(0, imports1.size()); final Set<URI> importsRoot = importsMap.get(OntologyConstant.testVersionUri1); Assert.assertNotNull(importsRoot); Assert.assertEquals(1, importsRoot.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri1, importsRoot.iterator().next()); }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
@Test public void testImportsOrderOneLevelOutOfOrder() throws Exception { final Model model = new LinkedHashModel(); OntologyUtils.ontologyIDsToModel(Arrays.asList(OntologyConstant.testOntologyID), model); model.add(OntologyConstant.testImportOntologyUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri1, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri1); model.add(OntologyConstant.testImportVersionUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testVersionUri1, OWL.IMPORTS, OntologyConstant.testImportOntologyUri1); final Set<URI> schemaOntologyUris = new LinkedHashSet<URI>(); final Set<URI> schemaVersionUris = new LinkedHashSet<URI>(); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri1); schemaOntologyUris.add(OntologyConstant.testOntologyUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri1); schemaVersionUris.add(OntologyConstant.testVersionUri1); final ConcurrentMap<URI, Set<URI>> importsMap = new ConcurrentHashMap<URI, Set<URI>>(); // Expected output solution from importsMap after calling orderImports // importsMap.put(testVersionUri1, // Collections.singleton(OntologyConstant.testImportVersionUri1)); // importsMap.put(testImportVersionUri1, new HashSet<URI>()); final List<URI> orderImports = OntologyUtils.orderImports(model, schemaOntologyUris, schemaVersionUris, importsMap, false);// w w w.jav a2s . co m Assert.assertEquals(2, orderImports.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri1, orderImports.get(0)); Assert.assertEquals(OntologyConstant.testVersionUri1, orderImports.get(1)); Assert.assertEquals(2, importsMap.size()); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testVersionUri1)); final Set<URI> imports1 = importsMap.get(OntologyConstant.testImportVersionUri1); Assert.assertNotNull(imports1); Assert.assertEquals(0, imports1.size()); final Set<URI> importsRoot = importsMap.get(OntologyConstant.testVersionUri1); Assert.assertNotNull(importsRoot); Assert.assertEquals(1, importsRoot.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri1, importsRoot.iterator().next()); }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
private void assertRealisticImportsMapV2(final ConcurrentMap<URI, Set<URI>> nextImportsMap) { Assert.assertEquals(12, nextImportsMap.size()); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddUserUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddUserUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddBaseUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddBaseUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddScienceUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddScienceUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddPlantUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddPlantUriV2)); Assert.assertEquals(0, nextImportsMap.get(OntologyConstant.testPoddDcUriV1).size()); Assert.assertEquals(0, nextImportsMap.get(OntologyConstant.testPoddDcUriV2).size()); Assert.assertEquals(1, nextImportsMap.get(OntologyConstant.testPoddFoafUriV1).size()); Assert.assertEquals(1, nextImportsMap.get(OntologyConstant.testPoddFoafUriV2).size()); Assert.assertEquals(2, nextImportsMap.get(OntologyConstant.testPoddUserUriV1).size()); Assert.assertEquals(2, nextImportsMap.get(OntologyConstant.testPoddUserUriV2).size()); Assert.assertEquals(3, nextImportsMap.get(OntologyConstant.testPoddBaseUriV1).size()); Assert.assertEquals(3, nextImportsMap.get(OntologyConstant.testPoddBaseUriV2).size()); Assert.assertEquals(4, nextImportsMap.get(OntologyConstant.testPoddScienceUriV1).size()); Assert.assertEquals(4, nextImportsMap.get(OntologyConstant.testPoddScienceUriV2).size()); Assert.assertEquals(5, nextImportsMap.get(OntologyConstant.testPoddPlantUriV1).size()); Assert.assertEquals(5, nextImportsMap.get(OntologyConstant.testPoddPlantUriV2).size()); Assert.assertTrue(/*from w w w .j a va 2s . c o m*/ nextImportsMap.get(OntologyConstant.testPoddFoafUriV1).contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddFoafUriV2).contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddUserUriV1).contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddUserUriV2).contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddUserUriV1) .contains(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddUserUriV2) .contains(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddBaseUriV1).contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddBaseUriV2).contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV1) .contains(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV2) .contains(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV1) .contains(OntologyConstant.testPoddUserUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV2) .contains(OntologyConstant.testPoddUserUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV1) .contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV2) .contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV1) .contains(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV2) .contains(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV1) .contains(OntologyConstant.testPoddUserUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV2) .contains(OntologyConstant.testPoddUserUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV1) .contains(OntologyConstant.testPoddBaseUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV2) .contains(OntologyConstant.testPoddBaseUriV2)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddPlantUriV1).contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddPlantUriV2).contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV1) .contains(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV2) .contains(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV1) .contains(OntologyConstant.testPoddUserUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV2) .contains(OntologyConstant.testPoddUserUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV1) .contains(OntologyConstant.testPoddBaseUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV2) .contains(OntologyConstant.testPoddBaseUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV1) .contains(OntologyConstant.testPoddScienceUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV2) .contains(OntologyConstant.testPoddScienceUriV2)); }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
@Test public void testImportsOrderFourLevelsOutOfOrder() throws Exception { final Model model = new LinkedHashModel(); OntologyUtils.ontologyIDsToModel(Arrays.asList(OntologyConstant.testOntologyID), model); model.add(OntologyConstant.testVersionUri1, OWL.IMPORTS, OntologyConstant.testImportOntologyUri1); model.add(OntologyConstant.testImportOntologyUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri1, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri1); model.add(OntologyConstant.testImportVersionUri1, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri2, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri2, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri2); model.add(OntologyConstant.testImportVersionUri2, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri1, OWL.IMPORTS, OntologyConstant.testImportVersionUri2); model.add(OntologyConstant.testImportOntologyUri3, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri3, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri3); model.add(OntologyConstant.testImportVersionUri3, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri2, OWL.IMPORTS, OntologyConstant.testImportVersionUri3); model.add(OntologyConstant.testImportOntologyUri4, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportOntologyUri4, OWL.VERSIONIRI, OntologyConstant.testImportVersionUri4); model.add(OntologyConstant.testImportVersionUri4, RDF.TYPE, OWL.ONTOLOGY); model.add(OntologyConstant.testImportVersionUri3, OWL.IMPORTS, OntologyConstant.testImportVersionUri4); final Set<URI> schemaOntologyUris = new LinkedHashSet<URI>(); final Set<URI> schemaVersionUris = new LinkedHashSet<URI>(); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri2); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri4); schemaOntologyUris.add(OntologyConstant.testOntologyUri1); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri3); schemaOntologyUris.add(OntologyConstant.testImportOntologyUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri2); schemaVersionUris.add(OntologyConstant.testImportVersionUri4); schemaVersionUris.add(OntologyConstant.testVersionUri1); schemaVersionUris.add(OntologyConstant.testImportVersionUri3); schemaVersionUris.add(OntologyConstant.testImportVersionUri1); final ConcurrentMap<URI, Set<URI>> importsMap = new ConcurrentHashMap<URI, Set<URI>>(); final List<URI> orderImports = OntologyUtils.orderImports(model, schemaOntologyUris, schemaVersionUris, importsMap, false);/*from ww w.j a v a2 s. co m*/ Assert.assertEquals(5, orderImports.size()); Assert.assertEquals(OntologyConstant.testImportVersionUri4, orderImports.get(0)); Assert.assertEquals(OntologyConstant.testImportVersionUri3, orderImports.get(1)); Assert.assertEquals(OntologyConstant.testImportVersionUri2, orderImports.get(2)); Assert.assertEquals(OntologyConstant.testImportVersionUri1, orderImports.get(3)); Assert.assertEquals(OntologyConstant.testVersionUri1, orderImports.get(4)); Assert.assertEquals(5, importsMap.size()); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri4)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsMap.containsKey(OntologyConstant.testVersionUri1)); final Set<URI> imports4 = importsMap.get(OntologyConstant.testImportVersionUri4); Assert.assertNotNull(imports4); Assert.assertEquals(0, imports4.size()); final Set<URI> imports3 = importsMap.get(OntologyConstant.testImportVersionUri3); Assert.assertNotNull(imports3); Assert.assertEquals(1, imports3.size()); Assert.assertTrue(imports3.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> imports2 = importsMap.get(OntologyConstant.testImportVersionUri2); Assert.assertNotNull(imports2); Assert.assertEquals(2, imports2.size()); Assert.assertTrue(imports2.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(imports2.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> imports1 = importsMap.get(OntologyConstant.testImportVersionUri1); Assert.assertNotNull(imports1); Assert.assertEquals(3, imports1.size()); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(imports1.contains(OntologyConstant.testImportVersionUri4)); final Set<URI> importsRoot = importsMap.get(OntologyConstant.testVersionUri1); Assert.assertNotNull(importsRoot); Assert.assertEquals(4, importsRoot.size()); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri1)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri2)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri3)); Assert.assertTrue(importsRoot.contains(OntologyConstant.testImportVersionUri4)); }
From source file:org.dkpro.lab.engine.impl.MultiThreadBatchTaskEngine.java
@Override protected void executeConfiguration(BatchTask aConfiguration, TaskContext aContext, Map<String, Object> aConfig, Set<String> aExecutedSubtasks) throws ExecutionException, LifeCycleException { if (log.isTraceEnabled()) { // Show all subtasks executed so far for (String est : aExecutedSubtasks) { log.trace("-- Already executed: " + est); }/*w ww. ja v a 2s.c o m*/ } // Set up initial scope used by sub-batch-tasks using the inherited scope. The scope is // extended as the subtasks of this batch are executed with the present configuration. // FIXME: That means that sub-batch-tasks in two different configurations cannot see // each other. Is that intended? Mind that the "executedSubtasks" set is intentionally // maintained *across* configurations, so maybe the scope should also be maintained // *across* configurations? - REC 2014-06-15 Set<String> scope = new HashSet<>(); if (aConfiguration.getScope() != null) { scope.addAll(aConfiguration.getScope()); } // Configure subtasks for (Task task : aConfiguration.getTasks()) { // Now the setup is complete aContext.getLifeCycleManager().configure(aContext, task, aConfig); } Queue<Task> queue = new LinkedList<>(aConfiguration.getTasks()); // keeps track of the execution threads; // TODO MW: do we really need this or can we work with the futures list only? Map<Task, ExecutionThread> threads = new HashMap<>(); // keeps track of submitted Futures and their associated tasks Map<Future<?>, Task> futures = new HashMap<Future<?>, Task>(); // will be instantiated with all exceptions from current loop ConcurrentMap<Task, Throwable> exceptionsFromLastLoop = null; ConcurrentMap<Task, Throwable> exceptionsFromCurrentLoop = new ConcurrentHashMap<>(); int outerLoopCounter = 0; // main loop do { outerLoopCounter++; threads.clear(); futures.clear(); ExecutorService executor = Executors.newFixedThreadPool(maxThreads); // set the exceptions from the last loop exceptionsFromLastLoop = new ConcurrentHashMap<>(exceptionsFromCurrentLoop); // Fix MW: Clear exceptionsFromCurrentLoop; otherwise the loop with run at most twice. exceptionsFromCurrentLoop.clear(); // process all tasks from the queue while (!queue.isEmpty()) { Task task = queue.poll(); TaskContextMetadata execution = getExistingExecution(aConfiguration, aContext, task, aConfig, aExecutedSubtasks); // Check if a subtask execution compatible with the present configuration has // does already exist ... if (execution == null) { // ... otherwise execute it with the present configuration log.info("Executing task [" + task.getType() + "]"); // set scope here so that the inherited scopes are considered if (task instanceof BatchTask) { ((BatchTask) task).setScope(scope); } ExecutionThread thread = new ExecutionThread(aContext, task, aConfig, aExecutedSubtasks); threads.put(task, thread); futures.put(executor.submit(thread), task); } else { log.debug("Using existing execution [" + execution.getId() + "]"); // Record new/existing execution aExecutedSubtasks.add(execution.getId()); scope.add(execution.getId()); } } // try and get results from all futures to check for failed executions for (Map.Entry<Future<?>, Task> entry : futures.entrySet()) { try { entry.getKey().get(); } catch (java.util.concurrent.ExecutionException ex) { Task task = entry.getValue(); // TODO MW: add a retry-counter here to prevent endless loops? log.info("Task exec failed for [" + task.getType() + "]"); // record the failed task, so that it can be re-added to the queue exceptionsFromCurrentLoop.put(task, ex); } catch (InterruptedException ex) { // thread interrupted, exit throw new RuntimeException(ex); } } log.debug("Calling shutdown"); executor.shutdown(); log.debug("All threads finished"); // collect the results for (Map.Entry<Task, ExecutionThread> entry : threads.entrySet()) { Task task = entry.getKey(); ExecutionThread thread = entry.getValue(); TaskContextMetadata execution = thread.getTaskContextMetadata(); // probably failed if (execution == null) { Throwable exception = exceptionsFromCurrentLoop.get(task); if (!(exception instanceof UnresolvedImportException) && !(exception instanceof java.util.concurrent.ExecutionException)) { throw new RuntimeException(exception); } exceptionsFromCurrentLoop.put(task, exception); // re-add to the queue queue.add(task); } else { // Record new/existing execution aExecutedSubtasks.add(execution.getId()); scope.add(execution.getId()); } } } // finish if the same tasks failed again while (!exceptionsFromCurrentLoop.keySet().equals(exceptionsFromLastLoop.keySet())); // END OF DO; finish if the same tasks failed again if (!exceptionsFromCurrentLoop.isEmpty()) { // collect all details StringBuilder details = new StringBuilder(); for (Throwable throwable : exceptionsFromCurrentLoop.values()) { details.append("\n -"); details.append(throwable.getMessage()); } // we re-throw the first exception Throwable next = exceptionsFromCurrentLoop.values().iterator().next(); if (next instanceof RuntimeException) { throw (RuntimeException) next; } // otherwise wrap it throw new RuntimeException(details.toString(), next); } log.info("MultiThreadBatchTask completed successfully. Total number of outer loop runs: " + outerLoopCounter); }
From source file:com.github.podd.utils.test.OntologyUtilsTest.java
private void assertRealisticImportsMapV3(final ConcurrentMap<URI, Set<URI>> nextImportsMap) { Assert.assertEquals(22, nextImportsMap.size()); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddDcUriV3)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddFoafUriV3)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddUserUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddUserUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddUserUriV3)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddBaseUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddBaseUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddBaseUriV3)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddScienceUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddScienceUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddScienceUriV3)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddPlantUriV1)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddPlantUriV2)); Assert.assertTrue(nextImportsMap.containsKey(OntologyConstant.testPoddPlantUriV3)); Assert.assertEquals(0, nextImportsMap.get(OntologyConstant.testPoddDcUriV1).size()); Assert.assertEquals(0, nextImportsMap.get(OntologyConstant.testPoddDcUriV2).size()); Assert.assertEquals(0, nextImportsMap.get(OntologyConstant.testPoddDcUriV3).size()); Assert.assertEquals(1, nextImportsMap.get(OntologyConstant.testPoddFoafUriV1).size()); Assert.assertEquals(1, nextImportsMap.get(OntologyConstant.testPoddFoafUriV2).size()); Assert.assertEquals(1, nextImportsMap.get(OntologyConstant.testPoddFoafUriV3).size()); Assert.assertEquals(2, nextImportsMap.get(OntologyConstant.testPoddUserUriV1).size()); Assert.assertEquals(2, nextImportsMap.get(OntologyConstant.testPoddUserUriV2).size()); Assert.assertEquals(2, nextImportsMap.get(OntologyConstant.testPoddUserUriV3).size()); Assert.assertEquals(3, nextImportsMap.get(OntologyConstant.testPoddBaseUriV1).size()); Assert.assertEquals(3, nextImportsMap.get(OntologyConstant.testPoddBaseUriV2).size()); Assert.assertEquals(3, nextImportsMap.get(OntologyConstant.testPoddBaseUriV3).size()); Assert.assertEquals(4, nextImportsMap.get(OntologyConstant.testPoddScienceUriV1).size()); Assert.assertEquals(6, nextImportsMap.get(OntologyConstant.testPoddScienceUriV2).size()); Assert.assertEquals(4, nextImportsMap.get(OntologyConstant.testPoddScienceUriV3).size()); Assert.assertEquals(5, nextImportsMap.get(OntologyConstant.testPoddPlantUriV1).size()); Assert.assertEquals(7, nextImportsMap.get(OntologyConstant.testPoddPlantUriV2).size()); Assert.assertEquals(5, nextImportsMap.get(OntologyConstant.testPoddPlantUriV3).size()); Assert.assertTrue(/*from ww w. j a va 2 s . c o m*/ nextImportsMap.get(OntologyConstant.testPoddFoafUriV1).contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddFoafUriV2).contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddFoafUriV3).contains(OntologyConstant.testPoddDcUriV3)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddUserUriV1).contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddUserUriV2).contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddUserUriV3).contains(OntologyConstant.testPoddDcUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddUserUriV1) .contains(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddUserUriV2) .contains(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddUserUriV3) .contains(OntologyConstant.testPoddFoafUriV3)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddBaseUriV1).contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddBaseUriV2).contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddBaseUriV3).contains(OntologyConstant.testPoddDcUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV1) .contains(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV2) .contains(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV3) .contains(OntologyConstant.testPoddFoafUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV1) .contains(OntologyConstant.testPoddUserUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV2) .contains(OntologyConstant.testPoddUserUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddBaseUriV3) .contains(OntologyConstant.testPoddUserUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV1) .contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV2) .contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV3) .contains(OntologyConstant.testPoddDcUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV1) .contains(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV2) .contains(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV3) .contains(OntologyConstant.testPoddFoafUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV1) .contains(OntologyConstant.testPoddUserUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV2) .contains(OntologyConstant.testPoddUserUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV3) .contains(OntologyConstant.testPoddUserUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV1) .contains(OntologyConstant.testPoddBaseUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV2) .contains(OntologyConstant.testPoddBaseUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddScienceUriV3) .contains(OntologyConstant.testPoddBaseUriV3)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddPlantUriV1).contains(OntologyConstant.testPoddDcUriV1)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddPlantUriV2).contains(OntologyConstant.testPoddDcUriV2)); Assert.assertTrue( nextImportsMap.get(OntologyConstant.testPoddPlantUriV3).contains(OntologyConstant.testPoddDcUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV1) .contains(OntologyConstant.testPoddFoafUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV2) .contains(OntologyConstant.testPoddFoafUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV3) .contains(OntologyConstant.testPoddFoafUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV1) .contains(OntologyConstant.testPoddUserUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV2) .contains(OntologyConstant.testPoddUserUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV3) .contains(OntologyConstant.testPoddUserUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV1) .contains(OntologyConstant.testPoddBaseUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV2) .contains(OntologyConstant.testPoddBaseUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV3) .contains(OntologyConstant.testPoddBaseUriV3)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV1) .contains(OntologyConstant.testPoddScienceUriV1)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV2) .contains(OntologyConstant.testPoddScienceUriV2)); Assert.assertTrue(nextImportsMap.get(OntologyConstant.testPoddPlantUriV3) .contains(OntologyConstant.testPoddScienceUriV3)); }