List of usage examples for javax.management AttributeNotFoundException getMessage
public String getMessage()
From source file:com.cyberway.issue.crawler.frontier.BdbFrontier.java
/** * Create a UriUniqFilter that will serve as record * of already seen URIs.//from w ww .j a va 2 s . co m * * @return A UURISet that will serve as a record of already seen URIs * @throws IOException */ protected UriUniqFilter createAlreadyIncluded() throws IOException { UriUniqFilter uuf; String c = null; try { c = (String) getAttribute(null, ATTR_INCLUDED); } catch (AttributeNotFoundException e) { // Do default action if attribute not in order. } // TODO: avoid all this special-casing; enable some common // constructor interface usable for all alt implemenations if (c != null && c.equals(BloomUriUniqFilter.class.getName())) { uuf = this.controller.isCheckpointRecover() ? deserializeAlreadySeen(BloomUriUniqFilter.class, this.controller.getCheckpointRecover().getDirectory()) : new BloomUriUniqFilter(); } else if (c != null && c.equals(MemFPMergeUriUniqFilter.class.getName())) { // TODO: add checkpointing for MemFPMergeUriUniqFilter uuf = new MemFPMergeUriUniqFilter(); } else if (c != null && c.equals(DiskFPMergeUriUniqFilter.class.getName())) { // TODO: add checkpointing for DiskFPMergeUriUniqFilter uuf = new DiskFPMergeUriUniqFilter(controller.getScratchDisk()); } else { // Assume its BdbUriUniqFilter. uuf = this.controller.isCheckpointRecover() ? deserializeAlreadySeen(BdbUriUniqFilter.class, this.controller.getCheckpointRecover().getDirectory()) : new BdbUriUniqFilter(this.controller.getBdbEnvironment()); if (this.controller.isCheckpointRecover()) { // If recover, need to call reopen of the db. try { ((BdbUriUniqFilter) uuf).reopen(this.controller.getBdbEnvironment()); } catch (DatabaseException e) { throw new IOException(e.getMessage()); } } } uuf.setDestination(this); return uuf; }
From source file:dk.netarkivet.harvester.tools.TwitterDecidingScope.java
/** * This routine makes any necessary Twitter API calls and queues the content discovered. * * @param controller The controller for this crawl. *//* w w w . jav a2 s.c o m*/ @Override public void initialize(CrawlController controller) { super.initialize(controller); twitter = (new TwitterFactory()).getInstance(); keywords = null; try { keywords = (StringList) super.getAttribute(ATTR_KEYWORDS); pages = ((Integer) super.getAttribute(ATTR_PAGES)).intValue(); geoLocations = (StringList) super.getAttribute(ATTR_GEOLOCATIONS); language = (String) super.getAttribute(ATTR_LANG); if (language == null) { language = "all"; } resultsPerPage = (Integer) super.getAttribute(ATTR_RESULTS_PER_PAGE); queueLinks = (Boolean) super.getAttribute(ATTR_QUEUE_LINKS); queueUserStatus = (Boolean) super.getAttribute(ATTR_QUEUE_USER_STATUS); queueUserStatusLinks = (Boolean) super.getAttribute(ATTR_QUEUE_USER_STATUS_LINKS); queueKeywordLinks = (Boolean) super.getAttribute(ATTR_QUEUE_KEYWORD_LINKS); } catch (AttributeNotFoundException e1) { e1.printStackTrace(); throw new RuntimeException(e1); } catch (MBeanException e1) { e1.printStackTrace(); throw new RuntimeException(e1); } catch (ReflectionException e1) { e1.printStackTrace(); throw new RuntimeException(e1); } for (Object keyword : keywords) { log.info("Twitter Scope keyword: {}", keyword); } // If keywords or geoLocations is missing, add a list with a single empty string so that the main loop is // executed at least once. if (keywords == null || keywords.isEmpty()) { keywords = new StringList("keywords", "empty keyword list", new String[] { "" }); } if (geoLocations == null || geoLocations.isEmpty()) { geoLocations = new StringList("geolocations", "empty geolocation list", new String[] { "" }); } log.info("Twitter Scope will queue {} page(s) of results.", pages); // Nested loop over keywords, geo_locations and pages. for (Object keyword : keywords) { String keywordString = (String) keyword; for (Object geoLocation : geoLocations) { String urlQuery = (String) keyword; Query query = new Query(); query.setRpp(resultsPerPage); if (language != null && !language.equals("")) { query.setLang(language); urlQuery += " lang:" + language; keywordString += " lang:" + language; } urlQuery = "http://twitter.com/search/" + URLEncoder.encode(urlQuery); if (queueKeywordLinks) { addSeedIfLegal(urlQuery); } for (int page = 1; page <= pages; page++) { query.setPage(page); if (!keyword.equals("")) { query.setQuery(keywordString); } if (!geoLocation.equals("")) { String[] locationArray = ((String) geoLocation).split(","); try { GeoLocation location = new GeoLocation(Double.parseDouble(locationArray[0]), Double.parseDouble(locationArray[1])); query.setGeoCode(location, Double.parseDouble(locationArray[2]), locationArray[3]); } catch (NumberFormatException e) { e.printStackTrace(); } } try { final QueryResult result = twitter.search(query); List<Tweet> tweets = result.getTweets(); for (Tweet tweet : tweets) { long id = tweet.getId(); String fromUser = tweet.getFromUser(); String tweetUrl = "http://www.twitter.com/" + fromUser + "/status/" + id; addSeedIfLegal(tweetUrl); tweetCount++; if (queueLinks) { extractEmbeddedLinks(tweet); } if (queueUserStatus) { String statusUrl = "http://twitter.com/" + tweet.getFromUser() + "/"; addSeedIfLegal(statusUrl); linkCount++; if (queueUserStatusLinks) { queueUserStatusLinks(tweet.getFromUser()); } } } } catch (TwitterException e1) { log.error(e1.getMessage()); } } } } System.out.println( TwitterDecidingScope.class + " added " + tweetCount + " tweets and " + linkCount + " other links."); }
From source file:org.archive.crawler.admin.CrawlJobHandler.java
/** * Creates a new settings handler based on an existing job. Basically all * the settings file for the 'based on' will be copied to the specified * directory.//from ww w . jav a 2 s .co m * * @param orderFile Order file to base new order file on. Cannot be null. * @param name Name for the new settings * @param description Description of the new settings. * @param seeds The contents of the new settings' seed file. * @param newSettingsDir * @param errorHandler * @param filename Name of new order file. * @param seedfile Name of new seeds file. * * @return The new settings handler. * @throws FatalConfigurationException * If there are problems with reading the 'base on' * configuration, with writing the new configuration or it's * seed file. */ protected XMLSettingsHandler createSettingsHandler(final File orderFile, final String name, final String description, final String seeds, final File newSettingsDir, final CrawlJobErrorHandler errorHandler, final String filename, final String seedfile) throws FatalConfigurationException { XMLSettingsHandler newHandler = null; try { newHandler = new XMLSettingsHandler(orderFile); if (errorHandler != null) { newHandler.registerValueErrorHandler(errorHandler); } newHandler.setErrorReportingLevel(errorHandler.getLevel()); newHandler.initialize(); } catch (InvalidAttributeValueException e2) { throw new FatalConfigurationException("InvalidAttributeValueException occured while creating" + " new settings handler for new job/profile\n" + e2.getMessage()); } // Make sure the directory exists. newSettingsDir.mkdirs(); try { // Set the seed file ((ComplexType) newHandler.getOrder().getAttribute("scope")) .setAttribute(new Attribute("seedsfile", seedfile)); } catch (AttributeNotFoundException e1) { throw new FatalConfigurationException( "AttributeNotFoundException occured while setting up" + "new job/profile\n" + e1.getMessage()); } catch (InvalidAttributeValueException e1) { throw new FatalConfigurationException("InvalidAttributeValueException occured while setting" + "up new job/profile\n" + e1.getMessage()); } catch (MBeanException e1) { throw new FatalConfigurationException( "MBeanException occured while setting up new" + " job/profile\n" + e1.getMessage()); } catch (ReflectionException e1) { throw new FatalConfigurationException( "ReflectionException occured while setting up" + " new job/profile\n" + e1.getMessage()); } File newFile = new File(newSettingsDir.getAbsolutePath(), filename); try { newHandler.copySettings(newFile, (String) newHandler.getOrder().getAttribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY)); } catch (IOException e3) { // Print stack trace to help debug issue where cannot create // new job from an old that has overrides. e3.printStackTrace(); throw new FatalConfigurationException("IOException occured while writing new settings files" + " for new job/profile\n" + e3.getMessage()); } catch (AttributeNotFoundException e) { throw new FatalConfigurationException("AttributeNotFoundException occured while writing new" + " settings files for new job/profile\n" + e.getMessage()); } catch (MBeanException e) { throw new FatalConfigurationException("MBeanException occured while writing new settings files" + " for new job/profile\n" + e.getMessage()); } catch (ReflectionException e) { throw new FatalConfigurationException("ReflectionException occured while writing new settings" + " files for new job/profile\n" + e.getMessage()); } CrawlerSettings orderfile = newHandler.getSettingsObject(null); orderfile.setName(name); orderfile.setDescription(description); if (seeds != null) { BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(newHandler.getPathRelativeToWorkingDirectory(seedfile)), "UTF-8")); try { writer.write(seeds); } finally { writer.close(); } } catch (IOException e) { throw new FatalConfigurationException( "IOException occured while writing seed file for new" + " job/profile\n" + e.getMessage()); } } return newHandler; }
From source file:org.archive.crawler.fetcher.OptimizeFetchHTTP.java
/** * Promote successful credential to the server. * * @param curi CrawlURI whose credentials we are to promote. *//*ww w .j ava 2s . co m*/ private void promoteCredentials(final CrawlURI curi) { if (!curi.hasCredentialAvatars()) { logger.error("No credentials to promote when there should be " + curi); } else { Set avatars = curi.getCredentialAvatars(); for (Iterator i = avatars.iterator(); i.hasNext();) { CredentialAvatar ca = (CredentialAvatar) i.next(); curi.removeCredentialAvatar(ca); // The server to attach too may not be the server that hosts // this passed curi. It might be of another subdomain. // The avatar needs to be added to the server that is dependent // on this precondition. Find it by name. Get the name from // the credential this avatar represents. Credential c = ca.getCredential(getSettingsHandler(), curi); String cd = null; try { cd = c.getCredentialDomain(curi); } catch (AttributeNotFoundException e) { logger.error("Failed to get cred domain for " + curi + " for " + ca + ": " + e.getMessage()); } if (cd != null) { CrawlServer cs = getController().getServerCache().getServerFor(cd); if (cs != null) { cs.addCredentialAvatar(ca); } } } } }
From source file:org.archive.crawler.fetcher.OptimizeFetchHTTP.java
private void setAcceptHeaders(CrawlURI curi, HttpMethod get) { try {//w w w.j a v a 2s . com StringList accept_headers = (StringList) getAttribute(ATTR_ACCEPT_HEADERS, curi); if (!accept_headers.isEmpty()) { for (ListIterator i = accept_headers.listIterator(); i.hasNext();) { String hdr = (String) i.next(); String[] nvp = hdr.split(": +"); if (nvp.length == 2) { get.setRequestHeader(nvp[0], nvp[1]); } else { logger.warn("Invalid accept header: " + hdr); } } } } catch (AttributeNotFoundException e) { logger.error(e.getMessage()); } }
From source file:org.hyperic.hq.plugin.jboss.JBossUtil.java
private static Object setAttribute(MBeanServerConnection mServer, ObjectName obj, String name, Object value) throws MetricUnreachableException, MetricNotFoundException, PluginException, ReflectionException, InstanceNotFoundException, MBeanException, IOException { if (name.startsWith("set")) { name = name.substring(3);/*from w w w . j a v a 2s .c o m*/ } Attribute attr = new Attribute(name, value); try { mServer.setAttribute(obj, attr); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (InvalidAttributeValueException e) { throw new ReflectionException(e); } return null; }
From source file:org.hyperic.hq.plugin.weblogic.WeblogicServiceControlPlugin.java
protected Object invoke(MBeanServerConnection mServer, String objectName, String method, Object[] args, String[] sig) throws MetricUnreachableException, MetricNotFoundException, PluginException { ObjectName obj;/* w ww . j av a 2 s. c o m*/ try { obj = new ObjectName(objectName); } catch (MalformedObjectNameException e1) { throw new PluginException("Unable to create an ObjectName from " + objectName); } MBeanInfo info; try { info = mServer.getMBeanInfo(obj); } catch (Exception e1) { throw new PluginException("Unable to obtain MBeanInfo from " + objectName); } if (sig.length == 0) { MBeanUtil.OperationParams params = MBeanUtil.getOperationParams(info, method, args); if (params.isAttribute) { if (method.startsWith("set")) { try { mServer.setAttribute(obj, new Attribute(method.substring(3), params.arguments[0])); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e); } return null; } else { try { return mServer.getAttribute(obj, method.substring(3)); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e); } } } sig = params.signature; args = params.arguments; } try { return mServer.invoke(obj, method, args, sig); } catch (Exception e) { throw new PluginException(e); } }
From source file:org.hyperic.hq.plugin.websphere.WebsphereServiceControlPlugin.java
protected Object invoke(AdminClient mServer, String objectName, String method, Object[] args, String[] sig) throws MetricUnreachableException, MetricNotFoundException, PluginException { ObjectName obj;/*w w w .jav a 2s. c o m*/ try { obj = new ObjectName(objectName); } catch (MalformedObjectNameException e1) { throw new PluginException("Unable to create an ObjectName from " + objectName); } MBeanInfo info; try { info = mServer.getMBeanInfo(obj); } catch (Exception e1) { throw new PluginException("Unable to obtain MBeanInfo from " + objectName); } if (sig.length == 0) { MBeanUtil.OperationParams params = MBeanUtil.getOperationParams(info, method, args); if (params.isAttribute) { if (method.startsWith("set")) { try { mServer.setAttribute(obj, new Attribute(method.substring(3), params.arguments[0])); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e); } return null; } else { try { return mServer.getAttribute(obj, method.substring(3)); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } catch (Exception e) { throw new PluginException(e); } } } sig = params.signature; args = params.arguments; } try { return mServer.invoke(obj, method, args, sig); } catch (Exception e) { throw new PluginException(e); } }
From source file:org.hyperic.hq.plugin.websphere.WebsphereUtil.java
public static double getMBeanCount(AdminClient mServer, ObjectName query, String attr) throws MetricUnreachableException, MetricNotFoundException { double count = 0; try {/*from www. j a v a 2s.c om*/ Set beansSet = mServer.queryNames(query, null); for (Iterator it = beansSet.iterator(); it.hasNext();) { ObjectName name = (ObjectName) it.next(); try { if (attr != null) { mServer.getAttribute(name, attr); } count++; } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(name.toString()); } catch (InstanceNotFoundException e) { throw new MetricNotFoundException(name.toString()); } catch (Exception e) { //e.g. unauthorized throw new MetricUnreachableException(name + ": " + e.getMessage(), e); } } } catch (ConnectorException e) { throw new MetricUnreachableException(query.toString(), e); } if (count == 0) { throw new MetricNotFoundException(query + " (Invalid node name?)"); } return count; }
From source file:org.hyperic.hq.product.jmx.MxUtil.java
private static Object getAttribute(MBeanServerConnection mServer, ObjectName obj, String name) throws MetricUnreachableException, MetricNotFoundException, PluginException, ReflectionException, InstanceNotFoundException, MBeanException, IOException { if (name.startsWith("get")) { name = name.substring(3);/*from w w w .j a va 2s. c o m*/ } try { return mServer.getAttribute(obj, name); } catch (AttributeNotFoundException e) { throw new MetricNotFoundException(e.getMessage(), e); } }