Example usage for java.util Timer schedule

List of usage examples for java.util Timer schedule

Introduction

In this page you can find the example usage for java.util Timer schedule.

Prototype

public void schedule(TimerTask task, Date firstTime, long period) 

Source Link

Document

Schedules the specified task for repeated fixed-delay execution, beginning at the specified time.

Usage

From source file:org.wso2.andes.kernel.slot.SlotDeletionScheduler.java

/**
 * Schedule a slot for deletion. This will continuously try to delete the slot
 * until slot manager informs that the slot is successfully removed
 *
 * @param slotToDelete slot to be removed from cluster
 * @param nodeID       Cluster unique ID of the node
 *//*from  w w w  .j a v a 2  s  .  co  m*/
public void scheduleSlotDeletion(Slot slotToDelete, String nodeID) {
    Timer timer = new Timer();
    SlotDeletionTimerTask timerTask = new SlotDeletionTimerTask(timer, slotToDelete, nodeID);
    timer.schedule(timerTask, 0, deleteRetryInterval);
}

From source file:org.wso2.carbon.apimgt.hybrid.gateway.usage.publisher.internal.APIUsagePublisherComponent.java

protected void activate(ComponentContext ctx) {

    //Scheduling a timer task for publishing uploaded on-premise gw's usage data if
    //usage data publishing is enabled thorough a property.
    try {//from  w w  w. j  a  va 2 s.c o  m
        ConfigManager configManager = ConfigManager.getConfigManager();
        String isUsageDataPublishingEnabled = configManager
                .getProperty(MicroGatewayAPIUsageConstants.IS_UPLOADED_USAGE_DATA_PUBLISH_ENABLED_PROPERTY);
        if (StringUtils.equals("true", isUsageDataPublishingEnabled)) {
            int usagePublishFrequency = MicroGatewayAPIUsageConstants.DEFAULT_UPLOADED_USAGE_PUBLISH_FREQUENCY;
            String usagePublishFrequencyProperty = configManager
                    .getProperty(MicroGatewayAPIUsageConstants.UPLOADED_USAGE_PUBLISH_FREQUENCY_PROPERTY);
            if (StringUtils.isNotBlank(usagePublishFrequencyProperty)) {
                try {
                    usagePublishFrequency = Integer.parseInt(usagePublishFrequencyProperty);
                } catch (NumberFormatException e) {
                    log.error(
                            "Error while parsing the system property: "
                                    + MicroGatewayAPIUsageConstants.UPLOADED_USAGE_PUBLISH_FREQUENCY_PROPERTY
                                    + " to integer. Using default usage publish frequency configuration: "
                                    + MicroGatewayAPIUsageConstants.DEFAULT_UPLOADED_USAGE_PUBLISH_FREQUENCY,
                            e);
                }
            }
            TimerTask usagePublisherTask = new UploadedUsagePublisherExecutorTask();
            Timer timer = new Timer();
            timer.schedule(usagePublisherTask, 0, usagePublishFrequency);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Micro GW API Usage data publishing is disabled.");
            }
        }
    } catch (OnPremiseGatewayException e) {
        log.error("Unexpected error occurred while reading properties from the config file. Micro GW API Usage "
                + "data publishing is disabled.", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Micro gateway API Usage Publisher bundle is activated.");
    }
}

From source file:org.sonar.server.benchmark.SourceIndexBenchmarkTest.java

private void benchmarkIndexing() {
    LOGGER.info("Indexing source lines");

    SourceIterator files = new SourceIterator(FILES, LINES_PER_FILE);
    ProgressTask progressTask = new ProgressTask(LOGGER, "files of " + LINES_PER_FILE + " lines",
            files.count());/*from  w ww. j a v  a  2 s .  com*/
    Timer timer = new Timer("SourceIndexer");
    timer.schedule(progressTask, ProgressTask.PERIOD_MS, ProgressTask.PERIOD_MS);

    long start = System.currentTimeMillis();
    tester.get(SourceLineIndexer.class).index(files);
    long end = System.currentTimeMillis();

    timer.cancel();
    long period = end - start;
    long nbLines = files.count.get() * LINES_PER_FILE;
    long throughputPerSecond = 1000L * nbLines / period;
    LOGGER.info(
            String.format("%d lines indexed in %d ms (%d docs/second)", nbLines, period, throughputPerSecond));
    benchmark.expectBetween("Throughput to index source lines", throughputPerSecond, 6000L, 6400L);

    // be sure that physical files do not evolve during estimation of size
    tester.get(EsClient.class).prepareOptimize(SourceLineIndexDefinition.INDEX).get();
    long dirSize = FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir());
    LOGGER.info(String.format("ES dir: " + FileUtils.byteCountToDisplaySize(dirSize)));
    benchmark.expectBetween("ES dir size (b)", dirSize, 103L * FileUtils.ONE_MB, 109L * FileUtils.ONE_MB);
}

