List of usage examples for java.util TimerTask cancel
public boolean cancel()
From source file:org.neo4j.server.web.LimitRequestTimeFilter.java
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws ServletException, IOException { HttpServletRequest request = (HttpServletRequest) req; int timeLimit = getTimeLimit(request); if (timeLimit <= 0) { chain.doFilter(req, res);/*from w w w.j a v a 2s. c om*/ } else { TimerTask timer = createTimer(timeLimit); try { chain.doFilter(req, res); } finally { timer.cancel(); } } }
From source file:org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils.java
public void cancelDeleteLogicalSwitch(final NodeId hwvtepNodeId, final String lsName) { Pair<NodeId, String> nodeIdLogicalSwitchNamePair = new ImmutablePair<>(hwvtepNodeId, lsName); TimerTask logicalSwitchDeleteTask = logicalSwitchDeletedTasks.get(nodeIdLogicalSwitchNamePair); if (logicalSwitchDeleteTask != null) { LOG.debug("Delete logical switch {} action on node {} cancelled", lsName, hwvtepNodeId); logicalSwitchDeleteTask.cancel(); logicalSwitchDeletedTasks.remove(nodeIdLogicalSwitchNamePair); }//from w ww. j av a 2 s. c o m }
From source file:org.opendaylight.vpnservice.elan.l2gw.utils.ElanL2GatewayUtils.java
public static void cancelDeleteLogicalSwitch(final NodeId hwvtepNodeId, final String lsName) { Pair<NodeId, String> nodeIdLogicalSwitchNamePair = new ImmutablePair<NodeId, String>(hwvtepNodeId, lsName); TimerTask logicalSwitchDeleteTask = LogicalSwitchDeletedTasks.get(nodeIdLogicalSwitchNamePair); if (logicalSwitchDeleteTask != null) { LOG.debug("Delete logical switch {} action on node {} cancelled", lsName, hwvtepNodeId); logicalSwitchDeleteTask.cancel(); LogicalSwitchDeletedTasks.remove(nodeIdLogicalSwitchNamePair); }/* w w w. j av a 2s . c om*/ }
From source file:org.opendaylight.vtn.manager.internal.packet.VTNPacketService.java
/** * Close the internal packet service./*from w ww .j a v a2s .c o m*/ */ @Override public void close() { listeners.clear(); super.close(); packetService.set(null); for (Iterator<TimerTask> it = topologyWaiting.values().iterator(); it.hasNext();) { TimerTask task = it.next(); task.cancel(); it.remove(); } }
From source file:org.opendaylight.vtn.manager.internal.packet.VTNPacketService.java
/** * Invoked when a node information has been added or removed. * * @param ev A {@link VtnNodeEvent} instance. *///www. j av a 2 s .c om @Override public void notifyVtnNode(VtnNodeEvent ev) { if (ev.getUpdateType() == VtnUpdateType.REMOVED) { // Terminate topology waits on ports contained by the removed node. long num = ev.getSalNode().getNodeNumber(); Set<Map.Entry<SalPort, TimerTask>> eset = topologyWaiting.entrySet(); for (Iterator<Map.Entry<SalPort, TimerTask>> it = eset.iterator(); it.hasNext();) { Map.Entry<SalPort, TimerTask> ent = it.next(); SalPort sport = ent.getKey(); if (sport.getNodeNumber() == num) { LOG.debug("{}: Terminate topology wait on removed node.", sport); TimerTask task = ent.getValue(); task.cancel(); } } } }
From source file:org.opendaylight.vtn.manager.internal.packet.VTNPacketService.java
/** * {@inheritDoc}/*w w w . j a va2 s . c o m*/ */ @Override public void notifyVtnPort(VtnPortEvent ev) throws VTNException { String reason = shouldTopologyWaitTerminate(ev); if (reason != null) { SalPort sport = ev.getSalPort(); TimerTask task = topologyWaiting.remove(sport); if (task != null) { LOG.debug("{}: Terminate topology wait: reason={}", sport, reason); task.cancel(); } } else if (Boolean.TRUE.equals(ev.getStateChange())) { // Wait for completion of topology detection on this port. addTopologyWaiting(ev.getSalPort()); } }
From source file:org.openmrs.test.BaseContextSensitiveTest.java
/** * Utility method for obtaining username and password through Swing interface for tests. Any * tests extending the org.openmrs.BaseTest class may simply invoke this method by name. * Username and password are returned in a two-member String array. If the user aborts, null is * returned. <b> <em>Do not call for non-interactive tests, since this method will try to * render an interactive dialog box for authentication!</em></b> * /*from w w w.j ava 2s . com*/ * @param message string to display above username field * @return Two-member String array containing username and password, respectively, or * <code>null</code> if user aborts dialog */ public static synchronized String[] askForUsernameAndPassword(String message) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } if (message == null || "".equals(message)) message = "Enter username/password to authenticate to OpenMRS..."; JPanel panel = new JPanel(new GridBagLayout()); JLabel usernameLabel = new JLabel("Username"); usernameLabel.setFont(font); usernameField = new JTextField(20); usernameField.setFont(font); JLabel passwordLabel = new JLabel("Password"); passwordLabel.setFont(font); JPasswordField passwordField = new JPasswordField(20); passwordField.setFont(font); panel.add(usernameLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0)); panel.add(usernameField, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); panel.add(passwordLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 5, 0)); panel.add(passwordField, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); frame = new JFrame(); Window window = new Window(frame); frame.setVisible(true); frame.setTitle("JUnit Test Credentials"); // We use a TimerTask to force focus on username, but still use // JOptionPane for model dialog TimerTask later = new TimerTask() { @Override public void run() { if (frame != null) { // bring the dialog's window to the front frame.toFront(); usernameField.grabFocus(); } } }; // try setting focus half a second from now new Timer().schedule(later, 500); // attention grabber for those people that aren't as observant TimerTask laterStill = new TimerTask() { @Override public void run() { if (frame != null) { frame.toFront(); // bring the dialog's window to the // front usernameField.grabFocus(); } } }; // if the user hasn't done anything in 10 seconds, tell them the window // is there new Timer().schedule(laterStill, 10000); // show the dialog box int response = JOptionPane.showConfirmDialog(window, panel, message, JOptionPane.OK_CANCEL_OPTION); // clear out the window so the timer doesn't screw up laterStill.cancel(); frame.setVisible(false); window.setVisible(false); frame = null; // response of 2 is the cancel button, response of -1 is the little red // X in the top right return (response == 2 || response == -1 ? null : new String[] { usernameField.getText(), String.valueOf(passwordField.getPassword()) }); }