List of usage examples for javax.management RuntimeOperationsException RuntimeOperationsException
public RuntimeOperationsException(java.lang.RuntimeException e, String message)
RuntimeOperationsException
that wraps the actual java.lang.RuntimeException
with a detailed message. From source file:catalina.mbeans.ContextResourceMBean.java
/** * Obtain and return the value of a specific attribute of this MBean. * * @param name Name of the requested attribute * * @exception AttributeNotFoundException if this attribute is not * supported by this MBean//from w ww .j ava 2 s . c o m * @exception MBeanException if the initializer of an object * throws an exception * @exception ReflectionException if a Java reflection exception * occurs when invoking the getter */ public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException { // Validate the input parameters if (name == null) throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null"); ContextResource cr = null; try { cr = (ContextResource) getManagedResource(); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } String value = null; if ("auth".equals(name)) { return (cr.getAuth()); } else if ("description".equals(name)) { return (cr.getDescription()); } else if ("name".equals(name)) { return (cr.getName()); } else if ("scope".equals(name)) { return (cr.getScope()); } else if ("type".equals(name)) { return (cr.getType()); } else { NamingResources nr = cr.getNamingResources(); if (nr == null) { throw new AttributeNotFoundException("Cannot find naming resource " + cr.getName()); } ResourceParams rp = nr.findResourceParams(cr.getName()); if (rp == null) { throw new AttributeNotFoundException("Cannot find resource param " + cr.getName()); } value = (String) rp.getParameters().get(name); if (value == null) { throw new AttributeNotFoundException("Cannot find attribute " + name + rp); } } return value; }
From source file:catalina.mbeans.ContextResourceMBean.java
/** * Set the value of a specific attribute of this MBean. * * @param attribute The identification of the attribute to be set * and the new value/*from ww w.java 2 s . c o m*/ * * @exception AttributeNotFoundException if this attribute is not * supported by this MBean * @exception MBeanException if the initializer of an object * throws an exception * @exception ReflectionException if a Java reflection exception * occurs when invoking the getter */ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { // Validate the input parameters if (attribute == null) throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null"); String name = attribute.getName(); Object value = attribute.getValue(); if (name == null) throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null"); ContextResource cr = null; try { cr = (ContextResource) getManagedResource(); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } if ("auth".equals(name)) { cr.setAuth((String) value); } else if ("description".equals(name)) { cr.setDescription((String) value); } else if ("name".equals(name)) { cr.setName((String) value); } else if ("scope".equals(name)) { cr.setScope((String) value); } else if ("type".equals(name)) { cr.setType((String) value); } else { ResourceParams rp = cr.getNamingResources().findResourceParams(cr.getName()); if (rp != null) { String valueStr = "" + value; rp.addParameter(name, valueStr); cr.getNamingResources().removeResourceParams(cr.getName()); } else { rp = new ResourceParams(); rp.setName(cr.getName()); String valueStr = "" + value; rp.addParameter(name, valueStr); } cr.getNamingResources().addResourceParams(rp); } // cannot use side-efects. It's removed and added back each time // there is a modification in a resource. NamingResources nr = cr.getNamingResources(); nr.removeResource(cr.getName()); nr.addResource(cr); }
From source file:com.cyberway.issue.crawler.admin.CrawlJob.java
public Object getAttribute(String attribute_name) throws AttributeNotFoundException { if (attribute_name == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot call getAttribute with null attribute name"); }/*ww w.j a va2 s. co m*/ // If no controller, we can't do any work in here. if (this.controller == null) { throw new RuntimeOperationsException(new NullPointerException("Controller is null"), "Controller is null"); } // Is it a bdbje attribute? if (this.bdbjeAttributeNameList.contains(attribute_name)) { try { return this.bdbjeMBeanHelper.getAttribute(this.controller.getBdbEnvironment(), attribute_name); } catch (MBeanException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } // Is it a crawl-order attribute? if (attribute_name.startsWith(this.controller.getOrder().getAbsoluteName())) { return getCrawlOrderAttribute(attribute_name); } if (!ATTRIBUTE_LIST.contains(attribute_name)) { throw new AttributeNotFoundException("Attribute " + attribute_name + " is unimplemented."); } // The pattern in the below is to match an attribute and when found // do a return out of if clause. Doing it this way, I can fall // on to the AttributeNotFoundException for case where we've an // attribute but no handler. if (attribute_name.equals(STATUS_ATTR)) { return getCrawlStatus(); } if (attribute_name.equals(NAME_ATTR)) { return getJobName(); } if (attribute_name.equals(UID_ATTR)) { return getUID(); } if (attribute_name.equals(TOTAL_DATA_ATTR)) { return new Long(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().totalBytesWritten()); } if (attribute_name.equals(CRAWL_TIME_ATTR)) { return new Long(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().getCrawlerTotalElapsedTime() / 1000); } if (attribute_name.equals(CURRENT_DOC_RATE_ATTR)) { return new Double(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().currentProcessedDocsPerSec()); } if (attribute_name.equals(DOC_RATE_ATTR)) { return new Double(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().processedDocsPerSec()); } if (attribute_name.equals(KB_RATE_ATTR)) { return new Long(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().currentProcessedKBPerSec()); } if (attribute_name.equals(CURRENT_KB_RATE_ATTR)) { return new Long(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().processedKBPerSec()); } if (attribute_name.equals(THREAD_COUNT_ATTR)) { return new Integer(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().activeThreadCount()); } if (attribute_name.equals(FRONTIER_SHORT_REPORT_ATTR)) { return getFrontierOneLine(); } if (attribute_name.equals(THREADS_SHORT_REPORT_ATTR)) { return getThreadOneLine(); } if (attribute_name.equals(DISCOVERED_COUNT_ATTR)) { return new Long(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().totalCount()); } if (attribute_name.equals(DOWNLOAD_COUNT_ATTR)) { return new Long(this.controller == null && this.controller.getStatistics() != null ? 0 : this.controller.getStatistics().successfullyFetchedCount()); } throw new AttributeNotFoundException("Attribute " + attribute_name + " not found."); }
From source file:com.cyberway.issue.crawler.admin.CrawlJob.java
public AttributeList getAttributes(String[] attributeNames) { if (attributeNames == null) { throw new RuntimeOperationsException( new IllegalArgumentException("attributeNames[] cannot be " + "null"), "Cannot call getAttributes with null attribute " + "names"); }/*from w w w . ja v a2 s . c o m*/ // If no controller, we can't do any work in here. if (this.controller == null) { throw new RuntimeOperationsException(new NullPointerException("Controller is null"), "Controller is null"); } AttributeList resultList = new AttributeList(); if (attributeNames.length == 0) { return resultList; } for (int i = 0; i < attributeNames.length; i++) { try { Object value = getAttribute(attributeNames[i]); resultList.add(new Attribute(attributeNames[i], value)); } catch (Exception e) { e.printStackTrace(); } } return (resultList); }
From source file:com.cyberway.issue.crawler.admin.CrawlJob.java
public AttributeList setAttributes(AttributeList attributes) { if (attributes == null) { throw new RuntimeOperationsException( new IllegalArgumentException("attributeNames[] cannot be " + "null"), "Cannot call getAttributes with null attribute " + "names"); }/*from w ww . j a va 2s . c o m*/ AttributeList resultList = new AttributeList(); if (attributes.size() == 0) { return resultList; } for (int i = 0; i < attributes.size(); i++) { try { Attribute attr = (Attribute) attributes.get(i); setAttribute(attr); String an = attr.getName(); Object newValue = getAttribute(an); resultList.add(new Attribute(an, newValue)); } catch (Exception e) { e.printStackTrace(); } } return resultList; }
From source file:com.cyberway.issue.crawler.admin.CrawlJob.java
public Object invoke(String operationName, Object[] params, String[] signature) throws ReflectionException { if (operationName == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Operation name cannot be null"), "Cannot call invoke with null operation name"); }// ww w. j a va 2 s .co m controller.installThreadContextSettingsHandler(); if (this.bdbjeOperationsNameList.contains(operationName)) { try { Object o = this.bdbjeMBeanHelper.invoke(this.controller.getBdbEnvironment(), operationName, params, signature); // If OP_DB_ST, return String version of result. if (operationName.equals(OP_DB_STAT)) { return o.toString(); } return o; } catch (MBeanException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } // TODO: Exploit passed signature. // The pattern in the below is to match an operation and when found // do a return out of if clause. Doing it this way, I can fall // on to the MethodNotFoundException for case where we've an // attribute but no handler. if (operationName.equals(IMPORT_URI_OPER)) { JmxUtils.checkParamsCount(IMPORT_URI_OPER, params, 3); mustBeCrawling(); try { importUri((String) params[0], ((Boolean) params[1]).booleanValue(), ((Boolean) params[2]).booleanValue()); } catch (URIException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } return null; } if (operationName.equals(IMPORT_URIS_OPER)) { JmxUtils.checkParamsCount(IMPORT_URIS_OPER, params, 4); mustBeCrawling(); return importUris((String) params[0], ((String) params[1]).toString(), ((Boolean) params[2]).booleanValue(), ((Boolean) params[3]).booleanValue()); } if (operationName.equals(DUMP_URIS_OPER)) { JmxUtils.checkParamsCount(DUMP_URIS_OPER, params, 4); mustBeCrawling(); if (!this.controller.isPaused()) { throw new RuntimeOperationsException(new IllegalArgumentException("Must " + "be paused"), "Cannot dump URI's from running job."); } dumpUris((String) params[0], (String) params[1], ((Integer) params[2]).intValue(), ((Boolean) params[3]).booleanValue()); } if (operationName.equals(PAUSE_OPER)) { JmxUtils.checkParamsCount(PAUSE_OPER, params, 0); mustBeCrawling(); pause(); return null; } if (operationName.equals(RESUME_OPER)) { JmxUtils.checkParamsCount(RESUME_OPER, params, 0); mustBeCrawling(); resume(); return null; } if (operationName.equals(FRONTIER_REPORT_OPER)) { JmxUtils.checkParamsCount(FRONTIER_REPORT_OPER, params, 1); mustBeCrawling(); return getFrontierReport((String) params[0]); } if (operationName.equals(THREADS_REPORT_OPER)) { JmxUtils.checkParamsCount(THREADS_REPORT_OPER, params, 0); mustBeCrawling(); return getThreadsReport(); } if (operationName.equals(SEEDS_REPORT_OPER)) { JmxUtils.checkParamsCount(SEEDS_REPORT_OPER, params, 0); mustBeCrawling(); StringWriter sw = new StringWriter(); if (getStatisticsTracking() != null && getStatisticsTracking() instanceof StatisticsTracker) { ((StatisticsTracker) getStatisticsTracking()).writeSeedsReportTo(new PrintWriter(sw)); } else { sw.write("Unsupported"); } return sw.toString(); } if (operationName.equals(CHECKPOINT_OPER)) { JmxUtils.checkParamsCount(CHECKPOINT_OPER, params, 0); mustBeCrawling(); try { checkpoint(); } catch (IllegalStateException e) { throw new RuntimeOperationsException(e); } return null; } if (operationName.equals(PROGRESS_STATISTICS_OPER)) { JmxUtils.checkParamsCount(PROGRESS_STATISTICS_OPER, params, 0); mustBeCrawling(); return getStatisticsTracking().getProgressStatisticsLine(); } if (operationName.equals(PROGRESS_STATISTICS_LEGEND_OPER)) { JmxUtils.checkParamsCount(PROGRESS_STATISTICS_LEGEND_OPER, params, 0); return getStatisticsTracking().progressStatisticsLegend(); } throw new ReflectionException(new NoSuchMethodException(operationName), "Cannot find the operation " + operationName); }
From source file:com.cyberway.issue.crawler.admin.CrawlJob.java
public void mustBeCrawling() { if (!isCrawling()) { throw new RuntimeOperationsException( new IllegalArgumentException("Not " + "crawling (Shouldn't ever be the case)"), "Not current crawling job?"); }/*from w ww . ja va2 s .c om*/ }
From source file:com.cyberway.issue.crawler.Heritrix.java
public Object getAttribute(String attribute_name) throws AttributeNotFoundException { if (attribute_name == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name cannot be null"), "Cannot call getAttribute with null attribute name"); }//w ww .j a va2s . c o m if (!Heritrix.ATTRIBUTE_LIST.contains(attribute_name)) { throw new AttributeNotFoundException("Attribute " + attribute_name + " is unimplemented."); } // The pattern in the below is to match an attribute and when found // do a return out of if clause. Doing it this way, I can fall // on to the AttributeNotFoundException for case where we've an // attribute but no handler. if (attribute_name.equals(STATUS_ATTR)) { return getStatus(); } if (attribute_name.equals(VERSION_ATTR)) { return getVersion(); } if (attribute_name.equals(ISRUNNING_ATTR)) { return new Boolean(this.getJobHandler().isRunning()); } if (attribute_name.equals(ISCRAWLING_ATTR)) { return new Boolean(this.getJobHandler().isCrawling()); } if (attribute_name.equals(ALERTCOUNT_ATTR)) { return new Integer(getAlertsCount()); } if (attribute_name.equals(NEWALERTCOUNT_ATTR)) { return new Integer(getNewAlertsCount()); } if (attribute_name.equals(CURRENTJOB_ATTR)) { if (this.getJobHandler().isCrawling()) { return this.getJobHandler().getCurrentJob().getJmxJobName(); } return null; } throw new AttributeNotFoundException("Attribute " + attribute_name + " not found."); }
From source file:com.cyberway.issue.crawler.Heritrix.java
public AttributeList getAttributes(String[] attributeNames) { if (attributeNames == null) { throw new RuntimeOperationsException( new IllegalArgumentException("attributeNames[] cannot be " + "null"), "Cannot call getAttributes with null attribute " + "names"); }/*w w w . j a v a 2 s. c o m*/ AttributeList resultList = new AttributeList(); if (attributeNames.length == 0) { return resultList; } for (int i = 0; i < attributeNames.length; i++) { try { Object value = getAttribute(attributeNames[i]); resultList.add(new Attribute(attributeNames[i], value)); } catch (Exception e) { e.printStackTrace(); } } return (resultList); }
From source file:com.cyberway.issue.crawler.Heritrix.java
public Object invoke(final String operationName, final Object[] params, final String[] signature) throws ReflectionException { if (operationName == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Operation name cannot be null"), "Cannot call invoke with null operation name"); }/* ww w . j av a 2 s. co m*/ // INFO logging of JMX invokes: [#HER-907] if (logger.isLoggable(Level.INFO)) { String paramsString = ""; for (Object o : params) { paramsString.concat("[" + o.toString() + "]"); } logger.info("JMX invoke: " + operationName + " [" + paramsString + "]"); } // The pattern in the below is to match an operation and when found // do a return out of if clause. Doing it this way, I can fall // on to the MethodNotFoundException for case where we've an // attribute but no handler. if (operationName.equals(START_OPER)) { JmxUtils.checkParamsCount(START_OPER, params, 0); start(); return null; } if (operationName.equals(STOP_OPER)) { JmxUtils.checkParamsCount(STOP_OPER, params, 0); stop(); return null; } if (operationName.equals(DESTROY_OPER)) { JmxUtils.checkParamsCount(DESTROY_OPER, params, 0); destroy(); return null; } if (operationName.equals(TERMINATE_CRAWL_JOB_OPER)) { JmxUtils.checkParamsCount(TERMINATE_CRAWL_JOB_OPER, params, 0); return new Boolean(this.jobHandler.terminateCurrentJob()); } if (operationName.equals(REBIND_JNDI_OPER)) { JmxUtils.checkParamsCount(REBIND_JNDI_OPER, params, 0); try { registerContainerJndi(); } catch (MalformedObjectNameException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } catch (UnknownHostException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } catch (NamingException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } return null; } if (operationName.equals(SHUTDOWN_OPER)) { JmxUtils.checkParamsCount(SHUTDOWN_OPER, params, 0); Heritrix.shutdown(); return null; } if (operationName.equals(LOG_OPER)) { JmxUtils.checkParamsCount(LOG_OPER, params, 2); logger.log(Level.parse((String) params[0]), (String) params[1]); return null; } if (operationName.equals(INTERRUPT_OPER)) { JmxUtils.checkParamsCount(INTERRUPT_OPER, params, 1); return interrupt((String) params[0]); } if (operationName.equals(START_CRAWLING_OPER)) { JmxUtils.checkParamsCount(START_CRAWLING_OPER, params, 0); startCrawling(); return null; } if (operationName.equals(STOP_CRAWLING_OPER)) { JmxUtils.checkParamsCount(STOP_CRAWLING_OPER, params, 0); stopCrawling(); return null; } if (operationName.equals(ADD_CRAWL_JOB_OPER)) { JmxUtils.checkParamsCount(ADD_CRAWL_JOB_OPER, params, 4); try { return addCrawlJob((String) params[0], (String) params[1], checkForEmptyPlaceHolder((String) params[2]), checkForEmptyPlaceHolder((String) params[3])); } catch (IOException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } catch (FatalConfigurationException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } if (operationName.equals(DELETE_CRAWL_JOB_OPER)) { JmxUtils.checkParamsCount(DELETE_CRAWL_JOB_OPER, params, 1); this.jobHandler.deleteJob((String) params[0]); return null; } if (operationName.equals(ADD_CRAWL_JOB_BASEDON_OPER)) { JmxUtils.checkParamsCount(ADD_CRAWL_JOB_BASEDON_OPER, params, 4); return addCrawlJobBasedOn((String) params[0], (String) params[1], checkForEmptyPlaceHolder((String) params[2]), checkForEmptyPlaceHolder((String) params[3])); } if (operationName.equals(ALERT_OPER)) { JmxUtils.checkParamsCount(ALERT_OPER, params, 1); SinkHandlerLogRecord slr = null; if (this.alertManager.getCount() > 0) { // This is creating a vector of all alerts just so I can then // use passed index into resultant vector -- needs to be // improved. slr = (SinkHandlerLogRecord) this.alertManager.getAll().get(((Integer) params[0]).intValue()); } return (slr != null) ? slr.toString() : null; } if (operationName.equals(PENDING_JOBS_OPER)) { JmxUtils.checkParamsCount(PENDING_JOBS_OPER, params, 0); try { return makeJobsTabularData(getJobHandler().getPendingJobs()); } catch (OpenDataException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } if (operationName.equals(COMPLETED_JOBS_OPER)) { JmxUtils.checkParamsCount(COMPLETED_JOBS_OPER, params, 0); try { return makeJobsTabularData(getJobHandler().getCompletedJobs()); } catch (OpenDataException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } if (operationName.equals(CRAWLEND_REPORT_OPER)) { JmxUtils.checkParamsCount(CRAWLEND_REPORT_OPER, params, 2); try { return getCrawlendReport((String) params[0], (String) params[1]); } catch (IOException e) { throw new RuntimeOperationsException(new RuntimeException(e)); } } throw new ReflectionException(new NoSuchMethodException(operationName), "Cannot find the operation " + operationName); }