-
-
Save voltgister/bdf935b49647c9889347 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.voltdb.exportclient; | |
| import java.io.IOException; | |
| import java.util.Properties; | |
| import org.voltcore.logging.VoltLogger; | |
| import org.voltdb.export.AdvertisedDataSource; | |
| import com.google_voltpatches.common.util.concurrent.ListeningExecutorService; | |
| public class PrinterExportClient extends ExportClientBase | |
| { | |
| private static final VoltLogger logger = new VoltLogger("ExportClient"); | |
| public PrinterExportClient() { | |
| logger.info("Creating Printer export client."); | |
| } | |
| @Override | |
| public void configure(Properties config) throws Exception { | |
| // passed deployment.xml export <configuration/> properties. | |
| } | |
| @Override | |
| public ExportDecoderBase constructExportDecoder(AdvertisedDataSource source) { | |
| // AdvertisedDataSource represents a <partition, table, generation> | |
| // triple. Partitions and tables are probably self-explanatory.Generations | |
| // are created across server reboots or schema changes so that old resources | |
| // are advertised until fully drained. The ExportClient's primary role is | |
| // to serve as a factory, providing concrete ExportDecoder implementations | |
| // for AdvertisedDataSources. | |
| return new PrinterExportDecoder(source); | |
| } | |
| static class PrinterExportDecoder extends ExportDecoderBase | |
| { | |
| PrinterExportDecoder(AdvertisedDataSource source) { | |
| super(source); | |
| } | |
| @Override | |
| public void sourceNoLongerAdvertised(AdvertisedDataSource source) { | |
| // The AdvertiseDataSource is no longer available. If file descriptors | |
| // or threads were allocated to handle the source, free them here. | |
| } | |
| @Override | |
| public void onBlockStart() throws RestartBlockException { | |
| // Default implementation is to do nothing | |
| // Override to provide per-block start handling. | |
| } | |
| @Override | |
| public boolean processRow(int rowSize, byte[] rowData) throws RestartBlockException { | |
| // Process row is the workhorse that handles each row of export data. | |
| try { | |
| // Process one row from the current block: useful export work goes here. | |
| ExportRowData pojo = this.decodeRow(rowData); | |
| System.out.println(pojo.values[0]); | |
| } catch (IOException e) { | |
| // throw restart with `true` to reject the block and apply back pressure. | |
| throw new RestartBlockException(true); | |
| } | |
| return true; // see ENG-5116 | |
| } | |
| @Override | |
| public void onBlockCompletion() throws RestartBlockException { | |
| // Default implementation is to do nothing. | |
| // Override to provide per-block end handling. | |
| } | |
| @Override | |
| public ListeningExecutorService getExecutor() { | |
| // By default, will return same-thread-executor. A note about threading | |
| // in the export client. Processing for an advertised data source is | |
| // done on an internal thread pool. You MUST NOT block the threads in | |
| // that pool. For example, Snapshots, Export overflow and other durability | |
| // mechanisms must schedule work on that thread pool to make progress. If | |
| // you block the default thread, you block Snapshot and Export overflow. | |
| // So -- either be kind -- or provide your own executor service here. | |
| return super.getExecutor(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment