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);
}
}
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;
}
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;
}
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);
}
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 + ".");
}
Aggregations