@Override public void writeSnapshot(OutputStream out, TransactionSnapshot snapshot) throws IOException { codec.encode(out, snapshot); }
@Override public void encode(OutputStream out, TransactionSnapshot snapshot) { SnapshotCodec codec = getCurrentCodec(); try { new BinaryEncoder(out).writeInt(codec.getVersion()); } catch (IOException e) { LOG.error("Unable to write transaction state version: ", e); throw Throwables.propagate(e); } codec.encode(out, snapshot); }
@Override public int getVersion() { return getCurrentCodec().getVersion(); }
@Override public TransactionSnapshot decode(InputStream in) { return getCodec(in).decode(in); }
@Override public TransactionVisibilityState decodeTransactionVisibilityState(InputStream in) { return getCodec(in).decodeTransactionVisibilityState(in); }
/** * Register all codec specified in the configuration with this provider. * There can only be one codec for a given version. */ private void initialize(Configuration configuration) { String[] codecClassNames = configuration.getTrimmedStrings(TxConstants.Persist.CFG_TX_SNAPHOT_CODEC_CLASSES); List<Class> codecClasses = Lists.newArrayList(); if (codecClassNames != null) { for (String clsName : codecClassNames) { try { codecClasses.add(Class.forName(clsName)); } catch (ClassNotFoundException cnfe) { LOG.warn("Unable to load class configured for " + TxConstants.Persist.CFG_TX_SNAPHOT_CODEC_CLASSES + ": " + clsName, cnfe); } } } if (codecClasses.size() == 0) { codecClasses.addAll(Arrays.asList(TxConstants.Persist.DEFAULT_TX_SNAPHOT_CODEC_CLASSES)); } for (Class<?> codecClass : codecClasses) { try { SnapshotCodec codec = (SnapshotCodec) (codecClass.newInstance()); codecs.put(codec.getVersion(), codec); LOG.debug("Using snapshot codec {} for snapshots of version {}", codecClass.getName(), codec.getVersion()); } catch (Exception e) { LOG.warn("Error instantiating snapshot codec {}. Skipping.", codecClass.getName(), e); } } }