List of usage examples for java.util Timer Timer
public Timer()
From source file:edu.unc.lib.dl.cdr.services.BatchIngestService.java
public void init() { initializeExecutor();/*w w w . j av a 2 s. c om*/ if (!isStartOnInit()) { this.executor.pause(); } // add a file system monitor to queue new ingests pollingTimer = new Timer(); pollingTimer.schedule(new EnqueueTask(), pollDirectorySeconds * 1000, pollDirectorySeconds * 1000); pollingTimer.schedule(new SweepFinishedTask(), 60 * 1000, sweepFinishedSeconds * 1000); }
From source file:cl.tide.fm.sensonet.SensonetClient.java
public void start(List<SensorView> s) { long interval = SettingsController.getInterval(); interval = interval < 10000 ? 10000 : interval; System.err.println("interval update " + interval); stop = false;//from w ww . j av a 2 s . co m timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { if (!isLogged) login(SettingsController.getSensonetUser(), SettingsController.getSensonetPassword()); System.out.println("\n Sensonet Status " + isOnline + " " + !stop + " " + isLogged); if (isOnline && !stop) { if (myDatasource == null) { findOrCreateDataSource("Senso"); if (variables.isEmpty()) findOrCreateVariables(s); } if (variables.size() > 0) { variables.forEach((va) -> { try { BasicNameValuePair param = new BasicNameValuePair("value", va.sensor.getValue() + ""); List<NameValuePair> params = new ArrayList<>(); params.add(param); HttpPost post = new HttpPost( baseUrl + "project/datasource/variable/value/" + va.id); post.setEntity(new UrlEncodedFormEntity(params)); CloseableHttpResponse result = client.execute(post); int statusCode = result.getStatusLine().getStatusCode(); if (statusCode == 200) { System.out.println(va.name + " enviado correctamente "); } else { System.err.println(statusCode + " Ocurrio un error al enviar " + va.name); } result.close(); } catch (IOException ex) { Logger.getLogger(SensonetClient.class.getName()).log(Level.SEVERE, null, ex); } }); } else { //almacenar los datos y envialos luego? System.err.println("No hay variables"); findOrCreateVariables(s); } } else { System.err.println("sensonet is offline"); } } }, 0, interval); }
From source file:edu.illinois.whereru.MainPageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_page); intent = new Intent(this, MainTabFragmentActivity.class); userInfo = getSharedPreferences(PREFERENCE_NAME, 0); boolean firstStart = userInfo.getBoolean(PREF_APPLICATION_STATE, true); // If it is the first time starting this application, load up registration dialog if (firstStart) showRegistrationDialog();//from w w w .j a v a 2 s . c o m else { // Give sometime to brag about the main page. Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { // start main tab fragment activity startActivity(intent); // terminate the main page // without this, back button would start this activity again. finish(); } }, 2000); // build friend info from DB FriendBuilder.build(getApplicationContext()); } }
From source file:nz.co.senanque.madura.bundle.BundleManagerImpl.java
@Override public void init() { super.init(); scanServletContext();/*from w w w.j ava2s . co m*/ if (getTime() != -1) { // we have a timer so launch it now TimerTask t = new TimerTask() { @Override public void run() { scan(); } }; Timer timer = new Timer(); timer.schedule(t, m_time, m_time); } else { scan(); } }
From source file:com.edmunds.etm.agent.impl.TcpHealthCheck.java
@Override public void execute(HealthCheckListener listener) { // Ensure that the listener is set Validate.notNull(listener, "Health check listener is null"); healthCheckListener = listener;/*from w w w . ja va 2 s .c o m*/ // Initialize time values elapsedTime = 0; lastCheckTime = new Date().getTime(); // Schedule the initial health check Timer timer = new Timer(); timer.scheduleAtFixedRate(new HealthCheckTask(timer), interval, interval); if (logger.isInfoEnabled()) { InetAddress addr = getHostAddress(); String message = String.format("Health check started for host %s on port %d", addr.getHostAddress(), port); logger.info(message); } }
From source file:com.reversemind.hypergate.server.HyperGateServerAdvertiser.java
/** * @param builder/*from ww w . j a v a 2 s . c o m*/ */ public HyperGateServerAdvertiser(ServerFactory.Builder builder) { super(builder); if (StringUtils.isEmpty(builder.getZookeeperHosts())) { throw new RuntimeException("Need zookeeper connection string"); } this.zookeeperHosts = builder.getZookeeperHosts(); if (StringUtils.isEmpty(builder.getServiceBasePath())) { throw new RuntimeException("Need zookeeper base path string"); } this.serviceBasePath = builder.getServiceBasePath(); this.metadata = new ServerMetadata(this.getName(), this.getInstanceName(), this.getHost(), this.getPort(), this.metrics); this.useMetrics = builder.isUseMetrics(); if (builder.isUseMetrics()) { this.periodPublishMetrics = builder.getPeriodPublishMetrics(); LOG.debug("builder.getPeriodPublishMetrics() == " + builder.getPeriodPublishMetrics()); if (builder.getPeriodPublishMetrics() < 0) { this.periodPublishMetrics = 1000; //ms } LOG.debug("this.periodPublishMetrics == " + this.periodPublishMetrics); this.metricsUpdateTask = new MetricsUpdateTask(); this.timer = new Timer(); this.timer.schedule(this.metricsUpdateTask, this.periodPublishMetrics, this.periodPublishMetrics); } }
From source file:com.firma.dev.letschat.MyFavoriteFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View listFragmentView = super.onCreateView(inflater, container, savedInstanceState); apiManager = new ApiManager(); ProfileDataSource profileDao = new ProfileDataSource(inflater.getContext()); try {/*from w ww. j av a 2 s . com*/ profileDao.open(); currentProfile = profileDao.getAllProfiles().get(0); profileDao.close(); } catch (SQLException e) { e.printStackTrace(); } userContactsTimer = new Timer(); getUserContactsTask = new GetUserContactsTask(); userContactsTimer.schedule(getUserContactsTask, 1000, 60000); fAdapter = new FavoriteAdapter(inflater.getContext(), getActivity()); setListAdapter(fAdapter); mSwipeRefreshLayout = new ListFragmentSwipeRefreshLayout(container.getContext()); mSwipeRefreshLayout.addView(listFragmentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mSwipeRefreshLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); this.setRefreshing(false); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { forceUpdate(); } }); return mSwipeRefreshLayout; }
From source file:com.microsoft.speech.tts.Authentication.java
public Authentication(String apiKey) { this.apiKey = apiKey; Thread th = new Thread(new Runnable() { @Override//from www. j a v a 2 s .c o m public void run() { RenewAccessToken(); } }); try { th.start(); th.join(); } catch (Exception e) { e.printStackTrace(); } // renew the accessToken every specified minutes accessTokenRenewer = new Timer(); nineMinitesTask = new TimerTask() { public void run() { RenewAccessToken(); } }; accessTokenRenewer.schedule(nineMinitesTask, RefreshTokenDuration, RefreshTokenDuration); }
From source file:cz.cvut.fel.webrtc.handlers.WebHandler.java
public WebHandler() { super();//from ww w.j av a 2 s . c om TimerTask task = new TimerTask() { @Override public void run() { Calendar currentDate = Calendar.getInstance(); for (WebUser user : registry.getAll()) { Calendar ping = user.getLastPing(); ping.add(Calendar.SECOND, 40); if (ping.before(currentDate)) { try { log.info("{} is unreachable.", user.getName()); leaveRoom(user); } catch (Exception e) { } } } } }; Timer timer = new Timer(); timer.scheduleAtFixedRate(task, 30000, 30000); }
From source file:deincraftlauncher.start.StartMinecraft.java
public static void startMC(Modpack pack) { try {// ww w.j a v a 2 s . co m System.out.println("trying to start minecraft"); GameInfos infos = new GameInfos(pack.getName(), new File(pack.getPath()), new GameVersion(pack.getMCVersion(), pack.getGameType()), new GameTweak[] { GameTweak.FORGE }); System.out.println("GameInfos done"); System.out.println("Zugangsdaten: " + settings.getUsername() + settings.getPassword()); Authenticator authenticator = new Authenticator(Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS); AuthResponse rep = authenticator.authenticate(AuthAgent.MINECRAFT, settings.getUsername(), settings.getPassword(), ""); AuthInfos authInfos = new AuthInfos(rep.getSelectedProfile().getName(), rep.getAccessToken(), rep.getSelectedProfile().getId()); System.out.println("authinfos done"); //AuthInfos authInfos = new AuthInfos(settings.getUsername(), MCAuthentication.getToken(settings.getUsername(), settings.getPassword()), MCAuthentication.getUUID(settings.getUsername(), settings.getPassword())); ExternalLaunchProfile profile = MinecraftLauncher.createExternalProfile(infos, getFolder(pack), authInfos); List<String> vmArgs = profile.getVmArgs(); vmArgs.add(String.valueOf("-Xms" + settings.getRAM() + "m")); //System.out.println("vm args: " + vmArgs); profile.setVmArgs(vmArgs); ExternalLauncher launcher = new MCLauncher(profile); System.out.println("profile and launcher done " + launcher.getProfile()); Process launch = launcher.launch(); BufferedReader stdout = new BufferedReader(new InputStreamReader(launch.getInputStream())); String line; while ((line = stdout.readLine()) != null) { System.out.println(line); } Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { Platform.runLater(() -> { System.out.println("minecraft started, changing start state"); pack.setStartState(PackViewHandler.StartState.Loading); pack.setStartText("gestartet"); }); } }, 8000); checkAlive(launch, pack); } catch (LaunchException | AuthenticationException | IOException ex) { Logger.getLogger(StartMinecraft.class.getName()).log(Level.SEVERE, null, ex); } }