Example usage for java.util Timer purge

List of usage examples for java.util Timer purge

Introduction

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

Prototype

public int purge() 

Source Link

Document

Removes all cancelled tasks from this timer's task queue.

Usage

From source file:hudson.plugins.blazemeter.PerformanceBuilder.java

@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
        @Nonnull TaskListener listener) throws InterruptedException, IOException {

    if (!validateTestId(listener)) {
        run.setResult(Result.FAILURE);
        return;//from w ww .ja v a  2 s.  c o  m
    }

    BlazemeterCredentialsBAImpl credentials = Utils.findCredentials(credentialsId, CredentialsScope.GLOBAL);
    boolean isValidCredentials = !StringUtils.isBlank(credentialsId) && validateCredentials(credentials);
    if (!isValidCredentials) {
        listener.error(BzmJobNotifier.formatMessage("Can not start build: Invalid credentials=" + credentialsId
                + "... is deprecated or absent in credentials store."));
        run.setResult(Result.NOT_BUILT);
        return;
    }

    String serverUrlConfig = BlazeMeterPerformanceBuilderDescriptor.getDescriptor().getBlazeMeterURL();
    String jobName = run.getFullDisplayName();
    VirtualChannel channel = launcher.getChannel();

    final long reportLinkId = System.currentTimeMillis();
    EnvVars envVars = run.getEnvironment(listener);

    BzmBuild bzmBuild = new BzmBuild(this, credentials.getUsername(), credentials.getPassword().getPlainText(),
            jobName, run.getId(),
            StringUtils.isBlank(serverUrlConfig) ? Constants.A_BLAZEMETER_COM : serverUrlConfig, envVars,
            workspace, listener, ProxyConfiguration.load(), !(channel instanceof LocalChannel),
            envVars.expand(reportLinkName), reportLinkId);

    ReportUrlTask reportUrlTask = new ReportUrlTask(run, jobName, channel, reportLinkId);

    Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(reportUrlTask, 20 * 1000, 10 * 1000);
    try {
        Result result = channel.call(bzmBuild);
        run.setResult(result);
    } catch (InterruptedException e) {
        LOGGER.warning("Build has been aborted");
        // start new task for wait Slave
        InterruptListenerTask interrupt = new InterruptListenerTask(run, jobName, channel);
        interrupt.start();
        interrupt.join();
        run.setResult(Result.ABORTED);
    } catch (Exception e) {
        listener.getLogger().println(BzmJobNotifier.formatMessage("Failure with exception: " + e.getMessage()));
        e.printStackTrace(listener.getLogger());
        run.setResult(Result.FAILURE);
    } finally {
        reportUrlTask.cancel();
        timer.cancel();
        timer.purge();
    }
}

From source file:org.broad.igv.batch.CommandExecutorTest.java

@Test
public void testSortByRegionScoreType() throws Exception {
    Timer deadlockChecker = TestUtils.startDeadlockChecker(1000);
    String sessionPath = TestUtils.DATA_DIR + "sessions/metabric_expression.xml";
    TestUtils.loadSession(igv, sessionPath);

    Collection<RegionOfInterest> rois = igv.getSession().getAllRegionsOfInterest();

    List<Track> tracks;
    int count = 0;
    for (RegionOfInterest roi : rois) {
        for (RegionScoreType type : RegionScoreType.values()) {
            igv.sortAllTracksByAttributes(new String[] { "NAME" }, new boolean[] { false });
            String typeStr = type.toString().toUpperCase();
            if (count % 2 == 0) {
                typeStr = typeStr.toLowerCase();
            }//w  w w .  j  a  v a 2  s .  c om
            String resp = exec.execute("sort " + typeStr + " " + roi.getLocusString());
            assertEquals("OK", resp);

            tracks = igv.getAllTracks();
            ReferenceFrame frame = FrameManager.getDefaultFrame();
            IGVTestHeadless.checkIsSorted(tracks, roi, type, frame.getZoom(), frame);
            count++;
        }
    }
    deadlockChecker.cancel();
    deadlockChecker.purge();
}

From source file:coffeshop.PaymentPage.java

private void btcTimer() {
    Timer timer = new Timer(); //new timer
    timeExpired = false;/* w  w  w  .  j a v  a 2 s. c  o  m*/
    TimerTask task = new TimerTask() {
        int counter = 10;

        public void run() {
            int minutes = 0;
            int seconds = 0;
            minutes = counter / 60;
            seconds = counter % 60;
            if (timeStop) {
                timer.cancel();
                timer.purge();
            } else {
                String timeString = String.format("Time Left: %02d:%02d", minutes, seconds);
                lblTimer.setText(timeString);
                counter--;
                if (counter == -1) {
                    timer.cancel();
                    timer.purge();
                    lblTimer.setText("Time Expired");
                    timeExpired = true;
                    lblQRC.setIcon(defaultQR);
                }
            }

        }
    };
    timer.scheduleAtFixedRate(task, 1000, 1000);
}

From source file:net.ustyugov.jtalk.service.JTalkService.java

public void disconnect(String account) {
    if (!started)
        return;/*from w ww .  j a  v  a 2  s .  co  m*/
    Log.e("Disconnect", account);
    if (connections.containsKey(account)) {
        if (connectionTasks.containsKey(account)) {
            connectionTasks.remove(account).cancel(true);
        }

        if (pingTimers.containsKey(account)) {
            Timer timer = pingTimers.remove(account);
            timer.cancel();
            timer.purge();
        }

        try {
            removeConnectionListener(account);
            Presence presence = new Presence(Presence.Type.unavailable, "", 0, null);
            XMPPConnection connection = connections.remove(account);
            connection.disconnect(presence);
        } catch (Exception ignored) {
        }

        try {
            if (sipManagers.containsKey(account)) {
                SipManager manager = sipManagers.get(account);
                manager.close("sip:" + account);
            }
        } catch (Exception ignored) {
        }
        setState(account, getString(R.string.Disconnect));
    }
    sendBroadcast(new Intent(Constants.UPDATE));
}

From source file:net.ustyugov.jtalk.service.JTalkService.java

public void disconnect() {
    if (!started)
        return;//from  w w  w.  j  av  a 2s . c o m
    if (wifiLock != null && wifiLock.isHeld())
        wifiLock.release();
    if (wakeLock != null && wakeLock.isHeld())
        wakeLock.release();
    Collection<XMPPConnection> con = getAllConnections();
    for (XMPPConnection connection : con) {
        String account = StringUtils.parseBareAddress(connection.getUser());
        if (isAuthenticated(account)) {
            if (connectionTasks.containsKey(account)) {
                connectionTasks.remove(account).cancel(true);
            }
            if (pingTimers.containsKey(account)) {
                Timer timer = pingTimers.remove(account);
                timer.cancel();
                timer.purge();
            }
            removeConnectionListener(account);
            Presence presence = new Presence(Presence.Type.unavailable, "", 0, null);
            connection.disconnect(presence);

            try {
                if (sipManagers.containsKey(account)) {
                    SipManager manager = sipManagers.get(account);
                    manager.close("sip:" + account);
                }
            } catch (Exception ignored) {
            }
        } else if (connection.isConnected())
            connection.disconnect();
        setState(account, getString(R.string.Disconnect));
        connections.remove(account);
    }
}