Search in sources :

Example 61 with TimerTask

use of java.util.TimerTask in project voltdb by VoltDB.

the class AdHocCompilerCache method startPeriodicStatsPrinting.

/**
     * Start a timer that prints cache stats to the console every 5s.
     * Used for development until we get better stats integration.
     */
public void startPeriodicStatsPrinting() {
    if (m_statsTimer == null) {
        m_statsTimer = new Timer();
        m_statsTimer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                printStats();
            }
        }, 5000, 5000);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 62 with TimerTask

use of java.util.TimerTask in project android_frameworks_base by ResurrectionRemix.

the class LocationBasedCountryDetector method detectCountry.

/**
     * Start detecting the country.
     * <p>
     * Queries the location from all location providers, then starts a thread to query the
     * country from GeoCoder.
     */
@Override
public synchronized Country detectCountry() {
    if (mLocationListeners != null) {
        throw new IllegalStateException();
    }
    // Request the location from all enabled providers.
    List<String> enabledProviders = getEnabledProviders();
    int totalProviders = enabledProviders.size();
    if (totalProviders > 0) {
        mLocationListeners = new ArrayList<LocationListener>(totalProviders);
        for (int i = 0; i < totalProviders; i++) {
            String provider = enabledProviders.get(i);
            if (isAcceptableProvider(provider)) {
                LocationListener listener = new LocationListener() {

                    @Override
                    public void onLocationChanged(Location location) {
                        if (location != null) {
                            LocationBasedCountryDetector.this.stop();
                            queryCountryCode(location);
                        }
                    }

                    @Override
                    public void onProviderDisabled(String provider) {
                    }

                    @Override
                    public void onProviderEnabled(String provider) {
                    }

                    @Override
                    public void onStatusChanged(String provider, int status, Bundle extras) {
                    }
                };
                mLocationListeners.add(listener);
                registerListener(provider, listener);
            }
        }
        mTimer = new Timer();
        mTimer.schedule(new TimerTask() {

            @Override
            public void run() {
                mTimer = null;
                LocationBasedCountryDetector.this.stop();
                // Looks like no provider could provide the location, let's try the last
                // known location.
                queryCountryCode(getLastKnownLocation());
            }
        }, getQueryLocationTimeout());
    } else {
        // There is no provider enabled.
        queryCountryCode(getLastKnownLocation());
    }
    return mDetectedCountry;
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Location(android.location.Location)

Example 63 with TimerTask

use of java.util.TimerTask in project KaiZen-OpenAPI-Editor by RepreZen.

the class QuickOutline method createTitleControl.

@Override
protected Control createTitleControl(Composite parent) {
    filterText = new Text(parent, SWT.NONE);
    Dialog.applyDialogFont(filterText);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.CENTER;
    filterText.setLayoutData(data);
    filterText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (isInvocationEvent(e)) {
                e.doit = false;
                handleMultiView();
            } else if (e.keyCode == SWT.CR) {
                handleSelection();
                QuickOutline.this.close();
            } else if (e.keyCode == SWT.ARROW_DOWN) {
                treeViewer.getTree().setFocus();
            } else if (e.keyCode == SWT.ARROW_UP) {
                treeViewer.getTree().setFocus();
            } else if (e.character == SWT.ESC) {
                QuickOutline.this.close();
            }
        }

        public void keyReleased(KeyEvent e) {
        // do nothing
        }
    });
    filterText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            if (filterTimer != null) {
                filterTimer.cancel();
            }
            // reset the timer each time there is a
            // text modification, so that only the last
            // one will be executed.
            filterTimer = new Timer();
            filterTimer.schedule(new TimerTask() {

                @Override
                public void run() {
                    if (filterText.isDisposed()) {
                        return;
                    }
                    // Make sure we access the text in the correct thread.
                    filterText.getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            // refreshing the tree will execute the filter.
                            if (Strings.emptyToNull(filterText.getText()) == null) {
                                treeViewer.refresh();
                                treeViewer.collapseAll();
                            } else {
                                treeViewer.refresh();
                                TreeItem[] items = treeViewer.getTree().getItems();
                                if (items != null && items.length > 0) {
                                    treeViewer.getTree().setSelection(items[0]);
                                    treeViewer.getTree().showItem(items[0]);
                                } else {
                                    treeViewer.setSelection(StructuredSelection.EMPTY);
                                }
                                treeViewer.expandAll();
                            }
                        }
                    });
                }
            }, 500);
        }
    });
    return filterText;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) Timer(java.util.Timer) TimerTask(java.util.TimerTask) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) KeyListener(org.eclipse.swt.events.KeyListener)

Example 64 with TimerTask

use of java.util.TimerTask in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WpsDialog method onStart.

@Override
protected void onStart() {
    /*
         * increment timeout bar per second.
         */
    mTimer = new Timer(false);
    mTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    mTimeoutBar.incrementProgressBy(1);
                }
            });
        }
    }, 1000, 1000);
    mContext.registerReceiver(mReceiver, mFilter);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 65 with TimerTask

