List of usage examples for java.lang Exception getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.chilmers.configbootstrapper.ConfigHelper.java
public PropertyResourceBundle getApplicationConfiguration(String applicationConfigLocation) { InputStream is = null;//from ww w. j a v a 2s .c o m try { if (applicationConfigLocation.startsWith("classpath:")) { applicationConfigLocation = applicationConfigLocation.replaceFirst("classpath:", ""); is = Thread.currentThread().getContextClassLoader().getResourceAsStream(applicationConfigLocation); } else if (applicationConfigLocation.startsWith("file:")) { applicationConfigLocation = applicationConfigLocation.replaceFirst("file:", ""); is = new FileInputStream(applicationConfigLocation); } else { logToSystemOut("The application configuration location must start with file: or classpath:"); } return new PropertyResourceBundle(is); } catch (Exception e) { logToSystemOut("There was a problem reading the application configuration at location: " + applicationConfigLocation + "\n" + "Exception:" + e.getClass().toString() + "\n" + "Message:" + e.getMessage()); } finally { try { is.close(); } catch (Exception e) { logToSystemOut("WARNING! Exception while trying to close configuration file.\n" + "Exception:" + e.getClass().toString() + "\n" + "Message:" + e.getMessage()); } } return null; }
From source file:de.tudarmstadt.lt.lm.app.NgramProbs.java
/** * //from w w w . j a va2s . c o m */ @SuppressWarnings("static-access") public NgramProbs(String args[]) { Options opts = new Options(); opts.addOption(new Option("?", "help", false, "display this message")); opts.addOption(OptionBuilder.withLongOpt("port").withArgName("port-number").hasArg() .withDescription( String.format("Specifies the port on which the rmi registry listens (default: %d).", Registry.REGISTRY_PORT)) .create("p")); opts.addOption(OptionBuilder.withLongOpt("host").withArgName("hostname").hasArg() .withDescription("Specifies the hostname on which the rmi registry listens (default: localhost).") .create("h")); opts.addOption(OptionBuilder.withLongOpt("file").withArgName("name").hasArg().withDescription( "Specify the file or directory that contains '.txt' with one ngram per line. Specify '-' to pipe from stdin. (default: '-').") .create("f")); opts.addOption(OptionBuilder.withLongOpt("out").withArgName("name").hasArg() .withDescription("Specify the output file. Specify '-' to use stdout. (default: '-').") .create("o")); opts.addOption(OptionBuilder.withLongOpt("name").withArgName("identifier").isRequired().hasArg() .withDescription("Specify the name of the language model provider that you want to connect to.") .create("i")); try { CommandLine cmd = new ExtendedGnuParser(true).parse(opts, args); if (cmd.hasOption("help")) CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, null, 0); _host = cmd.getOptionValue("host", "localhost"); _rmiport = Integer.parseInt(cmd.getOptionValue("port", String.valueOf(Registry.REGISTRY_PORT))); _file = cmd.getOptionValue("file", "-"); _out = cmd.getOptionValue("out", "-"); _name = cmd.getOptionValue("name"); _host = cmd.getOptionValue("host", "localhost"); } catch (Exception e) { LOG.error("{}: {}- {}", _rmi_string, e.getClass().getSimpleName(), e.getMessage()); CliUtils.print_usage_quit(System.err, StartLM.class.getSimpleName(), opts, USAGE_HEADER, String.format("%s: %s%n", e.getClass().getSimpleName(), e.getMessage()), 1); } _rmi_string = String.format("rmi://%s:%d/%s", _host, _rmiport, _name); }
From source file:com.pinterest.pinlater.backends.redis.RedisQueueMonitor.java
@Override protected void jobMonitorImpl(long runStartMillis, final Map.Entry<String, RedisPools> shard, int numAutoRetries) { // Skip the shard if it is unhealthy. if (!healthChecker.isServerLive(shard.getValue().getHost(), shard.getValue().getPort())) { LOG.warn(String.format("Skipped monitoring shard %s because it is unhealthy.", shard.getKey())); return;/*w w w. j ava2 s . com*/ } final double runStartTimeSeconds = runStartMillis / 1000.0; final double succeededGCTimeSeconds = (runStartMillis - getJobSucceededGCTimeoutMillis()) / 1000.0; final double failedGCTimeSeconds = (runStartMillis - getJobFailedGCTimeoutMillis()) / 1000.0; final double timeoutTimeSeconds = (runStartMillis - getJobClaimedTimeoutMillis()) / 1000.0; try { RedisUtils.executeWithConnection(shard.getValue().getMonitorRedisPool(), new Function<Jedis, Void>() { @Override public Void apply(Jedis conn) { Set<String> queueNames = RedisBackendUtils.getQueueNames(conn, shard.getKey()); for (String queueName : queueNames) { for (int priority = 1; priority <= numPriorityLevels; priority++) { String pendingQueueRedisKey = RedisBackendUtils.constructQueueRedisKey(queueName, shard.getKey(), priority, PinLaterJobState.PENDING); String inProgressQueueRedisKey = RedisBackendUtils.constructQueueRedisKey(queueName, shard.getKey(), priority, PinLaterJobState.IN_PROGRESS); String succeededQueueRedisKey = RedisBackendUtils.constructQueueRedisKey(queueName, shard.getKey(), priority, PinLaterJobState.SUCCEEDED); String failedQueueRedisKey = RedisBackendUtils.constructQueueRedisKey(queueName, shard.getKey(), priority, PinLaterJobState.FAILED); String hashRedisKeyPrefix = RedisBackendUtils.constructHashRedisKeyPrefix(queueName, shard.getKey()); // Handle timed out jobs. List<String> keys = Lists.newArrayList(inProgressQueueRedisKey, hashRedisKeyPrefix, pendingQueueRedisKey, failedQueueRedisKey); List<String> argv = Lists.newArrayList(String.valueOf(timeoutTimeSeconds), String.valueOf(getUpdateMaxSize()), String.valueOf(runStartTimeSeconds)); Object nums = conn.eval(RedisLuaScripts.MONITOR_TIMEOUT_UPDATE, keys, argv); List<Object> tmp = (List<Object>) nums; numTimeoutDone += Integer.valueOf((String) tmp.get(0)); numTimeoutRetry += Integer.valueOf((String) tmp.get(1)); numTimeoutEvict += Integer.valueOf((String) tmp.get(2)); // Succeeded job GC. keys = Lists.newArrayList(succeededQueueRedisKey, hashRedisKeyPrefix); argv = Lists.newArrayList(String.valueOf(succeededGCTimeSeconds), String.valueOf(getUpdateMaxSize())); numSucceededGC += (Long) conn.eval(RedisLuaScripts.MONITOR_GC_DONE_JOBS, keys, argv); // Failed job GC. keys = Lists.newArrayList(failedQueueRedisKey, hashRedisKeyPrefix); argv = Lists.newArrayList(String.valueOf(failedGCTimeSeconds), String.valueOf(getUpdateMaxSize())); numFailedGC += (Long) conn.eval(RedisLuaScripts.MONITOR_GC_DONE_JOBS, keys, argv); logCount++; if (logCount % getLogInterval() == 0) { LOG.info(String.format("JobQueueMonitor: " + "Shard: %s Queue: %s Priority: %d Timeout Done: %d Timeout Retry: %d " + "Succeeded GC: %d Failed GC: %d", shard.getKey(), queueName, priority, numTimeoutDone, numTimeoutRetry, numSucceededGC, numFailedGC)); if (numTimeoutEvict != 0) { LOG.error(String.format( "JobQueueMonitor: Shard: %s Queue: %s Priority: %d Timeout Evict: %d", shard.getKey(), queueName, priority, numTimeoutEvict)); } Stats.incr(queueName + "_timeout_done", numTimeoutDone); Stats.incr(queueName + "_timeout_retry", numTimeoutRetry); Stats.incr(queueName + "_timeout_evict", numTimeoutEvict); Stats.incr(queueName + "_succeeded_gc", (int) numSucceededGC); Stats.incr(queueName + "_failed_gc", (int) numFailedGC); logCount = 0; numTimeoutDone = 0; numTimeoutRetry = 0; numSucceededGC = 0; numFailedGC = 0; numTimeoutEvict = 0; } } } return null; } }); } catch (Exception e) { Stats.incr("PinLater.RedisQueueMonitor.errors." + e.getClass().getSimpleName()); LOG.error("Exception in JobQueueMonitor task", e); } }
From source file:de.topobyte.livecg.LiveCG.java
private void setLookAndFeel(String lookAndFeel) { try {//from w ww. j av a 2s . com UIManager.setLookAndFeel(lookAndFeel); } catch (Exception e) { logger.error("error while setting look and feel '" + lookAndFeel + "': " + e.getClass().getSimpleName() + ", message: " + e.getMessage()); } for (Window window : JFrame.getWindows()) { SwingUtilities.updateComponentTreeUI(window); // window.pack(); } }
From source file:com.newtifry.android.remote.BackendRequest.java
/** * Fire off this request in a thread in the background. * @param context The context for this request. * @param statusMessage If provided, show a progress dialog with this message. If NULL, no progress dialog is shown. * @param accountName The account name to perform the request under. */// www . j a va2s. c om public void startInThread(final Context context, final String statusMessage, final String accountName) { // Set up the dialog. if (statusMessage != null) { this.dialog = ProgressDialog.show(context, context.getString(R.string.app_name), statusMessage, true); } // Create a new thread. Thread thread = new Thread() { public void run() { // Create a client. BackendClient client = new BackendClient(context, accountName); BackendResponse result; try { Log.i(TAG, "Beginning request..."); // dumpRequest(); result = client.request(thisRequest); // Was it successful? if (result.isError()) { Log.d(TAG, "Error: " + result.getError()); } else { Log.d(TAG, "Success! Server returned: " + result.getJSON().toString()); } // Prepare the message to send back. Message message = Message.obtain(); message.obj = result; // Post it to ourselves - it will then post it back to the real thread. handler.sendMessage(message); } catch (Exception e) { Log.e(TAG, "Generic exception: " + e.getMessage() + " of type " + e.getClass().toString()); } } }; // And start the request. thread.start(); }
From source file:com.adaptris.core.fs.FsConsumer.java
/** * @see com.adaptris.core.AdaptrisComponent#init() *///from w w w . j a v a2 s.co m @Override public void init() throws CoreException { try { if (resetWipFiles()) { renameWipFiles(); } } catch (Exception e) { if (CoreException.class.isAssignableFrom(e.getClass())) { throw (CoreException) e; } else { throw new CoreException(e); } } super.init(); }
From source file:com.acc.controller.BaseController.java
@ResponseStatus(value = HttpStatus.BAD_REQUEST) @ResponseBody//from w ww . j av a 2s. co m @ExceptionHandler(CustomValidationException.class) public ValidationErrorData handleValidationException(final Exception excp, final HttpServletRequest request, final Writer writer) { LOG.info("Handling Exception for this request - " + excp.getClass().getSimpleName() + " - " + excp.getMessage()); if (LOG.isDebugEnabled()) { LOG.debug(excp); } final ValidationErrorData errorData = handleValidationErrorInternal(excp.getClass().getSimpleName(), excp.getMessage(), ((CustomValidationException) excp).getErrors()); return errorData; }
From source file:dk.nsi.haiba.lprimporter.importer.ImportExecutor.java
public void doProcess(boolean manual) { log.info("Started processing, manual=" + isManualOverride()); // Fetch new records from LPR contact table try {/* www.ja v a 2 s.c o m*/ statusRepo.importStartedAt(new DateTime()); if (manual) { emailSender.sendHello(); } Collection<Codes> allUsedSygehusKoder = classificationCheckHelper.getSygehusKoder(); Collection<Codes> allRegisteredSygehusKoder = classificationCheckHelper.getRegisteredSygehusKoder(); // test is generally done with 'startswith' as the registered codes may have an extension with sygehus // initials and the allused don't Collection<Codes> allUsedProcedureKoder = classificationCheckHelper.getProcedureKoder(); Collection<Codes> allRegisteredProcedureKoder = classificationCheckHelper.getRegisteredProcedureKoder(); Collection<Codes> allUsedDiagnoseKoder = classificationCheckHelper.getDiagnoseKoder(); Collection<Codes> allRegisteredDiagnoseKoder = classificationCheckHelper.getRegisteredDiagnoseKoder(); Collection<Codes> newSygehusKoder = testNewKoder(allUsedSygehusKoder, allRegisteredSygehusKoder); Collection<Codes> newProcedureKoder = testNewKoder(allUsedProcedureKoder, allRegisteredProcedureKoder); Collection<Codes> newDiagnoseKoder = testNewKoder(allUsedDiagnoseKoder, allRegisteredDiagnoseKoder); // for sygehuskoder, find the initials addSygehusInitials(newSygehusKoder); classificationCheckHelper.check(newSygehusKoder, newDiagnoseKoder, newProcedureKoder); statusRepo.importEndedWithSuccess(new DateTime()); if (manual) { emailSender.sendDone(null); } } catch (Exception e) { log.error("", e); statusRepo.importEndedWithFailure(new DateTime(), e.getClass().getName()); if (manual) { emailSender.sendDone(ExceptionUtils.getStackTrace(e)); } } }
From source file:io.redlink.solrlib.cloud.SolrCloudConnector.java
@Override @SuppressWarnings({ "squid:S1141", "squid:S3776" }) protected void init(ExecutorService executorService) throws IOException, SolrServerException { final Path sharedLibs = Files.createTempDirectory("solrSharedLibs"); try (CloudSolrClient client = createSolrClient()) { /* NOTE: do not use as this breaks compatibility with lower Solr Versions * <code>final List<String> existingCollections = CollectionAdminRequest.listCollections(client);</code> *//*from w ww.j a v a 2 s . c om*/ @SuppressWarnings("unchecked") final List<String> existingCollections = (List<String>) new CollectionAdminRequest.List() .process(client).getResponse().get("collections"); for (SolrCoreDescriptor coreDescriptor : coreDescriptors) { final String coreName = coreDescriptor.getCoreName(); final String remoteName = createRemoteName(coreName); if (availableCores.containsKey(coreName)) { log.warn("CoreName-Clash: {} already initialized. Skipping {}", coreName, coreDescriptor.getClass()); continue; } else { log.info("Initializing Core {} (remote: {})", coreName, remoteName); } if (config.isDeployCores()) { final Path tmp = Files.createTempDirectory(coreName); try { coreDescriptor.initCoreDirectory(tmp, sharedLibs); uploadConfig(remoteName, tmp); if (!existingCollections.contains(remoteName)) { // TODO: Check and log the response final NamedList<Object> response = client.request(CollectionAdminRequest .createCollection(remoteName, remoteName, Math.max(1, coreDescriptor.getNumShards()), Math.max(2, coreDescriptor.getReplicationFactor())) .setMaxShardsPerNode(config.getMaxShardsPerNode())); log.debug("Created Collection {}, CoreAdminResponse: {}", coreName, response); scheduleCoreInit(executorService, coreDescriptor, true); } else { log.debug("Collection {} already exists in SolrCloud '{}' as {}", coreName, config.getZkConnection(), remoteName); // TODO: Check and log the response final NamedList<Object> response = client .request(CollectionAdminRequest.reloadCollection(remoteName)); log.debug("Reloaded Collection {}, CoreAdminResponse: {}", coreName, response); scheduleCoreInit(executorService, coreDescriptor, false); } availableCores.put(coreName, coreDescriptor); } catch (SolrServerException e) { log.debug("Initializing core {} ({}) failed: {}", coreName, remoteName, e.getMessage()); throw new IOException( String.format("Initializing collection %s (%s) failed", coreName, remoteName), e); } finally { PathUtils.deleteRecursive(tmp); } } else { if (existingCollections.contains(remoteName)) { log.debug("Collection {} exists in SolrCloud '{}' as {}", coreName, config.getZkConnection(), remoteName); scheduleCoreInit(executorService, coreDescriptor, false); availableCores.put(coreName, coreDescriptor); } else { log.warn( "Collection {} (remote: {}) not available in SolrCloud '{}' " + "but deployCores is set to false", coreName, remoteName, config.getZkConnection()); } } } log.info("Initialized {} collections in Solr-Cloud {}: {}", availableCores.size(), config.getZkConnection(), availableCores); } catch (IOException e) { throw e; } catch (SolrServerException e) { log.error("Could not list existing collections: {}", e.getMessage(), e); throw new IOException("Could not list existing collections", e); } catch (final Exception t) { log.error("Unexpected {} during init(): {}", t.getClass().getSimpleName(), t.getMessage(), t); throw t; } finally { PathUtils.deleteRecursive(sharedLibs); } }
From source file:com.notifry.android.remote.BackendRequest.java
/** * Fire off this request in a thread in the background. * @param context The context for this request. * @param statusMessage If provided, show a progress dialog with this message. If NULL, no progress dialog is shown. * @param accountName The account name to perform the request under. *///from www.ja va2 s . c om public void startInThread(final Context context, final String statusMessage, final String accountName) { // Set up the dialog. if (statusMessage != null) { this.dialog = ProgressDialog.show(context, context.getString(R.string.app_name), statusMessage, true); } // Create a new thread. Thread thread = new Thread() { public void run() { // Create a client. BackendClient client = new BackendClient(context, accountName); BackendResponse result; try { //Log.i(TAG, "Beginning request..."); result = client.request(thisRequest); // Was it successful? /*if( result.isError() ) { Log.e(TAG, "Error: " + result.getError()); } else { Log.e(TAG, "Success! Server returned: " + result.getJSON().toString()); }*/ // Prepare the message to send back. Message message = Message.obtain(); message.obj = result; // Post it to ourselves - it will then post it back to the real thread. handler.sendMessage(message); } catch (Exception e) { Log.e(TAG, "Generic exception: " + e.getMessage() + " of type " + e.getClass().toString()); } } }; // And start the request. thread.start(); }