Search in sources :

Example 6 with TimerTask

use of java.util.TimerTask in project hadoop by apache.

the class RollingFileSystemSink method scheduleFlush.

/**
   * Schedule the current interval's directory to be flushed. If this ends up
   * running after the top of the next interval, it will execute immediately.
   *
   * @param when the time the thread should run
   */
private void scheduleFlush(Date when) {
    // Store the current currentDirPath to close later
    final PrintStream toClose = currentOutStream;
    flushTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            synchronized (lock) {
                // This close may have already been done by a putMetrics() call. If it
                // has, the PrintStream will swallow the exception, which is fine.
                toClose.close();
            }
            hasFlushed = true;
        }
    }, when);
}
Also used : PrintStream(java.io.PrintStream) TimerTask(java.util.TimerTask)

Example 7 with TimerTask

use of java.util.TimerTask in project hadoop by apache.

the class TestNodeHealthScriptRunner method testNodeHealthScript.

@Test
public void testNodeHealthScript() throws Exception {
    String errorScript = "echo ERROR\n echo \"Tracker not healthy\"";
    String normalScript = "echo \"I am all fine\"";
    String timeOutScript = Shell.WINDOWS ? "@echo off\nping -n 4 127.0.0.1 >nul\necho \"I am fine\"" : "sleep 4\necho \"I am fine\"";
    Configuration conf = new Configuration();
    writeNodeHealthScriptFile(normalScript, true);
    NodeHealthScriptRunner nodeHealthScriptRunner = new NodeHealthScriptRunner(nodeHealthscriptFile.getAbsolutePath(), 500, 1000, new String[] {});
    nodeHealthScriptRunner.init(conf);
    TimerTask timerTask = nodeHealthScriptRunner.getTimerTask();
    timerTask.run();
    // Normal Script runs successfully
    Assert.assertTrue("Node health status reported unhealthy", nodeHealthScriptRunner.isHealthy());
    Assert.assertEquals("", nodeHealthScriptRunner.getHealthReport());
    // Error script.
    writeNodeHealthScriptFile(errorScript, true);
    // Run timer
    timerTask.run();
    Assert.assertFalse("Node health status reported healthy", nodeHealthScriptRunner.isHealthy());
    Assert.assertTrue(nodeHealthScriptRunner.getHealthReport().contains("ERROR"));
    // Healthy script.
    writeNodeHealthScriptFile(normalScript, true);
    timerTask.run();
    Assert.assertTrue("Node health status reported unhealthy", nodeHealthScriptRunner.isHealthy());
    Assert.assertEquals("", nodeHealthScriptRunner.getHealthReport());
    // Timeout script.
    writeNodeHealthScriptFile(timeOutScript, true);
    timerTask.run();
    Assert.assertFalse("Node health status reported healthy even after timeout", nodeHealthScriptRunner.isHealthy());
    Assert.assertEquals(NodeHealthScriptRunner.NODE_HEALTH_SCRIPT_TIMED_OUT_MSG, nodeHealthScriptRunner.getHealthReport());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TimerTask(java.util.TimerTask) Test(org.junit.Test)

Example 8 with TimerTask

use of java.util.TimerTask in project hadoop by apache.

the class ActiveStandbyElectorBasedElectorService method enterNeutralMode.

/**
   * When the ZK client loses contact with ZK, this method will be called to
   * allow the RM to react. Because the loss of connection can be noticed
   * before the session timeout happens, it is undesirable to transition
   * immediately. Instead the method starts a timer that will wait
   * {@link YarnConfiguration#RM_ZK_TIMEOUT_MS} milliseconds before
   * initiating the transition into standby state.
   */
@Override
public void enterNeutralMode() {
    LOG.warn("Lost contact with Zookeeper. Transitioning to standby in " + zkSessionTimeout + " ms if connection is not reestablished.");
    // we'll transition to standby.
    synchronized (zkDisconnectLock) {
        if (zkDisconnectTimer == null) {
            zkDisconnectTimer = new Timer("Zookeeper disconnect timer");
            zkDisconnectTimer.schedule(new TimerTask() {

                @Override
                public void run() {
                    synchronized (zkDisconnectLock) {
                        // Only run if the timer hasn't been cancelled
                        if (zkDisconnectTimer != null) {
                            becomeStandby();
                        }
                    }
                }
            }, zkSessionTimeout);
        }
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 9 with TimerTask

use of java.util.TimerTask in project hadoop by apache.

the class NodesListManager method serviceInit.

@Override
protected void serviceInit(Configuration conf) throws Exception {
    this.conf = conf;
    int nodeIpCacheTimeout = conf.getInt(YarnConfiguration.RM_NODE_IP_CACHE_EXPIRY_INTERVAL_SECS, YarnConfiguration.DEFAULT_RM_NODE_IP_CACHE_EXPIRY_INTERVAL_SECS);
    if (nodeIpCacheTimeout <= 0) {
        resolver = new DirectResolver();
    } else {
        resolver = new CachedResolver(SystemClock.getInstance(), nodeIpCacheTimeout);
        addIfService(resolver);
    }
    // Read the hosts/exclude files to restrict access to the RM
    try {
        this.includesFile = conf.get(YarnConfiguration.RM_NODES_INCLUDE_FILE_PATH, YarnConfiguration.DEFAULT_RM_NODES_INCLUDE_FILE_PATH);
        this.excludesFile = conf.get(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, YarnConfiguration.DEFAULT_RM_NODES_EXCLUDE_FILE_PATH);
        this.hostsReader = createHostsFileReader(this.includesFile, this.excludesFile);
        setDecomissionedNMs();
        printConfiguredHosts();
    } catch (YarnException ex) {
        disableHostsFileReader(ex);
    } catch (IOException ioe) {
        disableHostsFileReader(ioe);
    }
    final int nodeRemovalTimeout = conf.getInt(YarnConfiguration.RM_NODEMANAGER_UNTRACKED_REMOVAL_TIMEOUT_MSEC, YarnConfiguration.DEFAULT_RM_NODEMANAGER_UNTRACKED_REMOVAL_TIMEOUT_MSEC);
    nodeRemovalCheckInterval = (Math.min(nodeRemovalTimeout / 2, 600000));
    removalTimer = new Timer("Node Removal Timer");
    removalTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            long now = Time.monotonicNow();
            for (Map.Entry<NodeId, RMNode> entry : rmContext.getInactiveRMNodes().entrySet()) {
                NodeId nodeId = entry.getKey();
                RMNode rmNode = entry.getValue();
                if (isUntrackedNode(rmNode.getHostName())) {
                    if (rmNode.getUntrackedTimeStamp() == 0) {
                        rmNode.setUntrackedTimeStamp(now);
                    } else if (now - rmNode.getUntrackedTimeStamp() > nodeRemovalTimeout) {
                        RMNode result = rmContext.getInactiveRMNodes().remove(nodeId);
                        if (result != null) {
                            decrInactiveNMMetrics(rmNode);
                            LOG.info("Removed " + result.getState().toString() + " node " + result.getHostName() + " from inactive nodes list");
                        }
                    }
                } else {
                    rmNode.setUntrackedTimeStamp(0);
                }
            }
        }
    }, nodeRemovalCheckInterval, nodeRemovalCheckInterval);
    super.serviceInit(conf);
}
Also used : Entry(java.util.Map.Entry) RMNode(org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode) Timer(java.util.Timer) TimerTask(java.util.TimerTask) NodeId(org.apache.hadoop.yarn.api.records.NodeId) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 10 with TimerTask

use of java.util.TimerTask in project hadoop by apache.

the class ContainerMetrics method scheduleTimerTaskIfRequired.

private synchronized void scheduleTimerTaskIfRequired() {
    if (flushPeriodMs > 0) {
        // Lazily initialize timer
        if (timer == null) {
            this.timer = new Timer("Metrics flush checker", true);
        }
        TimerTask timerTask = new TimerTask() {

            @Override
            public void run() {
                synchronized (ContainerMetrics.this) {
                    if (!finished) {
                        flushOnPeriod = true;
                    }
                }
            }
        };
        timer.schedule(timerTask, flushPeriodMs);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Aggregations

TimerTask (java.util.TimerTask)359 Timer (java.util.Timer)260 IOException (java.io.IOException)25 Date (java.util.Date)21 Test (org.junit.Test)20 File (java.io.File)13 ArrayList (java.util.ArrayList)11 Intent (android.content.Intent)8 Bundle (android.os.Bundle)8 InputMethodManager (android.view.inputmethod.InputMethodManager)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Location (android.location.Location)6 LocationListener (android.location.LocationListener)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 TextView (android.widget.TextView)5 URI (java.net.URI)5 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5