Commit 6412e227 authored by Gary Gregory's avatar Gary Gregory
Browse files

Use final.

parent 39c4b5c2
Showing with 141 additions and 139 deletions
+141 -139
......@@ -65,6 +65,7 @@ public final class MapRewritePolicy implements RewritePolicy {
}
@SuppressWarnings("unchecked")
final
MapMessage<?, Object> mapMsg = (MapMessage<?, Object>) msg;
final Map<String, Object> newMap = new HashMap<>(mapMsg.getData());
switch (mode) {
......
......@@ -47,7 +47,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle {
this(SIMPLE_NAME);
}
public ConfigurationScheduler(String name) {
public ConfigurationScheduler(final String name) {
super();
this.name = name;
}
......
......@@ -140,7 +140,7 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
*
* @return this builder
*/
public B setStacktraceAsString(boolean stacktraceAsString) {
public B setStacktraceAsString(final boolean stacktraceAsString) {
this.stacktraceAsString = stacktraceAsString;
return asBuilder();
}
......
......@@ -49,8 +49,8 @@ public final class Activator implements BundleActivator, SynchronousBundleListen
@Override
public void start(final BundleContext context) throws Exception {
Provider provider = new Log4jProvider();
Hashtable<String, String> props = new Hashtable<>();
final Provider provider = new Log4jProvider();
final Hashtable<String, String> props = new Hashtable<>();
props.put("APIVersion", "2.60");
provideRegistration = context.registerService(Provider.class.getName(), provider, props);
// allow the user to override the default ContextSelector (e.g., by using BasicContextSelector for a global cfg)
......@@ -73,7 +73,7 @@ public final class Activator implements BundleActivator, SynchronousBundleListen
}
private static void scanBundleForPlugins(final Bundle bundle) {
long bundleId = bundle.getBundleId();
final long bundleId = bundle.getBundleId();
// LOG4J2-920: don't scan system bundle for plugins
if (bundle.getState() == Bundle.ACTIVE && bundleId != 0) {
LOGGER.trace("Scanning bundle [{}, id=%d] for plugins.", bundle.getSymbolicName(), bundleId);
......
......@@ -27,34 +27,34 @@ import java.io.IOException;
class AbstractJacksonLogEventParser implements TextLogEventParser {
private final ObjectReader objectReader;
AbstractJacksonLogEventParser(ObjectMapper objectMapper) {
AbstractJacksonLogEventParser(final ObjectMapper objectMapper) {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
this.objectReader = objectMapper.readerFor(Log4jLogEvent.class);
}
@Override
public LogEvent parseFrom(String input) throws ParseException {
public LogEvent parseFrom(final String input) throws ParseException {
try {
return objectReader.readValue(input);
} catch (IOException e) {
} catch (final IOException e) {
throw new ParseException(e);
}
}
@Override
public LogEvent parseFrom(byte[] input) throws ParseException {
public LogEvent parseFrom(final byte[] input) throws ParseException {
try {
return objectReader.readValue(input);
} catch (IOException e) {
} catch (final IOException e) {
throw new ParseException(e);
}
}
@Override
public LogEvent parseFrom(byte[] input, int offset, int length) throws ParseException {
public LogEvent parseFrom(final byte[] input, final int offset, final int length) throws ParseException {
try {
return objectReader.readValue(input, offset, length);
} catch (IOException e) {
} catch (final IOException e) {
throw new ParseException(e);
}
}
......
......@@ -23,15 +23,15 @@ public class ParseException extends Exception {
private static final long serialVersionUID = -2739649998196663857L;
public ParseException(String message) {
public ParseException(final String message) {
super(message);
}
public ParseException(String message, Throwable cause) {
public ParseException(final String message, final Throwable cause) {
super(message, cause);
}
public ParseException(Throwable cause) {
public ParseException(final Throwable cause) {
super(cause);
}
}
......@@ -77,7 +77,7 @@ public class ScriptManager implements FileWatcher, Serializable {
final List<ScriptEngineFactory> factories = manager.getEngineFactories();
if (logger.isDebugEnabled()) {
final StringBuilder sb = new StringBuilder();
int factorySize = factories.size();
final int factorySize = factories.size();
logger.debug("Installed {} script engine{}", factorySize, factorySize != 1 ? "s" : Strings.EMPTY);
for (final ScriptEngineFactory factory : factories) {
String threading = (String) factory.getParameter(KEY_THREADING);
......@@ -85,7 +85,7 @@ public class ScriptManager implements FileWatcher, Serializable {
threading = "Not Thread Safe";
}
final StringBuilder names = new StringBuilder();
List<String> languageNames = factory.getNames();
final List<String> languageNames = factory.getNames();
for (final String name : languageNames) {
if (names.length() > 0) {
names.append(", ");
......
......@@ -47,7 +47,7 @@ public class AbstractStringLayoutTest {
@Test
public void testGetStringBuilderCapacityRestrictedToMax() throws Exception {
final StringBuilder sb = ConcreteStringLayout.getStringBuilder();
int initialCapacity = sb.capacity();
final int initialCapacity = sb.capacity();
assertEquals("initial capacity", ConcreteStringLayout.DEFAULT_STRING_BUILDER_SIZE, sb.capacity());
final int SMALL = 100;
......
......@@ -82,7 +82,7 @@ public class JsonLogEventParserTest extends LogEventParserTest {
@Test
public void testString() throws ParseException {
LogEvent logEvent = parser.parseFrom(JSON);
final LogEvent logEvent = parser.parseFrom(JSON);
assertLogEvent(logEvent);
}
......@@ -118,14 +118,14 @@ public class JsonLogEventParserTest extends LogEventParserTest {
@Test
public void testByteArray() throws ParseException {
LogEvent logEvent = parser.parseFrom(JSON.getBytes(StandardCharsets.UTF_8));
final LogEvent logEvent = parser.parseFrom(JSON.getBytes(StandardCharsets.UTF_8));
assertLogEvent(logEvent);
}
@Test
public void testByteArrayOffsetLength() throws ParseException {
byte[] bytes = ("abc" + JSON + "def").getBytes(StandardCharsets.UTF_8);
LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
final byte[] bytes = ("abc" + JSON + "def").getBytes(StandardCharsets.UTF_8);
final LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
assertLogEvent(logEvent);
}
......
......@@ -28,7 +28,7 @@ import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public abstract class LogEventParserTest {
protected void assertLogEvent(LogEvent logEvent) {
protected void assertLogEvent(final LogEvent logEvent) {
assertThat(logEvent, is(notNullValue()));
assertThat(logEvent.getTimeMillis(), equalTo(1493121664118L));
assertThat(logEvent.getThreadName(), equalTo("main"));
......
......@@ -82,7 +82,7 @@ public class XmlLogEventParserTest extends LogEventParserTest {
@Test
public void testString() throws ParseException {
LogEvent logEvent = parser.parseFrom(XML);
final LogEvent logEvent = parser.parseFrom(XML);
assertLogEvent(logEvent);
}
......@@ -113,14 +113,14 @@ public class XmlLogEventParserTest extends LogEventParserTest {
@Test
public void testByteArray() throws ParseException {
LogEvent logEvent = parser.parseFrom(XML.getBytes(StandardCharsets.UTF_8));
final LogEvent logEvent = parser.parseFrom(XML.getBytes(StandardCharsets.UTF_8));
assertLogEvent(logEvent);
}
@Test
public void testByteArrayOffsetLength() throws ParseException {
byte[] bytes = ("abc" + XML + "def").getBytes(StandardCharsets.UTF_8);
LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
final byte[] bytes = ("abc" + XML + "def").getBytes(StandardCharsets.UTF_8);
final LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
assertLogEvent(logEvent);
}
......
......@@ -76,7 +76,7 @@ public class YamlLogEventParserTest extends LogEventParserTest {
@Test
public void testString() throws ParseException {
LogEvent logEvent = parser.parseFrom(YAML);
final LogEvent logEvent = parser.parseFrom(YAML);
assertLogEvent(logEvent);
}
......@@ -107,14 +107,14 @@ public class YamlLogEventParserTest extends LogEventParserTest {
@Test
public void testByteArray() throws ParseException {
LogEvent logEvent = parser.parseFrom(YAML.getBytes(StandardCharsets.UTF_8));
final LogEvent logEvent = parser.parseFrom(YAML.getBytes(StandardCharsets.UTF_8));
assertLogEvent(logEvent);
}
@Test
public void testByteArrayOffsetLength() throws ParseException {
byte[] bytes = ("abc" + YAML + "def").getBytes(StandardCharsets.UTF_8);
LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
final byte[] bytes = ("abc" + YAML + "def").getBytes(StandardCharsets.UTF_8);
final LogEvent logEvent = parser.parseFrom(bytes, 3, bytes.length - 6);
assertLogEvent(logEvent);
}
......
......@@ -134,6 +134,7 @@ public class FlumeEvent extends SimpleEvent implements LogEvent {
if (message instanceof MapMessage) {
// Add the guid to the Map so that it can be included in the Layout.
@SuppressWarnings("unchecked")
final
MapMessage<?, String> stringMapMessage = (MapMessage<?, String>) message;
stringMapMessage.put(GUID, guid);
if (message instanceof StructuredDataMessage) {
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.nosql.appender.mongodb;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.appender.AppenderLoggingException;
import org.apache.logging.log4j.nosql.appender.AbstractNoSqlConnection;
import org.apache.logging.log4j.nosql.appender.NoSqlConnection;
import org.apache.logging.log4j.nosql.appender.NoSqlObject;
import org.apache.logging.log4j.status.StatusLogger;
import org.bson.BSON;
import org.bson.Transformer;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoException;
import com.mongodb.WriteConcern;
/**
* The MongoDB implementation of {@link NoSqlConnection}.
*/
public final class MongoDbConnection extends AbstractNoSqlConnection<BasicDBObject, MongoDbObject> {
private static final Logger LOGGER = StatusLogger.getLogger();
static {
BSON.addEncodingHook(Level.class, new Transformer() {
@Override
public Object transform(final Object o) {
if (o instanceof Level) {
return ((Level) o).name();
}
return o;
}
});
}
private final DBCollection collection;
private final WriteConcern writeConcern;
public MongoDbConnection(final DB database, final WriteConcern writeConcern, final String collectionName,
final Boolean isCapped, final Integer collectionSize) {
if (database.collectionExists(collectionName)) {
collection = database.getCollection(collectionName);
} else {
BasicDBObject options = new BasicDBObject();
options.put("capped", isCapped);
options.put("size", collectionSize);
this.collection = database.createCollection(collectionName, options);
}
this.writeConcern = writeConcern;
}
@Override
public MongoDbObject createObject() {
return new MongoDbObject();
}
@Override
public MongoDbObject[] createList(final int length) {
return new MongoDbObject[length];
}
@Override
public void insertObject(final NoSqlObject<BasicDBObject> object) {
try {
this.collection.insert(object.unwrap(), this.writeConcern);
} catch (final MongoException e) {
throw new AppenderLoggingException("Failed to write log event to MongoDB due to error: " + e.getMessage(),
e);
}
}
@Override
public void closeImpl() {
// LOG4J2-1196
this.collection.getDB().getMongo().close();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache license, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/
package org.apache.logging.log4j.nosql.appender.mongodb;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.appender.AppenderLoggingException;
import org.apache.logging.log4j.nosql.appender.AbstractNoSqlConnection;
import org.apache.logging.log4j.nosql.appender.NoSqlConnection;
import org.apache.logging.log4j.nosql.appender.NoSqlObject;
import org.apache.logging.log4j.status.StatusLogger;
import org.bson.BSON;
import org.bson.Transformer;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoException;
import com.mongodb.WriteConcern;
/**
* The MongoDB implementation of {@link NoSqlConnection}.
*/
public final class MongoDbConnection extends AbstractNoSqlConnection<BasicDBObject, MongoDbObject> {
private static final Logger LOGGER = StatusLogger.getLogger();
static {
BSON.addEncodingHook(Level.class, new Transformer() {
@Override
public Object transform(final Object o) {
if (o instanceof Level) {
return ((Level) o).name();
}
return o;
}
});
}
private final DBCollection collection;
private final WriteConcern writeConcern;
public MongoDbConnection(final DB database, final WriteConcern writeConcern, final String collectionName,
final Boolean isCapped, final Integer collectionSize) {
if (database.collectionExists(collectionName)) {
collection = database.getCollection(collectionName);
} else {
final BasicDBObject options = new BasicDBObject();
options.put("capped", isCapped);
options.put("size", collectionSize);
this.collection = database.createCollection(collectionName, options);
}
this.writeConcern = writeConcern;
}
@Override
public MongoDbObject createObject() {
return new MongoDbObject();
}
@Override
public MongoDbObject[] createList(final int length) {
return new MongoDbObject[length];
}
@Override
public void insertObject(final NoSqlObject<BasicDBObject> object) {
try {
this.collection.insert(object.unwrap(), this.writeConcern);
} catch (final MongoException e) {
throw new AppenderLoggingException("Failed to write log event to MongoDB due to error: " + e.getMessage(),
e);
}
}
@Override
public void closeImpl() {
// LOG4J2-1196
this.collection.getDB().getMongo().close();
}
}
......@@ -172,62 +172,62 @@ public final class MongoDbProvider implements NoSqlProvider<MongoDbConnection> {
@PluginBuilderAttribute
private String writeConcernConstant;
public B setServer(String server) {
public B setServer(final String server) {
this.server = server;
return asBuilder();
}
public B setPort(String port) {
public B setPort(final String port) {
this.port = port;
return asBuilder();
}
public B setDatabaseName(String databaseName) {
public B setDatabaseName(final String databaseName) {
this.databaseName = databaseName;
return asBuilder();
}
public B setCollectionName(String collectionName) {
public B setCollectionName(final String collectionName) {
this.collectionName = collectionName;
return asBuilder();
}
public B setUserName(String userName) {
public B setUserName(final String userName) {
this.userName = userName;
return asBuilder();
}
public B setPassword(String password) {
public B setPassword(final String password) {
this.password = password;
return asBuilder();
}
public B setCapped(boolean isCapped) {
public B setCapped(final boolean isCapped) {
this.isCapped = isCapped;
return asBuilder();
}
public B setCollectionSize(int collectionSize) {
public B setCollectionSize(final int collectionSize) {
this.collectionSize = collectionSize;
return asBuilder();
}
public B setFactoryClassName(String factoryClassName) {
public B setFactoryClassName(final String factoryClassName) {
this.factoryClassName = factoryClassName;
return asBuilder();
}
public B setFactoryMethodName(String factoryMethodName) {
public B setFactoryMethodName(final String factoryMethodName) {
this.factoryMethodName = factoryMethodName;
return asBuilder();
}
public B setWriteConcernConstantClassName(String writeConcernConstantClassName) {
public B setWriteConcernConstantClassName(final String writeConcernConstantClassName) {
this.writeConcernConstantClassName = writeConcernConstantClassName;
return asBuilder();
}
public B setWriteConcernConstant(String writeConcernConstant) {
public B setWriteConcernConstant(final String writeConcernConstant) {
this.writeConcernConstant = writeConcernConstant;
return asBuilder();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment