Example usage for java.util.concurrent TimeUnit DAYS

List of usage examples for java.util.concurrent TimeUnit DAYS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit DAYS.

Prototype

TimeUnit DAYS

To view the source code for java.util.concurrent TimeUnit DAYS.

Click Source Link

Document

Time unit representing twenty four hours.

Usage

From source file:org.zenoss.zep.impl.Application.java

private void startEventArchivePurging() {
    final int duration = config.getEventArchivePurgeIntervalDays();
    if (oldConfig != null && duration == oldConfig.getEventArchivePurgeIntervalDays()) {
        logger.info("Event archive purging configuration not changed.");
        return;/*from   w w w .j  a v  a 2  s. co m*/
    }
    cancelFuture(this.eventArchivePurger);
    this.eventArchivePurger = purge(eventStoreDao, duration, TimeUnit.DAYS,
            eventArchiveDao.getPartitionIntervalInMs(), "ZEP_EVENT_ARCHIVE_PURGER");
}

From source file:org.eclipse.skalli.core.rest.admin.StatisticsQueryTest.java

private void assertToPeriodQuery(String period, int value, TimeUnit unit) {
    Calendar cal = Calendar.getInstance();
    long now = cal.getTimeInMillis();
    long toMillis = now - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
    cal.setTimeInMillis(toMillis);//from   w ww  .  j av  a  2s  . c  o m
    String toStr = DatatypeConverter.printDateTime(cal);
    StatisticsQuery query = new StatisticsQuery(getParams(null, toStr, period), now);
    Assert.assertEquals(toMillis - TimeUnit.MILLISECONDS.convert(value, unit), query.getFrom());
    Assert.assertEquals(toMillis, query.getTo());
}

From source file:util.AdjacencyList.java

/**
 * Returns a SteinerTree which is a 2-approximation of the minimum steiner
 * tree of the graph represented by this AdjacencyList. The resulting
 * SteinerTree is in fact a connected, directed sub graph which contains all
 * targets and nodes in the shortest path between the targets. The total
 * weight of all edges is approximately as low as possible.
 *
 * @param targets The targets that have to be in the resulting tree (graph)
 * @return The SteinerTree representing a graph in the form of to node
 * arrays. The graph is described via the edges from nodeI[n] to nodeJ[n].
 *//*  w  ww.j a v  a 2  s.c  o m*/
