List of usage examples for java.util Timer Timer
public Timer()
From source file:de.sub.goobi.forms.ModuleServerForm.java
/** * Start module server./* www . ja va2 s .c o m*/ */ public void readAllModulesFromConfiguration() { if (modulmanager == null) { synchronized (ModuleServerForm.class) { if (modulmanager == null) { int port = ConfigCore.getIntParameter("kitodoModuleServerPort"); final GoobiModuleManager manager = new GoobiModuleManager(port, new ExtendedProzessImpl(), new ExtendedDataImpl()); // Alle Modulbeschreibungen aus der Konfigurationsdatei // modules.xml einlesen manager.addAll(getModulesFromConfigurationFile()); modulmanager = manager; } // Nachrichtensystem initialisieren int delay = 5000; int period = 1000; messageTimer = new Timer(); messageTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { ModuleServerForm.check_new_messages(modulmanager); } }, delay, period); running = true; } } }
From source file:com.fantasy.AggregatorConfig.java
@Bean @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public Timer timer() { return new Timer(); }
From source file:edu.uci.ics.jung.samples.AddNodeDemo.java
@Override public void init() { //create a graph Graph<Number, Number> ig = Graphs .<Number, Number>synchronizedDirectedGraph(new DirectedSparseMultigraph<Number, Number>()); ObservableGraph<Number, Number> og = new ObservableGraph<Number, Number>(ig); og.addGraphEventListener(new GraphEventListener<Number, Number>() { public void handleGraphEvent(GraphEvent<Number, Number> evt) { System.err.println("got " + evt); }//from w w w . j av a 2 s . c om }); this.g = og; //create a graphdraw layout = new FRLayout2<Number, Number>(g); // ((FRLayout)layout).setMaxIterations(200); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(600, 600)); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); getContentPane().setLayout(new BorderLayout()); getContentPane().setBackground(java.awt.Color.lightGray); getContentPane().setFont(new Font("Serif", Font.PLAIN, 12)); vv.getModel().getRelaxer().setSleepTime(500); vv.setGraphMouse(new DefaultModalGraphMouse<Number, Number>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>()); vv.setForeground(Color.white); getContentPane().add(vv); switchLayout = new JButton("Switch to SpringLayout"); switchLayout.addActionListener(new ActionListener() { @SuppressWarnings({ "unchecked", "rawtypes" }) public void actionPerformed(ActionEvent ae) { Dimension d = new Dimension(600, 600); if (switchLayout.getText().indexOf("Spring") > 0) { switchLayout.setText("Switch to FRLayout"); layout = new SpringLayout<Number, Number>(g, new ConstantTransformer(EDGE_LENGTH)); layout.setSize(d); vv.getModel().setGraphLayout(layout, d); } else { switchLayout.setText("Switch to SpringLayout"); layout = new FRLayout<Number, Number>(g, d); vv.getModel().setGraphLayout(layout, d); } } }); getContentPane().add(switchLayout, BorderLayout.SOUTH); timer = new Timer(); }
From source file:com.google.code.facebook.graph.sna.applet.AddNodeDemo.java
@Override public void init() { //create a graph Graph<Number, Number> ig = Graphs .<Number, Number>synchronizedDirectedGraph(new DirectedSparseMultigraph<Number, Number>()); ObservableGraph<Number, Number> og = new ObservableGraph<Number, Number>(ig); og.addGraphEventListener(new GraphEventListener<Number, Number>() { public void handleGraphEvent(GraphEvent<Number, Number> evt) { System.err.println("got " + evt); }/*w ww . jav a2 s . c o m*/ }); this.g = og; //create a graphdraw layout = new FRLayout2<Number, Number>(g); // ((FRLayout)layout).setMaxIterations(200); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(600, 600)); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); getContentPane().setLayout(new BorderLayout()); getContentPane().setBackground(java.awt.Color.lightGray); getContentPane().setFont(new Font("Serif", Font.PLAIN, 12)); vv.getModel().getRelaxer().setSleepTime(500); vv.setGraphMouse(new DefaultModalGraphMouse<Number, Number>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>()); vv.setForeground(Color.white); getContentPane().add(vv); switchLayout = new JButton("Switch to SpringLayout"); switchLayout.addActionListener(new ActionListener() { @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent ae) { Dimension d = new Dimension(600, 600); if (switchLayout.getText().indexOf("Spring") > 0) { switchLayout.setText("Switch to FRLayout"); layout = new SpringLayout<Number, Number>(g, new ConstantTransformer(EDGE_LENGTH)); layout.setSize(d); vv.getModel().setGraphLayout(layout, d); } else { switchLayout.setText("Switch to SpringLayout"); layout = new FRLayout<Number, Number>(g, d); vv.getModel().setGraphLayout(layout, d); } } }); getContentPane().add(switchLayout, BorderLayout.SOUTH); timer = new Timer(); }
From source file:edu.mayo.cts2.framework.plugin.service.lexevs.naming.DefaultCodingSchemeNameTranslator.java
protected void scheduleflushCache() { TimerTask flushTask = new TimerTask() { @Override//from w w w .j a v a2 s .c om public void run() { buildCaches(); } }; Timer timer = new Timer(); int minutesInMillis = FLUSH_PERIOD_MINUTES * 60 * 1000; timer.schedule(flushTask, 0, minutesInMillis); }
From source file:org.gtri.fhir.api.vistaex.rest.service.servlet.GtVistaRestfulServlet.java
/** * This method is called automatically when the * servlet is initializing.//from ww w. j a v a 2 s . com */ @Override public void initialize() { //Get a handle on the Web Application Context WebApplicationContext applicationContext = ContextLoaderListener.getCurrentWebApplicationContext(); /* * Two resource providers are defined. Each one handles a specific * type of resource. */ List<IResourceProvider> providers = new ArrayList<IResourceProvider>(); providers.add(new GtVistaExApiAllergyIntolleranceResourceProvider()); providers.add(new GtVistaExApiConditionResourceProvider()); providers.add(new GtVistaExApiEncounterResourceProvider()); providers.add(new GtVistaExApiMedicationAdministrationResourceProvider()); providers.add(new GtVistaExApiMedicationOrderResourceProvider()); providers.add(new GtVistaExApiObservationResourceProvider()); providers.add(new GtVistaExApiPatientResourceProvider()); providers.add(new GtVistaExApiProcedureResourceProvider()); setResourceProviders(providers); /* * Add custom conformance provider */ GtVistaExConformanceProvider conformanceProvider = new GtVistaExConformanceProvider(this); setServerConformanceProvider(conformanceProvider); /* * Use a narrative generator. This is a completely optional step, * but can be useful as it causes HAPI to generate narratives for * resources which don't otherwise have one. */ INarrativeGenerator narrativeGen = new DefaultThymeleafNarrativeGenerator(); getFhirContext().setNarrativeGenerator(narrativeGen); /* * This server interceptor causes the server to return nicely * formatter and coloured responses instead of plain JSON/XML if * the request is coming from a browser window. It is optional, * but can be nice for testing. */ registerInterceptor(new ResponseHighlighterInterceptor()); /* * Tells the server to return pretty-printed responses by default */ setDefaultPrettyPrint(true); /* * Default to JSON and pretty printing */ setDefaultResponseEncoding(EncodingEnum.JSON); setFhirContext(new FhirContext((FhirVersionEnum.DSTU2))); //log in to Vista Ex API VistaUtil.getVistaExResource().loginToVistaEx(); //start the refresh thread sessionRefreshTimerTask = new SessionRefreshTimer(); refreshTimer = new Timer(); refreshTimer.schedule(sessionRefreshTimerTask, SESSION_REFRESH_INTERVAL_MILLI, SESSION_REFRESH_INTERVAL_MILLI); }
From source file:eu.medsea.mimeutil.detector.OpendesktopMimeDetector.java
private void init(final String mimeCacheFile) { String cacheFile = mimeCacheFile; if (!new File(cacheFile).exists()) { cacheFile = internalMimeCacheFile; }// w w w. ja va2 s. co m // Map the mime.cache file as a memory mapped file FileChannel rCh = null; try { RandomAccessFile raf = null; raf = new RandomAccessFile(cacheFile, "r"); rCh = (raf).getChannel(); content = rCh.map(FileChannel.MapMode.READ_ONLY, 0, rCh.size()); // Read all of the MIME type from the Alias list initMimeTypes(); if (log.isDebugEnabled()) { log.debug("Registering a FileWatcher for [" + cacheFile + "]"); } TimerTask task = new FileWatcher(new File(cacheFile)) { protected void onChange(File file) { initMimeTypes(); } }; timer = new Timer(); // repeat the check every 10 seconds timer.schedule(task, new Date(), 10000); } catch (Exception e) { throw new MimeException(e); } finally { if (rCh != null) { try { rCh.close(); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); } } } }
From source file:net.frygo.findmybuddy.GCMIntentService.java
private static void generateNotification(Context context, String message) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); notificationIntent.putExtra("alert", message); message = message + " would like to add you as friend"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); mWakelock.acquire();/*from w w w . ja v a 2s . c o m*/ // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); }
From source file:org.wso2.carbon.apimgt.gateway.throttling.util.KeyTemplateRetriever.java
public void startKeyTemplateDataRetriever() { new Timer().schedule(this, ServiceReferenceHolder.getInstance().getThrottleProperties().getBlockCondition().getInitDelay()); }
From source file:com.alliander.osgp.adapter.protocol.iec61850.application.services.DeviceRegistrationService.java
/** * After the device has registered with the platform successfully, the * device has to be informed that the registration worked. Disable an * attribute so the device will stop attempting to register once a minute. * * @param deviceIdentification//from w w w . j a v a 2 s.c o m * The device identification. * @param ipAddress * The IP address of the device. * @param ied * The type of IED. * * @throws ProtocolAdapterException * In case the connection to the device can not be established. */ public void disableRegistration(final String deviceIdentification, final InetAddress ipAddress, final IED ied) throws ProtocolAdapterException { this.iec61850DeviceConnectionService.connect(ipAddress.getHostAddress(), deviceIdentification, ied, LogicalDevice.LIGHTING); final Iec61850ClientAssociation iec61850ClientAssociation = this.iec61850DeviceConnectionService .getIec61850ClientAssociation(deviceIdentification); final ServerModel serverModel = this.iec61850DeviceConnectionService.getServerModel(deviceIdentification); final DeviceConnection deviceConnection = new DeviceConnection( new Iec61850Connection(iec61850ClientAssociation, serverModel), deviceIdentification, ied); final Function<Void> function = new Function<Void>() { @Override public Void apply() throws Exception { DeviceRegistrationService.this.setLocationInformation(deviceConnection); DeviceRegistrationService.this.disableRegistration(deviceConnection); if (DeviceRegistrationService.this.isReportingAfterDeviceRegistrationEnabled) { LOGGER.info("Reporting enabled for device: {}", deviceConnection.getDeviceIdentification()); new Iec61850EnableReportingCommand().enableReportingOnDeviceWithoutUsingSequenceNumber( DeviceRegistrationService.this.iec61850DeviceConnectionService.getIec61850Client(), deviceConnection); // Don't disconnect now! The device should be able to send // reports. new Timer().schedule(new TimerTask() { @Override public void run() { try { new Iec61850ClearReportCommand().clearReportOnDevice(deviceConnection); } catch (final ProtocolAdapterException e) { LOGGER.error("Unable to clear report for device: " + deviceConnection.getDeviceIdentification(), e); } DeviceRegistrationService.this.iec61850DeviceConnectionService .disconnect(deviceConnection.getDeviceIdentification()); } }, DeviceRegistrationService.this.delayAfterDeviceRegistration); } else { LOGGER.info("Reporting disabled for device: {}", deviceIdentification); DeviceRegistrationService.this.iec61850DeviceConnectionService .disconnect(deviceConnection.getDeviceIdentification()); } return null; } }; this.iec61850DeviceConnectionService.sendCommandWithRetry(function); }