Example usage for java.util TimerTask TimerTask

List of usage examples for java.util TimerTask TimerTask

Introduction

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

Prototype

protected TimerTask() 

Source Link

Document

Creates a new timer task.

Usage

From source file:name.nirav.mp.service.analytics.EntityExtractionService.java

public EntityExtractionService(OpenCalaisConfig config, PredictionDB db) {
    this.config = config;
    this.calaisConfig = new CalaisConfig();
    this.calaisConfig.set(CalaisConfig.ConnParam.READ_TIMEOUT, config.readTimeout);
    this.calaisConfig.set(CalaisConfig.ConnParam.CONNECT_TIMEOUT, config.readTimeout);
    this.db = db;
    this.client = new CalaisRestClient(config.licenseKey);
    this.rateLimiter = RateLimiter.create(4);
    Timer timer = new Timer("Calais-ban-reset");
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            LocalDateTime now = LocalDateTime.now();
            if (now.getHour() >= 23) {
                LOG.info("It is close to midnight {}, resetting callCount", now.getHour());
                callCount = 0;//from   w w  w  .j  a va2 s .  c o  m
            }
        }
    }, 1000, TimeUnit.MINUTES.toMillis(30));
}

From source file:de.tor.tribes.util.ClipboardWatch.java

private synchronized void playNotification() {
    if (!Boolean.parseBoolean(GlobalOptions.getProperty("clipboard.notification"))) {
        return;/*from   w  w w  . ja v  a 2  s  . c o  m*/
    }

    Timer t = new Timer("ClipboardNotification", true);
    t.schedule(new TimerTask() {
        @Override
        public void run() {
            if (clip != null) {//reset clip
                clip.stop();
                clip.setMicrosecondPosition(0);
            }
            if (ac != null) {
                ac.stop();
            }

            try {
                if (org.apache.commons.lang.SystemUtils.IS_OS_WINDOWS) {
                    if (clip == null) {
                        clip = AudioSystem.getClip();
                        AudioInputStream inputStream = AudioSystem
                                .getAudioInputStream(ClockFrame.class.getResourceAsStream("/res/Ding.wav"));
                        clip.open(inputStream);
                    }
                    clip.start();
                } else {
                    if (ac == null) {
                        ac = Applet.newAudioClip(ClockFrame.class.getResource("/res/Ding.wav"));
                    }
                    ac.play();
                }
            } catch (Exception e) {
                logger.error("Failed to play notification", e);
            }
        }
    }, 0);
}

From source file:com.reddit.util.ApiUtil.java

/**
 * /*from w  w  w  .  jav  a2s. co m*/
 * @param delay - time in milliseconds to wait between requests
 */
public ApiUtil(long delay) {
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            delayedSufficiently = true;
        }

    }, new Date(), delay);
    start = System.currentTimeMillis();
}

From source file:org.bpmscript.js.reload.LibraryFileMonitor.java

/**
 * Kicks off the monitoring timer/*from   w  ww  . j  a v  a2s . c o  m*/
 */
public void afterPropertiesSet() throws Exception {
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            checkLibraries();
        }
    }, 1000, pollMillis);
}

From source file:samples.piggate.com.piggateCompleteExample.Service_Notify.java

@Override
public void onCreate() {
    super.onCreate();

    _piggate = new Piggate(this);

    timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override/*from   www  .ja  va  2s . c om*/
        public void run() {
            updateNotificationMsg(); //refresh the notification message
        }
    }, 0, 10000); //Time between calls

    _piggate.setListenerBeacon(new Piggate.PiggateBeaconCallback() { //Set the beacon listener

        //Handle if the device is not compatible
        @Override
        public void DeviceNotCompatible() {
            //Unused
        }

        //Handle if the bluetooth is not connected
        @Override
        public void BluetoothNotConnect() {
            //Unused
        }

        //Handle the pre - scanning of the beacons
        @Override
        public void PreScanning() {
            //Unused
        }

        //Handle the actions when the listener is ready
        @Override
        public void onReady() {
            //Unused
        }

        //Handle the beacon scanning errors
        @Override
        public void onErrorScanning() {
            //Unused
        }

        //Handle the actions where new beacons are discovered
        @Override
        public void GetNewBeacons(ArrayList<PiggateBeacon> beacons) {
            //Do a post notification to the notification bar when a beacon (an offer) is near with a custom message
            _piggate.postNotification(notificationtitle, notificationMsg, Activity_Main.class, R.drawable.logo);
            NotifyNewBeacons(); //Notify the activity about nearby beacons
        }

        //Handles the actions where beacons are detected
        @Override
        public void GetBeacons(ArrayList<PiggateBeacon> beacons) {
            //Unused
        }
    });
    _piggate.onStart(); //handles the onStart method of the Piggae object
}

From source file:samples.piggate.com.piggateInfoDemo.Service_Notify.java