public AdjacencyList steinerTree(final int[] targets) {
    final boolean[] isTarget = new boolean[getNodeCount()];

    // Dijkstra from all Targets to all Nodes
    int edgeCount = targets.length * (targets.length - 1);
    final int[] nodeI = new int[edgeCount];
    final int[] nodeJ = new int[edgeCount];
    final float[] distances = new float[edgeCount];
    final Dijkstra[] dijkstras = new Dijkstra[targets.length];

    ExecutorService executor = Executors.newFixedThreadPool(targets.length);
    for (int i = 0; i < targets.length; i++) {
        final int target = i;
        isTarget[targets[target]] = true;
        executor.execute(() -> {
            dijkstras[target] = new Dijkstra(AdjacencyList.this, targets[target], isTarget, targets.length);
            int counter = target * (targets.length - 1);
            for (int j = 0; j < targets.length; j++) {
                if (j != target) {
                    nodeI[counter] = targets[target];
                    nodeJ[counter] = targets[j];
                    distances[counter] = dijkstras[target].getDistanceTo(targets[j]);
                    counter++;
                }
            }
        });
    }
    executor.shutdown();
    try {
        executor.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException ex) {
        Logger.getLogger(AdjacencyList.class.getName()).log(Level.SEVERE, null, ex);
    }

    // First Kruskal
    AdjacencyList td = kruskalMST(getNodeCount(), nodeI.length, nodeI, nodeJ, distances,
            INIT_PARTLY_COUNTING_SORT);

    // First Kruskal to shortest Paths
    List<Integer> nodeIList = new ArrayList<>();
    List<Integer> nodeJList = new ArrayList<>();
    List<Float> weightList = new ArrayList<>();
    for (int i = 0; i < targets.length; i++) {
        for (int j = td.getStartOf(targets[i]); j < td.getEndOf(targets[i]); j++) {
            int[] edgesPath = dijkstras[i].getEdgesOfShortestPathTo(td.getToNode(j));
            int fromNode = targets[i];
            for (int k = 0; k < edgesPath.length; k++) {
                int m = edgesPath[k];
                nodeIList.add(fromNode);
                nodeJList.add(getToNode(m));
                fromNode = getToNode(m);
                weightList.add(getWeight(m));
            }
        }
    }
    int[] nodeI2 = new int[nodeIList.size()];
    int[] nodeJ2 = new int[nodeI2.length];
    float[] weights = new float[nodeJ2.length];
    for (int i = 0; i < nodeI2.length; i++) {
        nodeI2[i] = nodeIList.get(i);
        nodeJ2[i] = nodeJList.get(i);
        weights[i] = weightList.get(i);
    }

    // Second Kruskal
    AdjacencyList t = kruskalMST(getNodeCount(), nodeI2.length, nodeI2, nodeJ2, weights,
            INIT_PARTLY_COUNTING_SORT);

    // Remove LEAVES 
    int newEdgeCount = t.getEdgeCount();
    boolean removed = true;
    while (removed) {
        removed = false;
        for (int i = 0; i < t.getEdgeCount(); i++) {
            int toNode = t.getToNode(i);
            if (toNode >= 0 && !isTarget[toNode]) {
                boolean isLeaf = true;
                for (int j = t.getStartOf(toNode); j < t.getEndOf(toNode) && isLeaf; j++) {
                    if (t.getToNode(j) >= 0) {
                        isLeaf = false;
                    }
                }
                if (isLeaf) {
                    t.setToNode(i, -1);
                    removed = true;
                    newEdgeCount--;
                }
            }
        }
    }

    nodeI2 = new int[newEdgeCount];
    nodeJ2 = new int[newEdgeCount];
    float[] weights2 = new float[newEdgeCount];
    float totalWeight = 0;
    int current = 0;
    for (int i = 0; i < t.getNodeCount(); i++) {
        for (int m = t.getStartOf(i); m < t.getEndOf(i); m++) {
            int j = t.getToNode(m);
            if (j >= 0) {
                nodeI2[current] = i;
                nodeJ2[current] = j;
                weights2[current] = t.getWeight(m);
                totalWeight += t.getWeight(m);
                current++;
            }
        }
    }

    return new AdjacencyList(getNodeCount(), weights2.length, nodeI2, nodeJ2, weights2);
}

From source file:org.zenoss.zep.impl.Application.java

private void startEventTimePurging() {
    final int duration = config.getEventTimePurgeIntervalDays();
    if (oldConfig != null && duration == oldConfig.getEventTimePurgeIntervalDays()) {
        logger.info("Event Times purging configuration not changed.");
        return;/*w w w .  ja va 2 s.  c om*/
    }
    cancelFuture(this.eventTimePurger);
    this.eventTimePurger = purge(eventTimeDao, duration, TimeUnit.DAYS, eventTimeDao.getPartitionIntervalInMs(),
            "ZEP_EVENT_TIME_PURGER");
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
 * configure domainAxis (label, timeZone, locale, tick labels)
 * of time-series chart/*from  w  w w . j a v a 2s .com*/
 * @param dateAxis
 */
private void configureDomainAxis(DateAxis dateAxis) {
    if (this.begin != null)
        dateAxis.setMinimumDate(this.begin);
    if (this.end != null)
        dateAxis.setMaximumDate(this.end);
    dateAxis.setTimeZone(this.timeZone);

    Date dateMin = dateAxis.getMinimumDate();
    Date dateMax = dateAxis.getMaximumDate();
    //DateFormat formatter = new SimpleDateFormat("d.MM.yyyy HH:mm:ss.SSS");;
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM, locale);
    String label = "Time: " + formatter.format(dateMin) + " .. " + formatter.format(dateMax);
    formatter = new SimpleDateFormat("z");
    label += " " + formatter.format(dateMax);
    dateAxis.setLabel(label);

    TimeInstant max = new TimeInstant(dateMax);
    TimeInstant min = new TimeInstant(dateMin);
    TimeSpan diff = TimeOperations.diff(max, min);

    if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.DAYS)))
        formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
    else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.HOURS)))
        formatter = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
    else if (TimeSpan.isLongerOrEqual(diff, new TimeSpan(1, TimeUnit.MINUTES)))
        formatter = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
    else
        formatter = new SimpleDateFormat("HH:mm:ss.SSS");
    dateAxis.setDateFormatOverride(formatter);
    dateAxis.setVerticalTickLabels(true);
}

