List of usage examples for java.lang InterruptedException printStackTrace
public void printStackTrace()
From source file:com.wso2.rfid.apicalls.APICall.java
private static Token getToken(String consumerKey, String consumerSecret) { HttpClient httpClient = new HttpClient(); // String consumerKey = PizzaShackWebConfiguration.getInstance().getConsumerKey(); // String consumerSecret = PizzaShackWebConfiguration.getInstance().getConsumerSecret(); try {/*w ww.j av a2 s.com*/ String applicationToken = consumerKey + ":" + consumerSecret; BASE64Encoder base64Encoder = new BASE64Encoder(); applicationToken = "Basic " + base64Encoder.encode(applicationToken.getBytes()).trim(); // String payload = "grant_type=password&username="+username+"&password="+password; String payload = "grant_type=client_credentials"; HttpResponse httpResponse = httpClient.doPost(tokenEndpoint, applicationToken, payload, "application/x-www-form-urlencoded"); if (httpResponse.getStatusLine().getStatusCode() != 200) { return null; } String response = httpClient.getResponsePayload(httpResponse); if (response == null || response.isEmpty()) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } return getToken(consumerKey, consumerSecret); //Risk of infinite recursion :) } return getAccessToken(response); } catch (IOException e) { log.error("", e); return null; } }
From source file:de.Keyle.MyPet.util.player.UUIDFetcher.java
public static Map<String, UUID> call(List<String> names) { names = new ArrayList<String>(names); Iterator<String> iterator = names.iterator(); while (iterator.hasNext()) { String playerName = iterator.next(); if (fetchedUUIDs.containsKey(playerName)) { iterator.remove();/*from w ww . ja v a 2 s . c om*/ } } if (names.size() == 0) { return readonlyFetchedUUIDs; } int count = names.size(); DebugLogger.info("get UUIDs for " + names.size() + " player(s)"); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); try { for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body); JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); count -= array.size(); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); fetchedUUIDs.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } } catch (InterruptedException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (count > 0) { MyPetLogger.write("Can not get UUIDs for " + count + " players. Pets of these player may be lost."); } return readonlyFetchedUUIDs; }
From source file:net.bluehornreader.misc.Utils.java
/** * Terminates the VM. Waits 10s to avoid situations when a process crashes and it gets immediately restarted, killing the CPU. * * @param message/*from w ww.ja va 2s .c o m*/ * @param exitCode */ public static void exit(String message, int exitCode) { long sleep = 10000; LOG.info("Exiting due to: " + message); LOG.info(String.format("Sleeping for %d ms", sleep)); try { Thread.sleep(sleep); } catch (InterruptedException e) { e.printStackTrace(); LOG.error("Failed to sleep. Exiting anyway ...", e); } System.exit(exitCode); }
From source file:org.openbaton.autoscaling.utils.Utils.java
public static boolean isNfvoStarted(String ip, String port) { if (true)/*from www . j a v a 2 s . c o m*/ return true; int i = 0; log.info("Waiting until NFVO is available..."); while (!Utils.available(ip, port)) { i++; try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } if (i > 50) { return false; } } return true; }
From source file:mooltipass.AftBase.java
@BeforeClass public static void beforeClass() throws Exception { chromeDriverService = chromeDriverService(); if (chromeDriverService != null) { chromeDriverService.start();//from w w w. jav a 2 s .com } ChromeOptions options = new ChromeOptions(); // Appears you can only load one unpacked extensions this way... // list doesn't do it // List<String> arguments = new LinkedList<String>(); // arguments.add("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app"); // arguments.add("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext"); // options.addArguments(arguments); // comma delimited as some chrome arguments use doesn't work // options.addArguments("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app","load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext"); // String... doesn't work // options.addArguments("load-extension=" + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app," + System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext"); // Requires extensions are crx (zip file with public and private keys) // List extensions = new LinkedList(); // extensions.add(new File(System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome.hid-app")); // extensions.add(new File(System.getProperty(MOOLTIPASS_DIR) + File.separator + "authentication_clients" + File.separator + "chrome-ext")); // options.addExtensions(extensions); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); System.out.println("Starting an instance of chrome."); driver = new ChromeDriver(capabilities); // TODO figure out how to pre-install extensions automatically (see commented out code above for things that don't work) driver.get("chrome://extensions/"); System.out.println( "\nWaiting " + getTimeoutExtension() / 1000 + " seconds for you to install Extensions manually."); System.out.println( "Check the Developer mode checkbox and then use the Load unpackaged extensions to load the mooltipass authentication_clients chrome.hid-app and chrome.ext\n"); try { Thread.sleep(getTimeoutExtension()); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:misc.TestUtils.java
public static void delay(long millis) { try {//www .java 2 s .c o m Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:clientapi.util.ClientAPIUtils.java
/** * Sleeps the current thread for the specified length * of time represented as milliseconds without the need * for a try/catch enclosure.//from w w w . ja va 2s . com * * @see Thread#sleep(long) * * @param ms The milliseconds to sleep * @return Whether or not an {@code InterruptedException} was thrown by {@code Thread#sleep(long)} */ public static boolean sleep(long ms) { if (ms <= 0) { return true; } try { Thread.sleep(ms); return true; } catch (InterruptedException e) { e.printStackTrace(); } return false; }
From source file:co.uk.randompanda30.sao.modules.enhancement.BoosterHandler.java
public static void startBooster(Booster booster) { setBooster(booster);//w ww .ja va2s . c o m showingBoosterMessage = true; List<String> messages = (List<String>) Messages.MessagesValues.MODULES_BOOSTER_BOOSTERSTARTED.value; new BukkitRunnable() { @Override public void run() { for (String s : messages) { SAO.getPlugin().getServer().getScheduler().runTask(SAO.getPlugin(), () -> { if (Bukkit.getServer().getPlayer(booster.uuid) != null && Bukkit.getServer().getPlayer(booster.uuid).isOnline()) { Firework fw = (Firework) Bukkit.getServer().getPlayer(booster.uuid).getWorld() .spawnEntity(Bukkit.getServer().getPlayer(booster.uuid).getLocation(), EntityType.FIREWORK); FireworkMeta fwm = fw.getFireworkMeta(); FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.FUCHSIA) .withFade(Color.FUCHSIA).with(FireworkEffect.Type.BALL_LARGE).trail(true) .build(); fwm.addEffect(effect); fwm.setPower(0); fw.setFireworkMeta(fwm); } }); Dispatch.broadcastMessage(" ", true); String newS = s; newS = newS.replaceAll("%player", booster.name); newS = newS.replaceAll("%perc", Integer.toString(booster.percentage)); Dispatch.broadcastMessage(StringUtils.center(newS, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH), true); Yell.broadcastSound(Sound.NOTE_BASS, 5, 2); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } Yell.broadcastSound(Sound.LEVEL_UP, 5, 1); Play.broadcastEffect(Effect.ENDER_SIGNAL, 5); showingBoosterMessage = false; } }.runTaskAsynchronously(SAO.getPlugin()); }
From source file:com.crossbusiness.resiliency.aspect.AnnotationAsyncAspectTest.java
static private void awite(int time) { try {/*from www.j a va 2 s . c om*/ TimeUnit.MILLISECONDS.sleep(time); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:ru.retbansk.utils.scheduled.impl.ReadEmailAndConvertToXmlSpringImplTest.java
@BeforeClass public static void beforeClass() { reader = new ReadEmailAndConvertToXmlSpringImpl(); try {//w ww.j a v a 2 s .c o m UsefulMethods.populate(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } DayReport dayReport = new DayReport(); dayReport.setPersonId(USER2); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+3")); calendar.set(2012, Calendar.OCTOBER, 18); dayReport.setCalendar(calendar); List<TaskReport> taskList = new ArrayList<TaskReport>(); TaskReport taskReport = new TaskReport(); taskReport.setDate(calendar.getTime()); taskReport.setElapsedTime(1); taskReport.setStatus(TEST_STRING); taskReport.setWorkDescription(TEST_STRING2); taskList.add(taskReport); dayReport.setReportList(taskList); dayReportSet = new HashSet<DayReport>(); dayReportSet.add(dayReport); }