List of usage examples for javax.management.openmbean TabularData size
public int size();
From source file:dk.netarkivet.common.utils.JMXUtils.java
/** Get a single CompositeData object out of a TabularData structure. * * @param items TabularData structure as returned from JMX calls. * @return The one item in the items structure. * @throws ArgumentNotValid if there is not exactly one item in items, * or items is null./* w w w . j a v a 2s .c om*/ */ public static CompositeData getOneCompositeData(TabularData items) { ArgumentNotValid.checkNotNull(items, "TabularData items"); ArgumentNotValid.checkTrue(items.size() == 1, "TabularData items should have 1 item"); return (CompositeData) items.values().toArray()[0]; }
From source file:com.adobe.acs.commons.httpcache.store.caffeine.impl.CaffeineMemHttpCacheStoreImplTest.java
@Test public void test_getCacheStats() throws OpenDataException, HttpCacheDataStreamException { HttpCacheConfig config = mock(HttpCacheConfig.class); CacheKey key = mock(CacheKey.class); CacheContent content = mock(CacheContent.class); InputStream inputStream = getClass().getResourceAsStream("cachecontent.html"); when(content.getInputDataStream()).thenReturn(inputStream); caffeine.put(key, content);/* ww w. j a v a 2 s .c om*/ TabularData data = caffeine.getCacheStats(); assertEquals(12, data.size()); }
From source file:com.adobe.acs.commons.httpcache.store.mem.impl.MemHttpCacheStoreImplTest.java
@Test public void test_getCacheStats() throws OpenDataException, HttpCacheDataStreamException { HttpCacheConfig config = mock(HttpCacheConfig.class); CacheKey key = mock(CacheKey.class); CacheContent content = mock(CacheContent.class); InputStream inputStream = getClass().getResourceAsStream("cachecontent.html"); when(content.getInputDataStream()).thenReturn(inputStream); systemUnderTest.put(key, content);/* w w w . j a v a2 s . c o m*/ TabularData data = systemUnderTest.getCacheStats(); assertEquals(12, data.size()); }
From source file:dk.netarkivet.harvester.harvesting.controller.JMXHeritrixController.java
/** Check if the crawl has ended, either because Heritrix finished * of its own, or because we terminated it. * * @return True if the crawl has ended, either because Heritrix finished * or because we terminated it. Otherwise we return false. * @see HeritrixController#crawlIsEnded() *///from w w w . j a v a 2s . c o m public synchronized boolean crawlIsEnded() { // End of crawl can be seen in one of three ways: // 1) The Heritrix process has exited. // 2) The job has been moved to the completed jobs list in Heritrix. // 3) The job is in one of the FINISHED states. if (processHasExited()) { return true; } TabularData jobs = (TabularData) executeHeritrixCommand(COMPLETED_JOBS_COMMAND); if (jobs != null && jobs.size() > 0) { for (CompositeData value : (Collection<CompositeData>) jobs.values()) { String thisJobID = value.get(JmxUtils.NAME) + "-" + value.get(UID_PROPERTY); if (thisJobID.equals(jobName)) { return true; } } } String status = (String) getCrawlJobAttribute(STATUS_ATTRIBUTE); return status == null || status.equals(FINISHED_STATUS) || status.equals(ILLEGAL_STATUS); }
From source file:dk.netarkivet.harvester.harvesting.controller.JMXHeritrixController.java
/** * @throws IOFailure If Heritrix dies before initialization, * or we encounter any problems during the initialization. * @see HeritrixController#initialize() */ public void initialize() { if (processHasExited()) { String errMsg = "Heritrix process of " + this + " died before initialization"; log.warn(errMsg);//www. jav a2 s . co m throw new IOFailure(errMsg); } // We want to be sure there are no jobs when starting, in case we got // an old Heritrix or somebody added jobs behind our back. TabularData doneJobs = (TabularData) executeHeritrixCommand(COMPLETED_JOBS_COMMAND); TabularData pendingJobs = (TabularData) executeHeritrixCommand(PENDING_JOBS_COMMAND); if (doneJobs != null && doneJobs.size() > 0 || pendingJobs != null && pendingJobs.size() > 0) { throw new IllegalState( "This Heritrix instance is in a illegalState! " + "This instance has either old done jobs (" + doneJobs + "), or old pending jobs (" + pendingJobs + ")."); } // From here on, we can assume there's only the one job we make. // We'll use the arc file prefix to name the job, since the prefix // already contains the harvest id and job id. HeritrixFiles files = getHeritrixFiles(); executeHeritrixCommand(ADD_JOB_COMMAND, files.getOrderXmlFile().getAbsolutePath(), files.getArchiveFilePrefix(), getJobDescription(), files.getSeedsTxtFile().getAbsolutePath()); jobName = getJobName(); initializeProgressStatisticsLegend(); }
From source file:dk.netarkivet.harvester.harvesting.controller.JMXHeritrixController.java
/** Get the name of the one job we let this Heritrix run. The handling * of done jobs depends on Heritrix not being in crawl. This call * may take several seconds to finish./*from w w w . j ava2 s.c o m*/ * * @return The name of the one job that Heritrix has. * @throws IOFailure if the job created failed to initialize or didn't * appear in time. * @throws IllegalState if more than one job in done list, * or more than one pending job */ private String getJobName() { /* This is called just after we've told Heritrix to create a job. * It may take a while before the job is actually created, so we have * to wait around a bit. */ TabularData pendingJobs = null; TabularData doneJobs; int retries = 0; while (retries++ < JMXUtils.getMaxTries()) { // If the job turns up in Heritrix' pending jobs list, it's ready pendingJobs = (TabularData) executeHeritrixCommand(PENDING_JOBS_COMMAND); if (pendingJobs != null && pendingJobs.size() > 0) { break; // It's ready, we can move on. } // If there's an error in the job configuration, the job will be put // in Heritrix' completed jobs list. doneJobs = (TabularData) executeHeritrixCommand(COMPLETED_JOBS_COMMAND); if (doneJobs != null && doneJobs.size() >= 1) { // Since we haven't allowed Heritrix to start any crawls yet, // the only way the job could have ended and then put into // the list of completed jobs is by error. if (doneJobs.size() > 1) { throw new IllegalState("More than one job in done list: " + doneJobs); } else { CompositeData job = JMXUtils.getOneCompositeData(doneJobs); throw new IOFailure("Job " + job + " failed: " + job.get(STATUS_ATTRIBUTE)); } } if (retries < JMXUtils.getMaxTries()) { TimeUtils.exponentialBackoffSleep(retries); } } // If all went well, we now have exactly one job in the pending // jobs list. if (pendingJobs == null || pendingJobs.size() == 0) { throw new IOFailure("Heritrix has not created a job after " + (Math.pow(2, JMXUtils.getMaxTries()) / 1000) + " seconds, giving up."); } else if (pendingJobs.size() > 1) { throw new IllegalState("More than one pending job: " + pendingJobs); } else { // Note that we may actually get through to here even if the job // is malformed. The job will then die as soon as we tell it to // start crawling. CompositeData job = JMXUtils.getOneCompositeData(pendingJobs); String name = job.get(JmxUtils.NAME) + "-" + job.get(UID_PROPERTY); log.info("Heritrix created a job with name " + name); return name; } }
From source file:dk.netarkivet.harvester.harvesting.controller.BnfHeritrixController.java
/** * Initialize the JMXconnection to the Heritrix. * @throws IOFailure// w w w. ja v a2 s. c om * If Heritrix dies before initialization, or we encounter any * problems during the initialization. * @see HeritrixController#initialize() */ @Override public void initialize() { if (processHasExited()) { String errMsg = "Heritrix process of " + this + " died before initialization"; log.warn(errMsg); throw new IOFailure(errMsg); } log.info("Abort, if we lose the connection " + "to Heritrix, is " + ABORT_IF_CONN_LOST); initJMXConnection(); log.info("JMX connection initialized successfully"); crawlServiceBeanName = "org.archive.crawler:" + JmxUtils.NAME + "=Heritrix," + JmxUtils.TYPE + "=CrawlService," + JmxUtils.JMX_PORT + "=" + getJmxPort() + "," + JmxUtils.GUI_PORT + "=" + getGuiPort() + "," + JmxUtils.HOST + "=" + getHostName(); // We want to be sure there are no jobs when starting, in case we got // an old Heritrix or somebody added jobs behind our back. TabularData doneJobs = (TabularData) executeMBeanOperation(CrawlServiceOperation.completedJobs); TabularData pendingJobs = (TabularData) executeMBeanOperation(CrawlServiceOperation.pendingJobs); if (doneJobs != null && doneJobs.size() > 0 || pendingJobs != null && pendingJobs.size() > 0) { throw new IllegalState( "This Heritrix instance is in a illegalState! " + "This instance has either old done jobs (" + doneJobs + "), or old pending jobs (" + pendingJobs + ")."); } // From here on, we can assume there's only the one job we make. // We'll use the arc file prefix to name the job, since the prefix // already contains the harvest id and job id. HeritrixFiles files = getHeritrixFiles(); executeMBeanOperation(CrawlServiceOperation.addJob, files.getOrderXmlFile().getAbsolutePath(), files.getArchiveFilePrefix(), getJobDescription(), files.getSeedsTxtFile().getAbsolutePath()); jobName = getJobName(); crawlServiceJobBeanName = "org.archive.crawler:" + JmxUtils.NAME + "=" + jobName + "," + JmxUtils.TYPE + "=CrawlService.Job," + JmxUtils.JMX_PORT + "=" + getJmxPort() + "," + JmxUtils.MOTHER + "=Heritrix," + JmxUtils.HOST + "=" + getHostName(); }
From source file:dk.netarkivet.harvester.harvesting.controller.BnfHeritrixController.java
/** * Get the name of the one job we let this Heritrix run. The handling of * done jobs depends on Heritrix not being in crawl. This call may take * several seconds to finish./*w w w . ja v a 2 s.co m*/ * * @return The name of the one job that Heritrix has. * @throws IOFailure * if the job created failed to initialize or didn't appear in * time. * @throws IllegalState * if more than one job in done list, or more than one pending * job */ private String getJobName() { /* * This is called just after we've told Heritrix to create a job. It may * take a while before the job is actually created, so we have to wait * around a bit. */ TabularData pendingJobs = null; TabularData doneJobs; int retries = 0; final int maxJmxRetries = JMXUtils.getMaxTries(); while (retries++ < maxJmxRetries) { // If the job turns up in Heritrix' pending jobs list, it's ready pendingJobs = (TabularData) executeMBeanOperation(CrawlServiceOperation.pendingJobs); if (pendingJobs != null && pendingJobs.size() > 0) { break; // It's ready, we can move on. } // If there's an error in the job configuration, the job will be put // in Heritrix' completed jobs list. doneJobs = (TabularData) executeMBeanOperation(CrawlServiceOperation.completedJobs); if (doneJobs != null && doneJobs.size() >= 1) { // Since we haven't allowed Heritrix to start any crawls yet, // the only way the job could have ended and then put into // the list of completed jobs is by error. if (doneJobs.size() > 1) { throw new IllegalState("More than one job in done list: " + doneJobs); } else { CompositeData job = JMXUtils.getOneCompositeData(doneJobs); throw new IOFailure( "Job " + job + " failed: " + job.get(CrawlServiceJobAttribute.Status.name())); } } if (retries < maxJmxRetries) { TimeUtils.exponentialBackoffSleep(retries); } } // If all went well, we now have exactly one job in the pending // jobs list. if (pendingJobs == null || pendingJobs.size() == 0) { throw new IOFailure("Heritrix has not created a job after " + (Math.pow(2, maxJmxRetries) / TimeUtils.SECOND_IN_MILLIS) + " seconds, giving up."); } else if (pendingJobs.size() > 1) { throw new IllegalState("More than one pending job: " + pendingJobs); } else { // Note that we may actually get through to here even if the job // is malformed. The job will then die as soon as we tell it to // start crawling. CompositeData job = JMXUtils.getOneCompositeData(pendingJobs); String name = job.get(JmxUtils.NAME) + "-" + job.get(UID_PROPERTY); log.info("Heritrix created a job with name " + name); return name; } }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopierTest.java
@Test public void basicTestWithFS() throws Exception { IndexDefinition defn = new IndexDefinition(root, builder.getNodeState()); IndexCopier c1 = new IndexCopier(sameThreadExecutor(), getWorkDir()); Directory remote = new RAMDirectory(); Directory wrapped = c1.wrapForRead("/foo", defn, remote); byte[] t1 = writeFile(remote, "t1"); byte[] t2 = writeFile(remote, "t2"); assertEquals(2, wrapped.listAll().length); assertTrue(wrapped.fileExists("t1")); assertTrue(wrapped.fileExists("t2")); assertEquals(t1.length, wrapped.fileLength("t1")); assertEquals(t2.length, wrapped.fileLength("t2")); readAndAssert(wrapped, "t1", t1); //t1 should now be added to testDir File indexDir = c1.getIndexDir(defn, "/foo"); assertTrue(new File(indexDir, "t1").exists()); TabularData td = c1.getIndexPathMapping(); assertEquals(1, td.size()); }
From source file:org.apache.qpid.systest.management.jmx.ConnectionManagementTest.java
private CompositeDataSupport getTheOneChannelRow(final ManagedConnection mBean) throws Exception { TabularData channelsData = getChannelsDataWithRetry(mBean); assertEquals("Unexpected number of rows in channel table", 1, channelsData.size()); @SuppressWarnings("unchecked") final Iterator<CompositeDataSupport> rowItr = (Iterator<CompositeDataSupport>) channelsData.values() .iterator();//from w w w . j a v a 2 s .co m final CompositeDataSupport row = rowItr.next(); return row; }