From source file:org.wso2.carbon.cloud.gateway.transport.CGTransportSender.java

private static TimeUnit getTimeUnit(String timeUnit) {
    if (timeUnit.equals(CGConstant.MILLISECOND)) {
        return TimeUnit.MILLISECONDS;
    } else if (timeUnit.equals(CGConstant.SECOND)) {
        return TimeUnit.SECONDS;
    } else if (timeUnit.equals(CGConstant.MINUTE)) {
        return TimeUnit.MINUTES;
    } else if (timeUnit.equals(CGConstant.HOUR)) {
        return TimeUnit.HOURS;
    } else if (timeUnit.equals(CGConstant.DAY)) {
        return TimeUnit.DAYS;
    } else {//from   www .ja v a 2s. com
        // the default
        return TimeUnit.DAYS;
    }
}

From source file:de.mendelson.comm.as2.client.AS2Gui.java

/**
 * Creates new form NewJFrame//from  w  w w  .  j  a  v a2 s.  com
 */
public AS2Gui(Splash splash, String host) {
    this.host = host;
    //Set System default look and feel
    try {
        //support the command line option -Dswing.defaultlaf=...
        if (System.getProperty("swing.defaultlaf") == null) {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
    } catch (Exception e) {
        this.logger.warning(this.getClass().getName() + ":" + e.getMessage());
    }
    //load resource bundle
    try {
        this.rb = (MecResourceBundle) ResourceBundle.getBundle(ResourceBundleAS2Gui.class.getName());
    } catch (MissingResourceException e) {
        throw new RuntimeException("Oops..resource bundle " + e.getClassName() + " not found.");
    }
    initComponents();
    this.jButtonNewVersion.setVisible(false);
    this.jPanelRefreshWarning.setVisible(false);
    //set preference values to the GUI
    this.setBounds(this.clientPreferences.getInt(PreferencesAS2.FRAME_X),
            this.clientPreferences.getInt(PreferencesAS2.FRAME_Y),
            this.clientPreferences.getInt(PreferencesAS2.FRAME_WIDTH),
            this.clientPreferences.getInt(PreferencesAS2.FRAME_HEIGHT));
    //ensure to display all messages
    this.getLogger().setLevel(Level.ALL);
    LogConsolePanel consolePanel = new LogConsolePanel(this.getLogger());
    //define the colors for the log levels
    consolePanel.setColor(Level.SEVERE, LogConsolePanel.COLOR_BROWN);
    consolePanel.setColor(Level.WARNING, LogConsolePanel.COLOR_BLUE);
    consolePanel.setColor(Level.INFO, LogConsolePanel.COLOR_BLACK);
    consolePanel.setColor(Level.CONFIG, LogConsolePanel.COLOR_DARK_GREEN);
    consolePanel.setColor(Level.FINE, LogConsolePanel.COLOR_DARK_GREEN);
    consolePanel.setColor(Level.FINER, LogConsolePanel.COLOR_DARK_GREEN);
    consolePanel.setColor(Level.FINEST, LogConsolePanel.COLOR_DARK_GREEN);
    this.jPanelServerLog.add(consolePanel);
    this.setTitle(AS2ServerVersion.getProductName() + " " + AS2ServerVersion.getVersion());
    //initialize the help system if available
    this.initializeJavaHelp();
    this.jTableMessageOverview.getSelectionModel().addListSelectionListener(this);
    this.jTableMessageOverview.getTableHeader().setReorderingAllowed(false);
    //icon columns
    TableColumn column = this.jTableMessageOverview.getColumnModel().getColumn(0);
    column.setMaxWidth(20);
    column.setResizable(false);
    column = this.jTableMessageOverview.getColumnModel().getColumn(1);
    column.setMaxWidth(20);
    column.setResizable(false);
    this.jTableMessageOverview.setDefaultRenderer(Date.class,
            new TableCellRendererDate(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)));
    //add row sorter
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(this.jTableMessageOverview.getModel());
    jTableMessageOverview.setRowSorter(sorter);
    sorter.addRowSorterListener(this);
    this.jPanelFilterOverview.setVisible(this.showFilterPanel);
    this.jMenuItemHelpForum.setEnabled(Desktop.isDesktopSupported());
    //destroy splash, possible login screen for the client should come up
    if (splash != null) {
        splash.destroy();
    }
    this.setButtonState();
    this.jTableMessageOverview.addMouseListener(this);
    //popup menu issues
    this.jPopupMenu.setInvoker(this.jScrollPaneMessageOverview);
    this.jPopupMenu.addPopupMenuListener(this);
    super.addMessageProcessor(this);
    //perform the connection to the server
    //warning! this works for localhost only so far
    int clientServerCommPort = this.clientPreferences.getInt(PreferencesAS2.CLIENTSERVER_COMM_PORT);
    if (splash != null) {
        splash.destroy();
    }
    this.browserLinkedPanel.cyleText(new String[] {
            "For additional EDI software to convert and process your data please contact <a href='http://www.mendelson-e-c.com'>mendelson-e-commerce GmbH</a>",
            "To buy a commercial license please visit the <a href='http://shop.mendelson-e-c.com/'>mendelson online shop</a>",
            "Most trading partners demand a trusted certificate - Order yours at the <a href='http://ca.mendelson-e-c.com'>mendelson CA</a> now!",
            "Looking for additional secure data transmission software? Try the <a href='http://oftp2.mendelson-e-c.com'>mendelson OFTP2</a> solution!",
            "You want to send EDIFACT data from your SAP system? Ask <a href='mailto:info@mendelson.de?subject=Please%20inform%20me%20about%20your%20SAP%20integration%20solutions'>mendelson-e-commerce GmbH</a> for a solution.",
            "You need a secure FTP solution? <a href='mailto:info@mendelson.de?subject=Please%20inform%20me%20about%20your%20SFTP%20solution'>Ask us</a> for the mendelson SFTP software.",
            "Convert flat files, EDIFACT, SAP IDos, VDA, inhouse formats? <a href='mailto:info@mendelson.de?subject=Please%20inform%20me%20about%20your%20converter%20solution'>Ask us</a> for the mendelson EDI converter.",
            "For commercial support of this software please buy a license at <a href='http://as2.mendelson-e-c.com'>the mendelson AS2</a> website.",
            "Have a look at the <a href='http://www.mendelson-e-c.com/products_mbi.php'>mendelson business integration</a> for a powerful EDI solution.",
            "The <a href='mailto:info@mendelson.de?subject=Please%20inform%20me%20about%20your%20RosettaNet%20solution'>mendelson RosettaNet solution</a> supports RNIF 1.1 and RNIF 2.0.",
            "The <a href='http://www.mendelson-e-c.com/products_ide.php'>mendelson converter IDE</a> is the graphical mapper for the mendelson converter.",
            "To process any XML data and convert it to EDIFACT, VDA, flat files, IDocs and inhouse formats use <a href='http://www.mendelson-e-c.com/products_converter.php'>the mendelson converter</a>.",
            "To transmit your EDI data via HTTP/S please <a href='mailto:info@mendelson.de?subject=Please%20inform%20me%20about%20your%20HTTPS%20solution'>ask us</a> for the mendelson HTTPS solution.",
            "If you have questions regarding this product please refer to the <a href='http://community.mendelson-e-c.com/'>mendelson community</a>.", });
    this.connect(new InetSocketAddress(host, clientServerCommPort), 5000);
    Runnable dailyNewsThread = new Runnable() {

        @Override
        public void run() {
            while (true) {
                long lastUpdateCheck = Long.valueOf(clientPreferences.get(PreferencesAS2.LAST_UPDATE_CHECK));
                //check only once a day even if the system is started n times a day
                if (lastUpdateCheck < (System.currentTimeMillis() - TimeUnit.HOURS.toMillis(23))) {
                    clientPreferences.put(PreferencesAS2.LAST_UPDATE_CHECK,
                            String.valueOf(System.currentTimeMillis()));
                    jButtonNewVersion.setVisible(false);
                    String version = (AS2ServerVersion.getVersion() + " " + AS2ServerVersion.getBuild())
                            .replace(' ', '+');
                    Header[] header = htmlPanel.setURL(
                            "http://www.mendelson.de/en/mecas2/client_welcome.php?version=" + version,
                            AS2ServerVersion.getProductName() + " " + AS2ServerVersion.getVersion(),
                            new File("start/client_welcome.html"));
                    if (header != null) {
                        String downloadURL = null;
                        String actualBuild = null;
                        for (Header singleHeader : header) {
                            if (singleHeader.getName().equals("x-actual-build")) {
                                actualBuild = singleHeader.getValue().trim();
                            }
                            if (singleHeader.getName().equals("x-download-url")) {
                                downloadURL = singleHeader.getValue().trim();
                            }
                        }
                        if (downloadURL != null && actualBuild != null) {
                            try {
                                int thisBuild = AS2ServerVersion.getBuildNo();
                                int availableBuild = Integer.valueOf(actualBuild);
                                if (thisBuild < availableBuild) {
                                    jButtonNewVersion.setVisible(true);
                                }
                                downloadURLNewVersion = downloadURL;
                            } catch (Exception e) {
                                //nop
                            }
                        }
                    }
                } else {
                    htmlPanel.setPage(new File("start/client_welcome.html"));
                }
                try {
                    //check once a day for new update
                    Thread.sleep(TimeUnit.DAYS.toMillis(1));
                } catch (InterruptedException e) {
                    //nop
                }
            }
        }
    };
    Executors.newSingleThreadExecutor().submit(dailyNewsThread);
    this.as2StatusBar.setConnectedHost(this.host);
}

