/** {@inheritDoc} */ @Override public FijiTableReader openTableReader() { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot open a table reader on a FijiTable in state %s.", state); try { return HBaseFijiTableReader.create(this); } catch (IOException ioe) { throw new FijiIOException(ioe); } }
/** {@inheritDoc} */ @Override public FijiTableWriter openTableWriter() { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot open a table writer on a FijiTable in state %s.", state); try { return new HBaseFijiTableWriter(this); } catch (IOException ioe) { throw new FijiIOException(ioe); } }
/** {@inheritDoc} */ @Override public CassandraFijiTableReader openTableReader() { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot open a table reader on a FijiTable in state %s.", state); try { return CassandraFijiTableReader.create(this); } catch (IOException ioe) { throw new FijiIOException(ioe); } }
/** {@inheritDoc} */ @Override public Entry<T> next() { final Entry<T> entry = mNext; if (entry == null) { throw new NoSuchElementException(); } try { mNext = getNext(); } catch (IOException ioe) { throw new FijiIOException(ioe); } return entry; }
/** {@inheritDoc} */ @Override public Iterator<FijiCell<T>> iterator() { try { return new FijiCellIterator<T>( mRowData, mColumnName, mHBaseColumnNameTranslator); } catch (IOException ex) { throw new FijiIOException(ex); } } }
/** {@inheritDoc} */ @Override public FijiTableWriter openTableWriter() { final State state = mState.get(); Preconditions.checkState(state == State.OPEN, "Cannot open a table writer on a FijiTable in state %s.", state); try { return new CassandraFijiTableWriter(this); } catch (IOException ioe) { throw new FijiIOException(ioe); } }
/** {@inheritDoc} */ @Override public FijiCell<T> next() { final FijiCell<T> next = mNextCell; if (null == next) { throw new NoSuchElementException(); } else { try { mNextCell = getNextCell(); } catch (IOException ioe) { throw new FijiIOException(ioe); } return next; } }
/** {@inheritDoc} */ @Override public Entry<Long, T> next() { final Entry<Long, T> entry = mNext; if (entry == null) { throw new NoSuchElementException(); } try { mNext = getNext(); } catch (IOException ioe) { throw new FijiIOException(ioe); } return entry; }
/** * Get the next HBase Result from the ResultScanner, reopening the scanner if necessary. * * @return the next HBase Result from the ResultScanner. */ private Result getNextResult() { for (int retries = 0; retries < MAX_RETRIES_ON_TIMEOUT; ++retries) { try { return mResultScanner.next(); } catch (LeaseException le) { reopenScanner(); } catch (ScannerTimeoutException ste) { reopenScanner(); } catch (IOException ioe) { throw new FijiIOException(ioe); } } throw new FijiIOException(String.format( "Unable to get Result from HBase scanner after %d attempts.", MAX_RETRIES_ON_TIMEOUT)); }
/** * Factory for ZooKeeper session clients. * * <p> This returns immediately, but the ZooKeeper session is established asynchronously. </p> * * @throws FijiIOException on I/O error. */ private void createZKClient() { LOG.debug("Creating new ZooKeeper client for address {} in {}.", mZKAddress, this); try { synchronized (mMonitor) { mZKClient = new ZooKeeper(mZKAddress, SESSION_TIMEOUT, new SessionWatcher()); } } catch (IOException ioe) { throw new FijiIOException(ioe); } }
/** {@inheritDoc} */ @Override public HConnection getHConnection(Fiji fiji) { try { return HConnectionManager.createConnection(fiji.getConf()); } catch (IOException ioe) { throw new FijiIOException("Couldn't create an HConnection.", ioe); } }
/** * Deserialize a {@code FijiRowFilter} from JSON that has been constructed * using {@link #toJson}. * * @param json A JSON String created by {@link #toJson} * @return A {@code FijiRowFilter} represented by the JSON * @throws FijiIOException in case the json cannot be read or the filter * cannot be instantiated */ public static FijiRowFilter toFilter(String json) { final ObjectMapper mapper = new ObjectMapper(); try { final JsonNode root = mapper.readTree(json); return toFilter(root); } catch (IOException ioe) { throw new FijiIOException(ioe); } }
/** {@inheritDoc} */ @Override public Long apply(AvroSchema avroSchema) { if (avroSchema.getJson() != null) { final Schema schema = new Schema.Parser().parse(avroSchema.getJson()); try { return mSchemaTable.getOrCreateSchemaId(schema); } catch (IOException ioe) { throw new FijiIOException(ioe); } } else if (avroSchema.getUid() != null) { return avroSchema.getUid(); } else { throw new FijiIOException( "AvroSchema neither has a schema UID nor a schema JSON descriptor."); } } }
/** {@inheritDoc} */ @Override public void close() throws IOException { try { super.close(); } catch (IOException ioe) { throw ioe; } catch (Exception e) { throw new FijiIOException(e); } mFactory.mFactoryDelegate.getTable().release(); }
/** {@inheritDoc} */ @Override public FijiCell<T> apply(final KeyValue keyValue) { try { final DecodedCell<T> decodedCell = mCellDecoder.decodeCell(keyValue.getValue()); return FijiCell.create(mColumnName, keyValue.getTimestamp(), decodedCell); } catch (IOException e) { throw new FijiIOException(e); } } }
/** {@inheritDoc} */ @Override public TableLayoutDesc apply(final FijiTableLayout refLayout) { Preconditions.checkNotNull(refLayout); try { final TableLayoutDesc refDesc = refLayout.getDesc(); return new TableLayoutBuilder(refDesc, fiji) .withLayoutId(nextLayoutId(refDesc.getLayoutId())) .withWriter(column, writerSchema) .withWritten(column, writerSchema) .build(); } catch (InvalidLayoutException ile) { LOG.error("Internal error while updating table layout in DEVELOPER mode: {}", ile); throw new InternalFijiError(ile); } catch (IOException ioe) { LOG.error("I/O error while updating table layout in DEVELOPER mode: {}", ioe); throw new FijiIOException(ioe); } } };
@Override /** {@inheritDoc} */ public TableLayoutMonitor apply(String tableName) { final FijiURI tableURI = FijiURI.newBuilder(mInstanceURI).withTableName(tableName).build(); try { return new DefaultTableLayoutMonitor(tableURI, mSchemaTable, mMetaTable, mZKClient).start(); } catch (IOException e) { throw new FijiIOException(e); } } }
/** {@inheritDoc} */ @Override public FijiCell<T> apply(final Row row) { try { final DecodedCell<T> decodedCell = mCellDecoder.decodeCell(ByteUtils.toBytes(row.getBytes(CQLUtils.VALUE_COL))); return FijiCell.create(mColumnName, row.getLong(CQLUtils.VERSION_COL), decodedCell); } catch (IOException e) { throw new FijiIOException(e); } } }
/** {@inheritDoc} */ @Override protected JsonNode toJsonNode() { final ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(FAMILY_NODE, mFamily); root.put(QUALIFIER_NODE, mQualifier); final ObjectNode value = root.with(VALUE_NODE); // Schema's documentation for toString says it is rendered as JSON. value.put(SCHEMA_NODE, mValue.getWriterSchema().toString()); try { value.put(DATA_NODE, ToJson.toAvroJsonString(mValue.getData(), mValue.getWriterSchema())); } catch (IOException ioe) { throw new FijiIOException(ioe); } return root; }
/** {@inheritDoc} */ @Override public FijiRowFilter createFromJson(JsonNode root) { final String family = root.path(FAMILY_NODE).getTextValue(); final String qualifier = root.path(QUALIFIER_NODE).getTextValue(); final String schema = root.path(VALUE_NODE).path(SCHEMA_NODE).getTextValue(); final Schema writerSchema = (new Schema.Parser()).parse(schema); final String data = root.path(VALUE_NODE).path(DATA_NODE).getTextValue(); try { final DecodedCell<?> cell = new DecodedCell<Object>(writerSchema, FromJson.fromAvroJsonString(data, writerSchema)); return new ColumnValueEqualsRowFilter(family, qualifier, cell); } catch (IOException ioe) { throw new FijiIOException(ioe); } } }