@Override public boolean isReady() { if (signalManager != null) { long readyTimestamp = signalManager.getReadyTimestamp(getConstraints()); return readyTimestamp != -1; } return false; } }
@Override public void signalReady() { if (signalManager != null) { signalManager.signalReady(getConstraints()); } }
@Override public long getLastModified() { long lastMod = -1; for (Iterator<Path> i = dirIterator(); i.hasNext(); ) { Path dir = i.next(); try { for (FileStatus st : fs.listStatus(dir)) { if (lastMod < st.getModificationTime()) { lastMod = st.getModificationTime(); } } } catch (IOException e) { throw new DatasetIOException("Cannot find last modified time of of " + dir, e); } } // if view was marked ready more recently count it as the modified time if (signalManager != null) { long readyTimestamp = signalManager.getReadyTimestamp(getConstraints()); if (lastMod < readyTimestamp) { lastMod = readyTimestamp; } } return lastMod; }
@Override public boolean canReplace(View<E> part) { if (part instanceof FileSystemView) { return equals(part.getDataset()) && ((FileSystemView) part).getConstraints().alignedWithBoundaries(); } else if (part instanceof FileSystemDataset) { return equals(part); } return false; }
@Test public void testViewConstraints() { DatasetRepository repo = DatasetRepositories.repositoryFor("repo:file:/tmp/data"); repo.delete("ns", "test"); repo.create("ns", "test", descriptor); RefinableView<Record> v = Datasets.<Record, RefinableView<Record>> load("view:file:/tmp/data/ns/test?username=user", Record.class); Assert.assertNotNull("Should load view", v); Assert.assertTrue(v instanceof FileSystemView); Assert.assertEquals("Locations should match", URI.create("file:/tmp/data/ns/test"), v.getDataset().getDescriptor().getLocation()); DatasetDescriptor loaded = repo.load("ns", "test").getDescriptor(); Assert.assertEquals("Descriptors should match", loaded, v.getDataset().getDescriptor()); Assert.assertEquals("Should report correct namespace", "ns", v.getDataset().getNamespace()); Assert.assertEquals("Should report correct name", "test", v.getDataset().getName()); Constraints withUser = new Constraints(loaded.getSchema()) .with("username", new Utf8("user")); Assert.assertEquals("Constraints should be username=user", withUser, ((FileSystemView) v).getConstraints()); repo.delete("ns", "test"); }