From source file:org.apps8os.motivator.ui.MoodHistoryActivity.java

/**
 * Load the page titles to an array. This done so the Title Pager Indicator does not have to construct
 * them multiple times when changing pages.
 *///ww w  .  java  2  s  .c  om
public void setPageTitles() {
    mDayPageTitles = new String[mNumberOfTodayInSprint];
    mLocale = mRes.getConfiguration().locale;
    mDateFormat = new SimpleDateFormat("dd.MM.yyyy", mLocale);
    Calendar date = (Calendar) mStartDate.clone();
    for (int i = 0; i < mDayPageTitles.length; i++) {
        mDayPageTitles[i] = mDateFormat.format(date.getTime());
        date.add(Calendar.DATE, 1);
    }

    mWeekPageTitles = new String[mNumberOfWeeksInSprint];
    int size = mWeekPageTitles.length;
    for (int i = 0; i < size; i++) {
        long dateInMillis = mSprintStartDateInMillis + (TimeUnit.MILLISECONDS.convert(i, TimeUnit.DAYS) * 7);
        date.setTimeInMillis(dateInMillis);
        date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        mWeekPageTitles[i] = mDateFormat.format(date.getTime());
        date.add(Calendar.DATE, 6);
        mWeekPageTitles[i] += " - " + mDateFormat.format(date.getTime());
    }
}