use of java.util.TimerTask in project ACS by ACS-Community.

the class ManagerImpl method initialize.

/**
	 * Initializes Manager.
	 * @param	prevayler			implementation of prevayler system
	 * @param	context				remote directory implementation
	 */
public void initialize(Prevayler prevayler, CDBAccess cdbAccess, Context context, final Logger logger, ManagerContainerServices managerContainerServices) {
    this.prevayler = prevayler;
    this.remoteDirectory = context;
    this.logger = logger;
    // needs to be done here, since deserialization is used
    initializeDefaultConfiguration();
    if (cdbAccess != null)
        setCDBAccess(cdbAccess);
    readManagerConfiguration();
    componentsLock = (ProfilingReentrantLock.isProfilingEnabled ? new ProfilingReentrantLock("componentsLock") : new ReentrantLock());
    random = new Random();
    heartbeatTask = new Timer(true);
    delayedDeactivationTask = new Timer(true);
    containerLoggedInMonitor = new Object();
    activationSynchronization = new HashMap<String, ReferenceCountingLock>();
    activationPendingRWLock = new ReaderPreferenceReadWriteLock();
    shutdown = new AtomicBoolean(false);
    threadPool = new ThreadPoolExecutor(poolThreads, poolThreads, Long.MAX_VALUE, TimeUnit.NANOSECONDS, new LinkedBlockingQueue(), new DaemonThreadFactory("managerThreadPool"));
    managerCache = new HashMap<String, Manager>();
    pendingActivations = new HashMap<String, ComponentInfo>();
    pendingContainerShutdown = Collections.synchronizedSet(new HashSet<String>());
    pendingContainerAsyncRequests = new HashMap<String, Deque<ComponentInfoCompletionCallback>>();
    clientMessageQueue = new HashMap<Client, LinkedList<ClientMessageTask>>();
    groupedNotifyTaskMap = new HashMap<Object, GroupedNotifyTask>();
    threadsUsedPercentage = new AtomicInteger(0);
    // create threads
    threadPool.prestartAllCoreThreads();
    // read CDB startup
    try {
        String componentSpec = System.getProperty(NAME_CDB_COMPONENTSPEC);
        if (componentSpec != null) {
            cdbActivation = new ComponentSpec(componentSpec);
            logger.log(Level.INFO, "Using CDB component specification: '" + cdbActivation + "'.");
        }
    } catch (Throwable t) {
        logger.log(Level.WARNING, "Failed to parse '" + NAME_CDB_COMPONENTSPEC + "' variable, " + t.getMessage(), t);
    }
    // check load balancing strategy
    checkLoadBalancingStrategy();
    // establish connect to the alarm system
    try {
        alarmSource = new AlarmSourceImpl(managerContainerServices);
        alarmSource.start();
    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Failed to initialize Alarm System Interface " + ex.getMessage(), ex);
        alarmSource = null;
    }
    // register ping tasks
    initializePingTasks();
    // handle monitoring removal task
    final long timeInMs = enableHandleMonitoringDurationMins * 60L * 1000;
    if (enableHandleMonitoring && enableHandleMonitoringDurationMins > 0) {
        heartbeatTask.schedule(new TimerTask() {

            @Override
            public void run() {
                try {
                    logHandleCleanup(timeInMs);
                } catch (Throwable th) {
                    logger.log(Level.SEVERE, "Unexpected exception in handle log cleanup task.", th);
                }
            }
        }, 0, timeInMs);
    }
    // start topology sort manager
    topologySortManager = new ComponentInfoTopologicalSortManager(components, containers, activationPendingRWLock, pendingContainerShutdown, threadPool, logger);
    if (prevayler == null)
        statePersitenceFlag.set(false);
    String enDis = statePersitenceFlag.get() ? "enabled" : "disabled";
    logger.info("Manager initialized with state persistence " + enDis + ".");
}
Also used : DaemonThreadFactory(alma.acs.concurrent.DaemonThreadFactory) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Manager(com.cosylab.acs.maci.Manager) Random(java.util.Random) TimerTask(java.util.TimerTask) AlarmSourceImpl(alma.acs.alarmsystem.source.AlarmSourceImpl) Client(com.cosylab.acs.maci.Client) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque) LinkedList(java.util.LinkedList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timer(java.util.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Aggregations

TimerTask (java.util.TimerTask)900 Timer (java.util.Timer)653 IOException (java.io.IOException)90 Date (java.util.Date)58 Test (org.junit.Test)57 File (java.io.File)30 ArrayList (java.util.ArrayList)29 Intent (android.content.Intent)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)21 Handler (android.os.Handler)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 HashMap (java.util.HashMap)17 List (java.util.List)14 TextView (android.widget.TextView)13 CountDownLatch (java.util.concurrent.CountDownLatch)13 View (android.view.View)12 Map (java.util.Map)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 InputMethodManager (android.view.inputmethod.InputMethodManager)11 Random (java.util.Random)11