List of usage examples for java.util.concurrent TimeUnit HOURS
TimeUnit HOURS
To view the source code for java.util.concurrent TimeUnit HOURS.
Click Source Link
From source file:org.italiangrid.voms.aa.x509.ACServlet.java
/** * //www.ja v a2 s . c o m * @return */ protected AttributeAuthority newAttributeAuthority() { long maximumValidity = VOMSConfiguration.instance() .getLong(VOMSConfigurationConstants.VOMS_AA_X509_MAX_AC_VALIDITY, TimeUnit.HOURS.toSeconds(12)); boolean legacyFQANEncoding = VOMSConfiguration.instance() .getBoolean(VOMSConfigurationConstants.VOMS_AA_X509_LEGACY_FQAN_ENCODING, true); return AttributeAuthorityFactory.newAttributeAuthority(maximumValidity, legacyFQANEncoding); }
From source file:com.googlesource.gerrit.plugins.github.velocity.VelocityStaticServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse rsp) throws IOException { final Resource p = local(req); if (p == null) { CacheHeaders.setNotCacheable(rsp); rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); return;//from www . j a va 2s . c om } final String type = contentType(p.getName()); final byte[] tosend; if (!type.equals("application/x-javascript") && RPCServletUtils.acceptsGzipEncoding(req)) { rsp.setHeader("Content-Encoding", "gzip"); tosend = compress(readResource(p)); } else { tosend = readResource(p); } CacheHeaders.setCacheable(req, rsp, 12, TimeUnit.HOURS); rsp.setDateHeader("Last-Modified", p.getLastModified()); rsp.setContentType(type); rsp.setContentLength(tosend.length); final OutputStream out = rsp.getOutputStream(); try { out.write(tosend); } finally { out.close(); } }
From source file:org.wso2.carbon.governance.api.util.CheckpointTimeUtils.java
/** * This method is used to format a timestamp to 'dd:hh:mm:ss'. * * @param duration timestamp duration.//from ww w . j a v a 2 s . c o m * @return formatted time duration to 'dd:hh:mm:ss'. */ public static String formatTimeDuration(long duration) { String timeDuration; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)); // Setting the duration to a readable format. if (days == 0 && hours == 0 && minutes == 0) { timeDuration = String.format(durationSecondsFormat, seconds); } else if (days == 0 && hours == 0) { timeDuration = String.format(durationMinutesSecondsFormat, minutes, seconds); } else if (days == 0) { timeDuration = String.format(durationHoursMinutesSecondsFormat, hours, minutes, seconds); } else { timeDuration = String.format(durationDaysHoursMinutesSecondsFormat, days, hours, minutes, seconds); } return timeDuration; }
From source file:org.bimserver.tests.TestSimultaniousDownloadWithCaching.java
private void start() { BimServerConfig config = new BimServerConfig(); Path homeDir = Paths.get("home"); try {//from w w w.j a va 2 s. com if (Files.isDirectory(homeDir)) { PathUtils.removeDirectoryWithContent(homeDir); } } catch (IOException e) { e.printStackTrace(); } config.setClassPath(System.getProperty("java.class.path")); config.setHomeDir(homeDir); config.setPort(8080); config.setStartEmbeddedWebServer(true); config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../"))); final BimServer bimServer = new BimServer(config); try { LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null); bimServer.start(); if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) { bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null); } } catch (PluginException e2) { e2.printStackTrace(); } catch (ServerException e) { e.printStackTrace(); } catch (DatabaseInitException e) { e.printStackTrace(); } catch (BimserverDatabaseException e) { e.printStackTrace(); } catch (DatabaseRestartRequiredException e) { e.printStackTrace(); } catch (UserException e) { e.printStackTrace(); } try { final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL); ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class); SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class); final AuthInterface authInterface = serviceMap.get(AuthInterface.class); serviceInterface = bimServer.getServiceFactory() .get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL) .get(ServiceInterface.class); settingsInterface.setCacheOutputFiles(true); settingsInterface.setGenerateGeometryOnCheckin(false); final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1"); SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface() .getDeserializerByName("IfcStepDeserializer"); Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc"); serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true); final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid()); ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000)); for (int i = 0; i < 20; i++) { executor.execute(new Runnable() { @Override public void run() { try { ServiceMap serviceMap2 = bimServer.getServiceFactory().get( authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL); SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap .getServiceInterface().getSerializerByName("Ifc2x3"); Long download = serviceMap2.getServiceInterface().download( Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true); SDownloadResult downloadData = serviceMap2.getServiceInterface() .getDownloadData(download); if (downloadData.getFile() .getDataSource() instanceof CacheStoringEmfSerializerDataSource) { CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData .getFile().getDataSource(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); c.writeToOutputStream(baos, null); System.out.println(baos.size()); } catch (SerializerException e) { e.printStackTrace(); } } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(downloadData.getFile().getInputStream(), baos); System.out.println(baos.size()); } serviceMap2.getServiceInterface().cleanupLongAction(download); } catch (ServerException e) { e.printStackTrace(); } catch (UserException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (PublicInterfaceNotFoundException e1) { e1.printStackTrace(); } } }); } executor.shutdown(); executor.awaitTermination(1, TimeUnit.HOURS); bimServer.stop(); } catch (ServerException e1) { e1.printStackTrace(); } catch (UserException e1) { e1.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (PublicInterfaceNotFoundException e2) { e2.printStackTrace(); } }
From source file:com.fallahpoor.infocenter.fragments.GeneralFragment.java
private String getFormattedUptime() { String uptimeStr;//from w ww. j a v a2s.c om long uptimeLong = SystemClock.elapsedRealtime(); uptimeStr = String.format(Utils.getLocale(), "%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(uptimeLong), TimeUnit.MILLISECONDS.toMinutes(uptimeLong) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(uptimeLong)), TimeUnit.MILLISECONDS.toSeconds(uptimeLong) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(uptimeLong))); return uptimeStr; }
From source file:org.ahp.vinavidai.quiz.action.ProcessEditQuestion.java
/** * /*from ww w . java2 s . c o m*/ * @param pEditQuestionForm * @param pLoggedInUser */ private void storeQuestion(EditQuestionForm pEditQuestionForm, User pLoggedInUser) { Quiz lQuizUnderCreation = pEditQuestionForm.getQuiz(); Question lQuestion = new Question(); Audit lAudit = AhpBusinessDelegate.createAudit(pLoggedInUser); lQuestion.setAudit(lAudit); lQuestion.setQuiz(lQuizUnderCreation); lQuestion.setQuestionType(QuestionType.valueOf(pEditQuestionForm.getQuestionType())); lQuestion.setQuestionDescription(pEditQuestionForm.getQuestionDescription()); lQuestion.setQuestionObjective(pEditQuestionForm.getQuestionObjective()); if (lQuizUnderCreation.getQuestions() != null) { lQuestion.setQuestionOrder(pEditQuestionForm.getQuiz().getQuestions().size() + 1); } else { lQuestion.setQuestionOrder(1); } Category lCategory = new Category(); lCategory.setCategoryId(pEditQuestionForm.getSelectedQuestionCategory()); lQuestion.setCategory(lCategory); SkillLevel lSkillLevel = new SkillLevel(); lSkillLevel.setSkillLevelId(pEditQuestionForm.getSelectedQuestionSkillLevel()); lQuestion.setSkillLevel(lSkillLevel); lQuestion.setQuestionPoints(pEditQuestionForm.getQuestionPoints()); long lQuestionDuration = -1; if (StringUtils.isNotBlank(pEditQuestionForm.getResponseDurationInHours())) { lQuestionDuration += TimeUnit.MILLISECONDS .convert(Long.parseLong(pEditQuestionForm.getResponseDurationInHours()), TimeUnit.HOURS); } if (StringUtils.isNotBlank(pEditQuestionForm.getResponseDurationInMinutes())) { lQuestionDuration += TimeUnit.MILLISECONDS .convert(Long.parseLong(pEditQuestionForm.getResponseDurationInHours()), TimeUnit.MINUTES); } if (StringUtils.isNotBlank(pEditQuestionForm.getResponseDurationInSeconds())) { lQuestionDuration += TimeUnit.MILLISECONDS .convert(Long.parseLong(pEditQuestionForm.getResponseDurationInHours()), TimeUnit.SECONDS); } lQuestion.setQuestionDuration(lQuestionDuration); if (lQuestion.getQuestionType().equals(QuestionType.MultipleChoice) || lQuestion.getQuestionType().equals(QuestionType.WordList) || lQuestion.getQuestionType().equals(QuestionType.Matching) || lQuestion.getQuestionType().equals(QuestionType.Ordering)) { for (Option lOption : pEditQuestionForm.getOptions()) { lOption.setQuestion(lQuestion); lOption.setAudit(lAudit); } } if (lQuestion.getQuestionType().equals(QuestionType.TrueOrFalse) || lQuestion.getQuestionType().equals(QuestionType.Descriptive)) { Option lOption = pEditQuestionForm.getOptions().get(0); lOption.setQuestion(lQuestion); if (!StringUtils.isEmpty(lOption.getDescriptionQuestionMaximumSizeTypeStr())) { lOption.setDescriptionQuestionMaximumSizeType(DescriptionQuestionMaximumSizeType .valueOf(lOption.getDescriptionQuestionMaximumSizeTypeStr())); } lOption.setAudit(lAudit); List<Option> lOptions = new LinkedList<Option>(); lOptions.add(lOption); pEditQuestionForm.setOptions(lOptions); } // Set Options in Question Set<Option> lOptions = new LinkedHashSet<Option>(); for (Option lOption : pEditQuestionForm.getOptions()) { lOptions.add(lOption); } lQuestion.setOptions(lOptions); /* * if ( lQuizUnderCreation.getQuestions() == null ) { Set<Question> * lQuestions = new LinkedHashSet<Question>(); lQuestions.add( lQuestion * ); // lQuizUnderCreation.setQuestions( lQuestions ); } else { * lQuizUnderCreation.getQuestions().add( lQuestion ); } */ lQuizUnderCreation = this.mQuizService.updateQuiz(lQuizUnderCreation); pEditQuestionForm.setQuiz(lQuizUnderCreation); }
From source file:com.erudika.scoold.controllers.SearchController.java
@ResponseBody @GetMapping("/opensearch.xml") public ResponseEntity<String> openSearch() { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\" " + " xmlns:moz=\"http://www.mozilla.org/2006/browser/search/\">\n" + " <ShortName>" + Config.APP_NAME + "</ShortName>\n" + " <Description>Search for questions and answers</Description>\n" + " <InputEncoding>UTF-8</InputEncoding>\n" + " <Image width=\"16\" height=\"16\" type=\"image/x-icon\">http://scoold.com/favicon.ico</Image>\n" + " <Url type=\"text/html\" method=\"get\" template=\"" + ScooldServer.getServerURL() + "/search?q={searchTerms}\"></Url>\n" + "</OpenSearchDescription>"; return ResponseEntity.ok().contentType(MediaType.APPLICATION_XML) .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)).eTag(Utils.md5(xml)).body(xml); }
From source file:com.markupartist.sthlmtraveling.utils.DateTimeUtil.java
/** * Format duration without rounding. Seconds are still rounded though. * * @param resources a resource//from w w w .j a v a 2 s.co m * @param millis duration in millis * @return A string representing the duration */ public static CharSequence formatDetailedDuration(@NonNull final Resources resources, long millis) { int days = 0, hours = 0, minutes = 0; if (millis > 0) { days = (int) TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); hours = (int) TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); minutes = (int) TimeUnit.MILLISECONDS.toMinutes(millis); } if (days > 0) { return resources.getQuantityString(R.plurals.duration_days, days, days); } if (hours > 0) { if (minutes == 0) { return resources.getQuantityString(R.plurals.duration_short_hours, hours, hours); } return resources.getString(R.string.duration_short_hours_minutes, hours, minutes); } return resources.getQuantityString(R.plurals.duration_short_minutes, minutes, minutes); }
From source file:com.liferay.portal.search.elasticsearch.internal.connection.EmbeddedElasticsearchConnection.java
@Override public void close() { super.close(); if (_node == null) { return;//w w w . jav a2 s. co m } try { Class.forName(ByteBufferUtil.class.getName()); } catch (ClassNotFoundException cnfe) { if (_log.isWarnEnabled()) { _log.warn( StringBundler.concat("Unable to preload ", String.valueOf(ByteBufferUtil.class), " to prevent Netty shutdown concurrent class loading ", "interruption issue"), cnfe); } } if (PortalRunMode.isTestMode()) { settingsBuilder.put("index.refresh_interval", "-1"); settingsBuilder.put("index.translog.flush_threshold_ops", Integer.MAX_VALUE); settingsBuilder.put("index.translog.interval", "1d"); Settings settings = settingsBuilder.build(); Injector injector = _node.injector(); IndicesService indicesService = injector.getInstance(IndicesService.class); Iterator<IndexService> iterator = indicesService.iterator(); while (iterator.hasNext()) { IndexService indexService = iterator.next(); injector = indexService.injector(); IndexSettingsService indexSettingsService = injector.getInstance(IndexSettingsService.class); indexSettingsService.refreshSettings(settings); } ThreadPool threadPool = injector.getInstance(ThreadPool.class); ScheduledExecutorService scheduledExecutorService = threadPool.scheduler(); if (scheduledExecutorService instanceof ThreadPoolExecutor) { ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) scheduledExecutorService; threadPoolExecutor.setRejectedExecutionHandler(_REJECTED_EXECUTION_HANDLER); } scheduledExecutorService.shutdown(); try { scheduledExecutorService.awaitTermination(1, TimeUnit.HOURS); } catch (InterruptedException ie) { if (_log.isWarnEnabled()) { _log.warn("Thread pool shutdown wait was interrupted", ie); } } } _node.close(); _node = null; _file.deltree(_jnaTmpDirName); }
From source file:com.hpcloud.util.Duration.java
public long toHours() { return TimeUnit.HOURS.convert(length, timeUnit); }