Skip to content

Commit

Permalink
remove deprecated parserfactory methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Sep 10, 2023
1 parent 2d36dd7 commit 387d328
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 70 deletions.
69 changes: 2 additions & 67 deletions src/main/java/emissary/parser/ParserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
import emissary.config.ConfigUtil;
import emissary.config.Configurator;
import emissary.core.Factory;
import emissary.util.WindowedSeekableByteChannel;
import emissary.util.shell.Executrix;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;

/**
* Provide a factory for getting the proper type of input parser Provide the implementing classes for that match the
* configured Data Identifier Engine in both PARSER_IMPL_[type] and PARSER_NIO_IMPL_[type] variants if available. All
* configured parsers must implement emissary.parser.SessionParser.
* configured Data Identifier Engine in PARSER_NIO_IMPL_[type] variants if available. All configured parsers must
* implement emissary.parser.SessionParser.
*
* When no proper mappings are found or the specified parser cannot be instantiated, the SimpleParser and
* SimpleNioParser are used instead. If these cannot be instantiated, then something is likely seriously wrong.
Expand Down Expand Up @@ -110,53 +106,6 @@ public void reconfigure(@Nullable Configurator config) {
}
}

/**
* Make a session parser with the data
*
* @param data the bytes to parse
* @return SessionParser implementation
*/
@Deprecated
public SessionParser makeSessionParser(byte[] data) {
try {
WindowedSeekableByteChannel channel = new WindowedSeekableByteChannel(Channels.newChannel(new ByteArrayInputStream(data)), 1024 * 1024);
return makeSessionParser(channel);
} catch (IOException ex) {
logger.warn("Unable to instantiate channel");
throw new RuntimeException("Failed to instantiate WindowedSeekableByteChannel from byte[]", ex);
}
}

/**
* Make a session parser with the data of the specified data type
*
* @param type the data type
* @param data the bytes to parse
* @return SessionParser implementation
*/
@Deprecated
public SessionParser makeSessionParser(String type, byte[] data) {
try {
WindowedSeekableByteChannel channel = new WindowedSeekableByteChannel(Channels.newChannel(new ByteArrayInputStream(data)), 1024 * 1024);
return makeSessionParser(type, channel);
} catch (IOException ex) {
logger.warn("Unable to instantiate channel");
throw new RuntimeException("Failed to instantiate WindowedSeekableByteChannel from byte[]", ex);
}
}

/**
* Make a session parser with the data in the file. If no RAF parser is configured for the type of this data, a byte[]
* parser will be produced if there is one available.
*
* @param raf the data to be parsed
* @return SessionParser implementation
*/
@Deprecated
public SessionParser makeSessionParser(RandomAccessFile raf) {
return makeSessionParser(raf.getChannel());
}

/**
* Make a session parser with the data in channel. If no NIO parser is configured for the type of this data, a standard
* byte[] parser will be produced if there is one available and the size of the data in the channel is less than the
Expand Down Expand Up @@ -190,20 +139,6 @@ public SessionParser makeSessionParser(String type, SeekableByteChannel channel)
return sp;
}

/**
* Make a session parser with the data in the file. If no RAF parser is configured for the type of this data, a standard
* byte[] parser will be produced if there is one available.
*
* @param type the type of data
* @param raf the data to be parsed
* @return SessionParser implementation
*/
@Deprecated
public SessionParser makeSessionParser(String type, RandomAccessFile raf) {
return makeSessionParser(type, raf.getChannel());
}


/**
* Make a session parser for the specified data type with the args
*
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/emissary/pickup/PickUpPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
import emissary.pool.AgentPool;
import emissary.util.ClassComparator;
import emissary.util.TimeUtil;
import emissary.util.WindowedSeekableByteChannel;
import emissary.util.shell.Executrix;

import org.slf4j.MDC;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.nio.channels.Channels;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -625,7 +628,14 @@ public int processSessions(byte[] data, String fixedName, File theFile) {
int sessionNum = 0;

// Get the right type of session parser
SessionParser sp = parserFactory.makeSessionParser(data);
SessionParser sp;
try {
WindowedSeekableByteChannel channel = new WindowedSeekableByteChannel(Channels.newChannel(new ByteArrayInputStream(data)), 1024 * 1024);
sp = parserFactory.makeSessionParser(channel);
} catch (IOException e) {
logger.warn("Unable to instantiate channel");
throw new RuntimeException("Failed to instantiate WindowedSeekableByteChannel from byte[]", e);
}
logger.debug("Using session parser from byte ident {}", sp.getClass().getName());

// .. and a session producer to crank out the data objects...
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/emissary/parser/ParserFactory.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
# Set up some defaults
#
DEFAULT_PARSER = "emissary.parser.SimpleParser"
DEFAULT_NIO_PARSER = "emissary.parser.SimpleNioParser"

#
Expand All @@ -14,7 +13,6 @@ MAX_NIO_FALLBACK_SIZE = "100M"
# Any classes specified here must implement
# the interfact emissary.parser.SessionParser
#
PARSER_IMPL_simple = "emissary.parser.SimpleParser"
PARSER_NIO_IMPL_simple = "emissary.parser.SimpleNioParser"

#
Expand Down

0 comments on commit 387d328

Please sign in to comment.