From source file:com.tencent.mars.proxy.NetMsgHeaderHandler.java

public NetMsgHeaderHandler() {
    super();//from  www  . j ava  2  s .  com

    checker = new ContextTimeoutChecker();
    Timer timer = new Timer();
    timer.schedule(checker, 15 * 60 * 1000, 15 * 60 * 1000);
}

From source file:org.sipfoundry.sipxconfig.admin.CronSchedule.java

public Timer schedule(TimerTask task) {
    if (m_enabled) {
        Timer timer = new Timer();
        timer.schedule(task, getFirstDate(), getDelay());
        return timer;
    }/*  w  ww.j  a  v a 2s  .co m*/
    return null;
}

From source file:com.anritsu.mcrepositorymanager.utils.Packing.java

public Packing(ArrayList<McPackage> packageListToBePacked) {
    this.packageListToBePacked = packageListToBePacked;
    archiveNameFile = new File(REPOSITORY_LOCATION + ARCHIVE_NAME);
    try {//from   ww  w . ja v  a  2  s.  com
        out = new ZipOutputStream(new FileOutputStream(archiveNameFile));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Packing.class.getName()).log(Level.SEVERE, null, ex);
    }

    for (McPackage p : packageListToBePacked) {
        p.setPackageSize(getPackageSize(p));
    }

    // Update status.packageDownloadedSize
    Timer t = new Timer();
    t.schedule(new TimerTask() {
        @Override
        public void run() {

            try {
                String fileName = status.getProcessingPackage().getFileName();
                File f = new File(FOLDER_PATH + fileName);
                status.getProcessingPackage().setPackageDownloadedSize(f.length());
            } catch (Exception exp) {
                status.getProcessingPackage().setPackageDownloadedSize(0);
            }
        }
    }, 0, 1000);
}

From source file:co.mafiagame.telegraminterface.outputhandler.TelegramChannel.java

@PostConstruct
private void init() {
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    client = HttpClients.createDefault();
    this.url = telegramUrl + telegramToken + "/sendMessage";
    TimerTask timerTask = new TimerTask() {
        @Override//from ww  w . ja v a2  s  .c o m
        public void run() {
            SendMessage sendMessage = null;
            try {
                if (!outQueue.isEmpty()) {
                    sendMessage = outQueue.take();
                    deliverMessage(sendMessage);
                }
            } catch (InterruptedException e) {
                logger.error("error in reading outQueue", e);
            } catch (Exception e) {
                logger.error("error sending message " + sendMessage, e);
            }
        }
    };
    Timer timer = new Timer();
    timer.schedule(timerTask, TimeUnit.MINUTES.toMillis(1), TimeUnit.MILLISECONDS.toMillis(200));
}

From source file:edu.mayo.cts2.framework.plugin.service.lexevs.naming.DefaultCodingSchemeNameTranslator.java

protected void scheduleflushCache() {
    TimerTask flushTask = new TimerTask() {
        @Override//from   www  .j av  a 2  s  .c  o  m
        public void run() {
            buildCaches();
        }
    };

    Timer timer = new Timer();

    int minutesInMillis = FLUSH_PERIOD_MINUTES * 60 * 1000;
    timer.schedule(flushTask, 0, minutesInMillis);
}

From source file:nz.co.senanque.madura.bundle.BundleManagerImpl.java

@Override
public void init() {
    super.init();
    scanServletContext();/*from   w ww . ja  v a 2  s .com*/
    if (getTime() != -1) {
        // we have a timer so launch it now
        TimerTask t = new TimerTask() {

            @Override
            public void run() {
                scan();

            }
        };
        Timer timer = new Timer();
        timer.schedule(t, m_time, m_time);
    } else {
        scan();
    }
}

From source file:esg.node.components.metrics.ESGMetrics.java

private void startMetricsCollection() {
    log.trace("launching node metrics timer");
    long delay = Long.parseLong(props.getProperty("metrics.initialDelay"));
    long period = Long.parseLong(props.getProperty("metrics.period"));
    log.trace("metrics delay: " + delay + " sec");
    log.trace("metrics period: " + period + " sec");

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        public final void run() {
            //log.trace("Checking for new datanode information... [busy? "+ESGMetrics.this.isBusy+"]");
            if (!ESGMetrics.this.isBusy) {
                ESGMetrics.this.isBusy = true;
                if (fetchNodeStats()) {
                    metricsDAO.markLastCompletionTime();
                }/*  w  ww .j  av  a 2s.  c  o m*/
                ESGMetrics.this.isBusy = false;
            }
        }
    }, delay * 1000, period * 1000);
}