- java.lang.Object
-
- dev.bitbite.networking.DataPreProcessor
-
public class DataPreProcessor extends java.lang.ObjectKeeps track of allDataProcessingLayers and processes data by passing it to each layer and returning its result. Layers will process the data in the order they are registered.- See Also:
DataProcessingLayer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataPreProcessor.TransferModeThe Transfer directions data can travel
-
Constructor Summary
Constructors Modifier Constructor Description protectedDataPreProcessor()Instantiates the DataPreProcessor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLayer(DataPreProcessor.TransferMode mode, int index, DataProcessingLayer layer)Inserts a layer at the specified index.voidaddLayer(DataPreProcessor.TransferMode mode, DataProcessingLayer layer)Appends a layer at the end of the listDataProcessingLayergetLayerAt(DataPreProcessor.TransferMode mode, int index)Returns a layer of the specified transfermode at a specified position in the list.java.util.ArrayList<DataProcessingLayer>getLayers(DataPreProcessor.TransferMode mode)Returns the list of layersvoidinitLayers()Initializes theDataProcessingLayersprotected byte[]process(DataPreProcessor.TransferMode mode, byte[] data)Sends the data to each registeredDataProcessingLayerIf no DataProcessingLayer is registered, data will stay as it is and returns the processed datavoidremoveLayer(DataPreProcessor.TransferMode mode, DataProcessingLayer layer)Removes a layer from the listvoidshutdown()Deactivates theDataProcessingLayers
-
-
-
Method Detail
-
process
protected byte[] process(DataPreProcessor.TransferMode mode, byte[] data)
Sends the data to each registeredDataProcessingLayerIf no DataProcessingLayer is registered, data will stay as it is and returns the processed data- Parameters:
mode- - transfer direction of the datadata- to process- Returns:
- processed data
-
initLayers
public void initLayers() throws LayerInitFailedExceptionInitializes theDataProcessingLayers- Throws:
LayerInitFailedException- ifDataProcessingLayer.onEnable()returns false
-
shutdown
public void shutdown() throws LayerDisableFailedExceptionDeactivates theDataProcessingLayers- Throws:
LayerDisableFailedException- ifDataProcessingLayer.onDisable()returns false
-
addLayer
public void addLayer(DataPreProcessor.TransferMode mode, DataProcessingLayer layer)
Appends a layer at the end of the list- Parameters:
mode- - the transfermode the layer is designed forlayer- -DataProcessingLayerto add
-
addLayer
public void addLayer(DataPreProcessor.TransferMode mode, int index, DataProcessingLayer layer)
Inserts a layer at the specified index. Shifts the layer currently at that position (if any) and any subsequent layers to the right (adds one to their indices).- Parameters:
mode- - the transfermode the layer is designed forindex- to add the layer atlayer- -DataProcessingLayerto add
-
getLayerAt
public DataProcessingLayer getLayerAt(DataPreProcessor.TransferMode mode, int index)
Returns a layer of the specified transfermode at a specified position in the list.- Parameters:
mode- - the transfermode of the layer to getindex- of the layer to get- Returns:
- layer -
DataProcessingLayerat given index
-
removeLayer
public void removeLayer(DataPreProcessor.TransferMode mode, DataProcessingLayer layer)
Removes a layer from the list- Parameters:
mode- - the transfermode of the layer to removelayer- -DataProcessingLayerto remove
-
getLayers
public java.util.ArrayList<DataProcessingLayer> getLayers(DataPreProcessor.TransferMode mode)
Returns the list of layers- Parameters:
mode- - the transfermode of the layer to remove- Returns:
- ArrayList of
DataProcessingLayers
-
-