@Override
public void onCreate() {
    super.onCreate();

    _piggate = new Piggate(this);

    timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override/*from  ww w .  j  a  v a 2  s . c  om*/
        public void run() {
            updateNotificationMsg(); //refresh the notification message
        }
    }, 0, 10000); //Time between calls

    _piggate.setListenerBeacon(new Piggate.PiggateBeaconCallback() { //Set the beacon listener

        //Handle if the device is not compatible
        @Override
        public void DeviceNotCompatible() {
            //Unused
        }

        //Handle if the bluetooth is not connected
        @Override
        public void BluetoothNotConnect() {
            //Unused
        }

        //Handle the pre - scanning of the beacons
        @Override
        public void PreScanning() {
            //Unused
        }

        //Handle the actions when the listener is ready
        @Override
        public void onReady() {
            //Unused
        }

        //Handle the beacon scanning errors
        @Override
        public void onErrorScanning() {
            //Unused
        }

        //Handle the actions where new beacons are discovered
        @Override
        public void GetNewBeacons(ArrayList<PiggateBeacon> beacons) {
            //Do a post notification to the notification bar when a beacon (an offer) is near with a custom message
            _piggate.postNotification(notificationtitle, notificationMsg, Activity_Main.class, R.drawable.logo);
            NotifyNewBeacons(); //Notify the activity about nearby beaconsd
        }

        //Handles the actions where beacons are detected
        @Override
        public void GetBeacons(ArrayList<PiggateBeacon> beacons) {
            //Unused
        }
    });
    _piggate.onStart(); //handles the onStart method of the Piggae object
}

From source file:RLCcircuit.RLCcircuitJFrame.java

public void VoltageInput(boolean StartOrStop) {
    if (!StartOrStop) {
        if (task != null) {
            task.cancel();// w  w w .j av  a2s . c  o  m
            task = null;
        }

        return;
    }

    if (timer == null)
        timer = new Timer();

    //        time = 0;
    task = new TimerTask() {
        public void run() {
            graphPanel.repaint();
            time = time + 1;
        }
    };
    timer.scheduleAtFixedRate(task, 0, 100);
}

From source file:com.smartitengineering.cms.spi.lock.impl.distributed.LocalLockRegistrarImpl.java

@Inject
public void initTimeoutChecking() {
    timer.schedule(new TimerTask() {

        @Override/*from  w ww  .ja  va  2  s.  c  om*/
        public void run() {
            lock.lock();
            List<Entry<Key, LockDetails>> removables = new ArrayList<Entry<Key, LockDetails>>();
            try {
                long currentTime = System.currentTimeMillis();

                final Set<Entry<Key, LockDetails>> entrySet = lockMap.entrySet();
                for (Entry<Key, LockDetails> entry : entrySet) {
                    if (currentTime >= entry.getValue().getTimeoutTime()) {
                        removables.add(
                                new SimpleEntry<Key, LockDetails>(entry.getKey(), lockMap.get(entry.getKey())));
                    }
                }
            } catch (Exception ex) {
                logger.warn(ex.getMessage(), ex);
            } finally {
                lock.unlock();
            }
            for (Entry<Key, LockDetails> removable : removables) {
                unlock(removable.getKey(), removable.getValue().getLockId());
                removable.getValue().getListener().lockTimedOut(removable.getKey());
            }
        }
    }, localLockTimeout, localLockTimeout);
}

From source file:me.tassoevan.cordova.ForegroundService.java

@Override
public void onCreate() {
    super.onCreate();

    final Handler handler = new Handler();

    startForeground(NOTIFICATION_ID, makeNotification());

    keepAliveTask = new TimerTask() {
        @Override//from  ww  w  .ja v a  2 s  .co m
        public void run() {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    Log.d(BackgroundPlugin.class.getName(), "" + new Date().getTime());
                }
            });
        }
    };

    scheduler.schedule(keepAliveTask, 0, 1000);
}

From source file:svc.managers.DemoManager.java

public List<DemoCitation> createCitationsAndViolations() {
    List<DemoCitation> demoCitations = new ArrayList<DemoCitation>();

    DemoUtilities demoUtilities = new DemoUtilities();
    List<Citation> citations = demoUtilities.generateRandomCitations();
    List<Violation> violations = demoUtilities.generateRandomViolations();

    mockCitationDataSource.insertCitations(citations);
    violationManager.insertViolations(violations);

    for (int citationCount = 0; citationCount < citations.size(); citationCount++) {
        Citation citation = citations.get(citationCount);
        int numberOfViolations = 0;
        for (int violationCount = 0; violationCount < violations.size(); violationCount++) {
            if (violations.get(violationCount).citation_number.equals(citation.citation_number)) {
                numberOfViolations++;//from  w  ww. j  a va  2  s. c o m
            }
        }
        DemoCitation demoCitation = new DemoCitation();
        demoCitation.citationNumber = citation.citation_number;
        demoCitation.dob = citation.date_of_birth;
        demoCitation.driversLicenseNumber = citation.drivers_license_number;
        Period daysTillCourt = DatabaseUtilities.getCurrentDate().until(citation.court_dateTime.toLocalDate());
        demoCitation.daysTillCourt = daysTillCourt.getDays();
        demoCitation.numberOfViolations = numberOfViolations;

        demoCitations.add(demoCitation);
    }

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            mockCitationDataSource.removeCitations(citations);
            violationManager.removeViolations(violations);
        }

    }, 60 * 60 * 1000);

    return demoCitations;
}