Search in sources :

Example 1 with MessageFilter

use of co.rsk.net.eth.MessageFilter in project rskj by rsksmart.

the class RskSystemProperties method getMessageRecorder.

public MessageRecorder getMessageRecorder() {
    if (messageRecorder != null) {
        return messageRecorder;
    }
    if (!hasMessageRecorderEnabled()) {
        return null;
    }
    String database = this.databaseDir();
    String filename = "messages";
    Path filePath;
    if (Paths.get(database).isAbsolute()) {
        filePath = Paths.get(database, filename);
    } else {
        filePath = Paths.get(System.getProperty("user.dir"), database, filename);
    }
    String fullFilename = filePath.toString();
    MessageFilter filter = new MessageFilter(this.getMessageRecorderCommands());
    try {
        messageRecorder = new WriterMessageRecorder(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fullFilename), StandardCharsets.UTF_8)), filter);
    } catch (IOException ex) {
        logger.error("Exception creating message recorder: ", ex);
    }
    return messageRecorder;
}
Also used : Path(java.nio.file.Path) WriterMessageRecorder(co.rsk.net.eth.WriterMessageRecorder) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) MessageFilter(co.rsk.net.eth.MessageFilter) BufferedWriter(java.io.BufferedWriter)

Example 2 with MessageFilter

use of co.rsk.net.eth.MessageFilter in project rskj by rsksmart.

the class RskContext method getMessageRecorder.

private MessageRecorder getMessageRecorder() {
    if (writerMessageRecorder == null) {
        RskSystemProperties rskSystemProperties = getRskSystemProperties();
        if (!rskSystemProperties.hasMessageRecorderEnabled()) {
            return null;
        }
        Path filePath = FileUtil.getDatabaseDirectoryPath(rskSystemProperties.databaseDir(), "messages");
        String fullFilename = filePath.toString();
        MessageFilter filter = new MessageFilter(rskSystemProperties.getMessageRecorderCommands());
        try {
            // This resource needs to remain open when method returns, so LGTM warning is disabled.
            writerMessageRecorder = new WriterMessageRecorder(new BufferedWriter(// lgtm [java/output-resource-leak]
            new OutputStreamWriter(new FileOutputStream(fullFilename), StandardCharsets.UTF_8)), filter);
        } catch (IOException ex) {
            throw new IllegalArgumentException("Can't use this path to record messages", ex);
        }
    }
    return writerMessageRecorder;
}
Also used : Path(java.nio.file.Path) WriterMessageRecorder(co.rsk.net.eth.WriterMessageRecorder) MessageFilter(co.rsk.net.eth.MessageFilter)

Aggregations

MessageFilter (co.rsk.net.eth.MessageFilter)2 WriterMessageRecorder (co.rsk.net.eth.WriterMessageRecorder)2 Path (java.nio.file.Path)2 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1