From source file:uk.ac.cam.eng.rule.retrieval.RuleRetriever.java

/**
 * @param args/*from w  w w .ja v  a  2s  . c  o m*/
 * @throws IOException
 * @throws FileNotFoundException
 * @throws InterruptedException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
public int run(String[] args) throws FileNotFoundException, IOException, InterruptedException,
        IllegalArgumentException, IllegalAccessException {
    RuleRetrieverParameters params = new RuleRetrieverParameters();
    JCommander cmd = new JCommander(params);

    try {
        cmd.parse(args);
        Configuration conf = getConf();
        Util.ApplyConf(cmd, FeatureCreator.MAPRED_SUFFIX, conf);
        RuleRetriever retriever = new RuleRetriever();
        retriever.loadDir(params.hfile, conf);
        retriever.setup(params.test_file, conf);
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        System.err.println("Generating query");
        List<Set<Text>> queries = retriever.generateQueries(params.test_file, conf);
        System.err.printf("Query took %d seconds to generate\n", stopWatch.getTime() / 1000);
        System.err.println("Executing queries");
        try (BufferedWriter out = new BufferedWriter(
                new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(params.rules))))) {
            FeatureCreator features = new FeatureCreator(conf);
            ExecutorService threadPool = Executors.newFixedThreadPool(conf.getInt(RETRIEVEL_THREADS, 1));

            for (int i = 0; i < queries.size(); ++i) {
                HFileRuleQuery query = new HFileRuleQuery(retriever.readers[i], retriever.bfs[i], out,
                        queries.get(i), features, retriever, conf);
                threadPool.execute(query);
            }
            threadPool.shutdown();
            threadPool.awaitTermination(1, TimeUnit.DAYS);
            // Add ascii constraints not already found in query
            for (RuleWritable asciiConstraint : retriever.asciiConstraints) {
                if (!retriever.foundAsciiConstraints.contains(asciiConstraint)) {
                    features.writeRule(asciiConstraint, AlignmentAndFeatureMap.EMPTY,
                            EnumRuleType.ASCII_OOV_DELETE, out);
                }
            }
            // Add Deletetion and OOV rules
            RuleWritable deletionRuleWritable = new RuleWritable();
            deletionRuleWritable.setLeftHandSide(new Text(EnumRuleType.ASCII_OOV_DELETE.getLhs()));
            deletionRuleWritable.setTarget(new Text("0"));
            RuleWritable oovRuleWritable = new RuleWritable();
            oovRuleWritable.setLeftHandSide(new Text(EnumRuleType.ASCII_OOV_DELETE.getLhs()));
            oovRuleWritable.setTarget(new Text(""));
            for (Text source : retriever.testVocab) {
                if (retriever.foundTestVocab.contains(source)) {
                    deletionRuleWritable.setSource(source);
                    features.writeRule(deletionRuleWritable, AlignmentAndFeatureMap.EMPTY,
                            EnumRuleType.ASCII_OOV_DELETE, out);
                } else {
                    oovRuleWritable.setSource(source);
                    features.writeRule(oovRuleWritable, AlignmentAndFeatureMap.EMPTY,
                            EnumRuleType.ASCII_OOV_DELETE, out);
                }
            }
            // Glue rules
            for (RuleWritable glueRule : retriever.getGlueRules()) {
                features.writeRule(glueRule, AlignmentAndFeatureMap.EMPTY, EnumRuleType.GLUE, out);
            }
        }
        System.out.println(retriever.foundAsciiConstraints);
        System.out.println(retriever.foundTestVocab);
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        cmd.usage();
    }

    return 1;
}