List of usage examples for java.util Timer Timer
public Timer(String name)
From source file:org.apache.servicemix.jms.JmsComponent.java
private void scheduleConsumerStopper() { stopperTimer = new Timer("component." + getContext().getComponentName() + ".timer"); stopperTimer.schedule(consumersStopper.createTimerTask(), 1000, 1000); // TODO: configurable }
From source file:com.mobicage.rogerthat.registration.YSAAARegistrationActivity.java
@Override protected void onServiceBound() { setContentView(R.layout.ysaaa_registration); mWiz = YSAAARegistrationWizard.getWizard(mService, Installation.id(this)); if (CloudConstants.USE_GCM_KICK_CHANNEL && GoogleServicesUtils.checkPlayServices(this, true)) { GoogleServicesUtils.registerGCMRegistrationId(mService, new GCMRegistrationIdFoundCallback() { @Override/*www . j a v a 2s. com*/ public void idFound(String registrationId) { mGCMRegistrationId = registrationId; } }); } mStatusLbl = (TextView) findViewById(R.id.status); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mTimer = new Timer(false); mRetryBtn = (Button) findViewById(R.id.retry_button); mRetryBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { register(); } }); final String[] receivingIntents = new String[] { FriendsPlugin.FRIENDS_LIST_REFRESHED, FriendsPlugin.FRIEND_UPDATE_INTENT, FriendsPlugin.FRIEND_ADDED_INTENT, BrandingMgr.SERVICE_BRANDING_AVAILABLE_INTENT, BrandingMgr.GENERIC_BRANDING_AVAILABLE_INTENT }; IntentFilter filter = new IntentFilter(); for (String action : receivingIntents) filter.addAction(action); registerReceiver(new SafeBroadcastReceiver() { @Override public String[] onSafeReceive(Context context, Intent intent) { T.UI(); launchMainActivityAndFinishIfAppReady(); return receivingIntents; }; }, filter); register(); }
From source file:com.moss.veracity.core.Veracity.java
public Veracity(LaunchParameters parameters) throws Exception { log = LogFactory.getLog(this.getClass()); File dataDir = parameters.dataDirectory(); File configFile = new File(dataDir, "veracity.xml"); File imageDir = new File(dataDir, "images"); File persistenceDir = new File(dataDir, "env"); File brokerDir = new File(dataDir, "broker"); if (!dataDir.exists() && !dataDir.mkdirs()) { throw new Exception("Could not create dir: " + dataDir); }/*from w w w . ja v a 2 s. co m*/ if (!imageDir.exists() && !imageDir.mkdirs()) { throw new Exception("Could not create dir: " + imageDir); } try { configManager = new ConfigManager(configFile); persistence = new PersistenceManager(persistenceDir); long tenSeconds = 1000 * 10; long thirtyMinutes = 1000 * 60 * 30; keyExpirationTimer = new Timer(true); keyExpirationTimer.scheduleAtFixedRate(new KeyExpirationTimerTask(), tenSeconds, thirtyMinutes); createDefaultUser(); JAXBContext updateJaxbContext = JAXBContext.newInstance(PublicKeyTransmission.class, AccountModifiedTransmission.class, PasswordMechanism.class); updateReceiver = new UpdateReceiver(updateJaxbContext, persistence); new Thread("InitialReceiverConfigThread") { public void run() { updateReceiver.configure(configManager.config()); } }.start(); configManager.addListener(new ConfigListener() { public void configChanged(Configuration config) { updateReceiver.configure(config); } }); URI brokerVmUri = new URI("vm://localhost?create=false"); URI brokerTcpUri = new URI("tcp://" + parameters.bindAddress() + ":" + parameters.syncPort()); if (log.isDebugEnabled()) { log.debug("Starting Broker with public uri: " + brokerTcpUri); } broker = new BrokerService(); broker.addConnector(brokerVmUri); broker.addConnector(brokerTcpUri); broker.setPersistent(true); broker.setDataDirectoryFile(brokerDir); broker.setUseShutdownHook(false); broker.setUseJmx(false); broker.start(); updateTransmitter = new UpdateTransmitterJMSImpl(brokerVmUri, updateJaxbContext); endorsementManager = new EndorsementManager(persistence, updateTransmitter); endorsementManager.configure(configManager.config()); configManager.addListener(new ConfigListener() { public void configChanged(Configuration config) { endorsementManager.configure(config); } }); if (log.isDebugEnabled()) { log.debug("Creating http server"); } jetty = new Server(parameters.httpPort()); if (log.isDebugEnabled()) { log.debug("Publishing Authentication service"); } { Authentication authService = new AuthenticationImpl(persistence, endorsementManager); String path = "/" + authService.getClass().getSimpleName(); SwitchingContentHandler handler = new SwitchingContentHandler(path); handler.addHandler(new JAXWSContentHandler(authService)); handler.addHandler(new HessianContentHandler(Authentication.class, authService)); jetty.addHandler(handler); } if (log.isDebugEnabled()) { log.debug("Publishing Management service"); } { Management manageService = new ManagementImpl(persistence, configManager, updateTransmitter); String path = "/" + manageService.getClass().getSimpleName(); SwitchingContentHandler handler = new SwitchingContentHandler(path); handler.addHandler(new JAXWSContentHandler(manageService)); handler.addHandler(new HessianContentHandler(Management.class, manageService)); jetty.addHandler(handler); } if (log.isDebugEnabled()) { log.debug("Creating identity manager servlet context"); } HttpHandler idManagerServlet = new IdentityManagerServlet(); jetty.addHandler(new BSHandler(IdentityManagerServlet.LAUNCH_PATH, idManagerServlet)); jetty.addHandler(new BSHandler(IdentityManagerServlet.JAR_PATH, idManagerServlet)); if (log.isDebugEnabled()) { log.debug("Starting http server"); } jetty.start(); /* * Cleanup */ shutdownHook = new ShutdownThread(); Runtime.getRuntime().addShutdownHook(shutdownHook); } catch (Exception ex) { shutdown(); throw ex; } }
From source file:org.powertac.visualizer.services.VisualizerServiceTournament.java
/** * Called on initialization to start message feeder and state machine. *//* w ww .j a va 2 s . com*/ public void init() { // Start the logger Logger root = Logger.getRootLogger(); root.removeAllAppenders(); try { PatternLayout logLayout = new PatternLayout("%r %-5p %c{2}: %m%n"); String logPath = System.getProperty("catalina.base", ""); if (!logPath.isEmpty()) { logPath += "/logs/" + machineName + "-viz.log"; } else { logPath += "log/" + machineName + "-viz.log"; } FileAppender logFile = new FileAppender(logLayout, logPath, false); root.addAppender(logFile); } catch (IOException ioe) { log.info("Can't open log file"); System.exit(0); } // Start the message feeder messageFeeder = new Thread(messagePump); messageFeeder.setDaemon(true); messageFeeder.start(); // Start the state machine tickTimer = new Timer(true); stateTask = new TimerTask() { @Override public void run() { log.debug("message count = " + visualizerBean.getMessageCount() + ", queue size = " + messageQueue.size()); // Timer fires every 30 secs, but tournamentLogin() sleep for 60 secs // if no game available. That would build up ticks in the queue if (currentState == loginWait && eventQueue.contains(Event.tick)) { return; } putEvent(Event.tick); } }; tickTimer.schedule(stateTask, 10, tickPeriod); stateRunner = new Thread(runStates); stateRunner.setDaemon(true); stateRunner.start(); }
From source file:com.sumzerotrading.broker.ib.InteractiveBrokersBroker.java
public InteractiveBrokersBroker(IBSocket ibSocket) { this.ibSocket = ibSocket; try {/*from w ww .ja v a 2 s . c o m*/ loadOrderMaps(); } catch (Exception ex) { throw new SumZeroException(ex); } orderEventMap = new PassiveExpiringMap<>(30, TimeUnit.SECONDS); callbackInterface = ibSocket.getConnection(); callbackInterface.addIbConnectionDelegate(this); ibConnection = ibSocket.getClientSocket(); orderProcessor = new IBOrderEventProcessor(orderEventQueue, this); currencyOrderTimer = new Timer(true); currencyOrderTimer.schedule(getCurrencyOrderMonitor(), 0, 1000 * 60); }
From source file:com.symbian.driver.plugins.comms.stat.StatProcess.java
/** * Starts a timer to terminate a job when the TimeOut has occured if Timeout * is greater than 0//from ww w.ja v a 2 s . c o m * * @param aTimeout * The length of time before the job should be canceled. * @return The Timer object which controls the timeout. */ private static Timer startTimer(final int aTimeout) { try { TIMEOUT_MAX = TDConfig.getInstance().getPreferenceInteger(TDConfig.TOTAL_TIMEOUT); } catch (ParseException lParseException) { // ignore , we have a default value. } Timer lTimeoutTimer = new Timer(false); lTimeoutTimer.schedule(new TimerTask() { public void run() { LOGGER.log(Level.SEVERE, "Time out : " + aTimeout + " ms reached."); STOP = true; } }, (aTimeout == 0) ? TIMEOUT_MAX : aTimeout); return lTimeoutTimer; }
From source file:com.vdenotaris.spring.boot.security.saml.web.config.WebSecurityConfig.java
@PostConstruct public void init() { this.backgroundTaskTimer = new Timer(true); this.multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); }
From source file:dk.itst.oiosaml.sp.metadata.CRLChecker.java
public void startChecker(long period, final IdpMetadata metadata, final Configuration conf) { if (timer != null) return;//from w w w . ja v a 2 s . c o m log.info("Starting CRL checker, running with " + period + " seconds interval. Checking " + metadata.getEntityIDs().size() + " certificates"); timer = new Timer("CRLChecker"); timer.schedule(new TimerTask() { public void run() { log.debug("Running CRL checker task"); try { checkCertificates(metadata, conf); } catch (Exception e) { log.error("Unable to run CRL checker", e); } } }, 1000L, 1000L * period); }
From source file:eu.stratosphere.nephele.instance.DefaultInstanceManager.java
/** * Constructor./*from w w w .j ava 2 s. c o m*/ */ public DefaultInstanceManager() { this.registeredHosts = new HashMap<InstanceConnectionInfo, Instance>(); long tmpCleanUpInterval = (long) GlobalConfiguration.getInteger(CLEANUP_INTERVAL_KEY, DEFAULT_CLEANUP_INTERVAL) * 1000; if (tmpCleanUpInterval < 10) { // Clean up interval must be at least ten seconds LOG.warn("Invalid clean up interval. Reverting to default cleanup interval of " + DEFAULT_CLEANUP_INTERVAL + " secs."); tmpCleanUpInterval = DEFAULT_CLEANUP_INTERVAL; } this.cleanUpInterval = tmpCleanUpInterval; this.networkTopology = NetworkTopology.createEmptyTopology(); // look every BASEINTERVAL milliseconds for crashed hosts final boolean runTimerAsDaemon = true; new Timer(runTimerAsDaemon).schedule(cleanupStaleMachines, 1000, 1000); }
From source file:dk.netarkivet.archive.bitarchive.distribute.BitarchiveServer.java
/** * The server creates an instance of the bitarchive it provides access to * and starts to listen to JMS messages on the incomming jms queue * <p/>/*from w w w .j a va 2 s.c o m*/ * Also, heartbeats are sent out at regular intervals to the Bitarchive * Monitor, to tell that this bitarchive is alive. * * @throws UnknownID - if there was no heartbeat frequency or temp * dir defined in settings or if the * bitarchiveid cannot be created. * @throws PermissionDenied - if the temporary directory or the file * directory cannot be written */ private BitarchiveServer() throws UnknownID, PermissionDenied { System.setOut( new PrintStream(new LoggingOutputStream(LoggingOutputStream.LoggingLevel.INFO, log, "StdOut: "))); System.setErr( new PrintStream(new LoggingOutputStream(LoggingOutputStream.LoggingLevel.WARN, log, "StdErr: "))); boolean listening = false; // are we listening to queue ANY_BA File serverdir = FileUtils.getTempDir(); if (!serverdir.exists()) { serverdir.mkdirs(); } if (!serverdir.canWrite()) { throw new PermissionDenied("Not allowed to write to temp directory '" + serverdir + "'"); } log.info("Storing temporary files at '" + serverdir.getPath() + "'"); bitarchiveAppId = createBitarchiveAppId(); allBa = Channels.getAllBa(); anyBa = Channels.getAnyBa(); baMon = Channels.getTheBamon(); ba = Bitarchive.getInstance(); con = JMSConnectionFactory.getInstance(); con.setListener(allBa, this); baa = BitarchiveAdmin.getInstance(); if (baa.hasEnoughSpace()) { con.setListener(anyBa, this); listening = true; } else { log.warn("Not enough space to guarantee store -- not listening " + "to " + anyBa.getName()); } // create map for batchjobs batchProcesses = Collections.synchronizedMap(new HashMap<String, Thread>()); // Create and start the heartbeat sender Timer timer = new Timer(true); heartBeatSender = new HeartBeatSender(baMon, this); long frequency = Settings.getLong(ArchiveSettings.BITARCHIVE_HEARTBEAT_FREQUENCY); timer.scheduleAtFixedRate(heartBeatSender, 0, frequency); log.info("Heartbeat frequency: '" + frequency + "'"); // Next logentry depends on whether we are listening to ANY_BA or not String logmsg = "Created bitarchive server listening on: " + allBa.getName(); if (listening) { logmsg += " and " + anyBa.getName(); } log.info(logmsg); log.info("Broadcasting heartbeats on: " + baMon.getName()); }