"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/filter/AbstractFilterable.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

AbstractFilterable.java  (apache-log4j-2.11.1-src):AbstractFilterable.java  (apache-log4j-2.11.2-src)
skipping to change at line 26 skipping to change at line 26
*/ */
package org.apache.logging.log4j.core.filter; package org.apache.logging.log4j.core.filter;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.core.AbstractLifeCycle; import org.apache.logging.log4j.core.AbstractLifeCycle;
import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LifeCycle2; import org.apache.logging.log4j.core.LifeCycle2;
import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginElement;
/** /**
* Enhances a Class by allowing it to contain Filters. * Enhances a Class by allowing it to contain Filters.
*/ */
public abstract class AbstractFilterable extends AbstractLifeCycle implements Fi lterable { public abstract class AbstractFilterable extends AbstractLifeCycle implements Fi lterable {
/** /**
* Subclasses can extend this abstract Builder. * Subclasses can extend this abstract Builder.
* *
* @param <B> The type to build. * @param <B> The type to build.
*/ */
public abstract static class Builder<B extends Builder<B>> { public abstract static class Builder<B extends Builder<B>> {
@PluginElement("Filter") @PluginElement("Filter")
private Filter filter; private Filter filter;
public Filter getFilter() { // We are calling this attribute propertyArray because we use the more g
return filter; eneric "properties" in several places
} // with different types: Array, Map and List.
@PluginElement("Properties")
private Property[] propertyArray;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public B asBuilder() { public B asBuilder() {
return (B) this; return (B) this;
} }
public B withFilter(final Filter filter) { public Filter getFilter() {
return filter;
}
public Property[] getPropertyArray() {
return propertyArray;
}
public B setFilter(final Filter filter) {
this.filter = filter; this.filter = filter;
return asBuilder(); return asBuilder();
} }
public B setPropertyArray(final Property[] properties) {
this.propertyArray = properties;
return asBuilder();
}
/**
* Sets the filter.
*
* @param filter The filter
* @return this
* @deprecated Use {@link #setFilter(Filter)}.
*/
@Deprecated
public B withFilter(final Filter filter) {
return setFilter(filter);
}
} }
/** /**
* May be null. * May be null.
*/ */
private volatile Filter filter; private volatile Filter filter;
protected AbstractFilterable(final Filter filter) { @PluginElement("Properties")
this.filter = filter; private final Property[] propertyArray;
}
protected AbstractFilterable() { protected AbstractFilterable() {
this(null, Property.EMPTY_ARRAY);
}
protected AbstractFilterable(final Filter filter) {
this(filter, Property.EMPTY_ARRAY);
} }
/** /**
* Returns the Filter. * @since 2.11.2
* @return the Filter or null.
*/ */
@Override protected AbstractFilterable(final Filter filter, final Property[] propertyA
public Filter getFilter() { rray) {
return filter; this.filter = filter;
this.propertyArray = propertyArray == null ? Property.EMPTY_ARRAY : prop
ertyArray;
} }
/** /**
* Adds a filter. * Adds a filter.
* @param filter The Filter to add. * @param filter The Filter to add.
*/ */
@Override @Override
public synchronized void addFilter(final Filter filter) { public synchronized void addFilter(final Filter filter) {
if (filter == null) { if (filter == null) {
return; return;
skipping to change at line 100 skipping to change at line 130
this.filter = filter; this.filter = filter;
} else if (this.filter instanceof CompositeFilter) { } else if (this.filter instanceof CompositeFilter) {
this.filter = ((CompositeFilter) this.filter).addFilter(filter); this.filter = ((CompositeFilter) this.filter).addFilter(filter);
} else { } else {
final Filter[] filters = new Filter[] {this.filter, filter}; final Filter[] filters = new Filter[] {this.filter, filter};
this.filter = CompositeFilter.createFilters(filters); this.filter = CompositeFilter.createFilters(filters);
} }
} }
/** /**
* Returns the Filter.
* @return the Filter or null.
*/
@Override
public Filter getFilter() {
return filter;
}
/**
* Determines if a Filter is present.
* @return false if no Filter is present.
*/
@Override
public boolean hasFilter() {
return filter != null;
}
/**
* Determine if the LogEvent should be processed or ignored.
* @param event The LogEvent.
* @return true if the LogEvent should be processed.
*/
@Override
public boolean isFiltered(final LogEvent event) {
return filter != null && filter.filter(event) == Filter.Result.DENY;
}
/**
* Removes a Filter. * Removes a Filter.
* @param filter The Filter to remove. * @param filter The Filter to remove.
*/ */
@Override @Override
public synchronized void removeFilter(final Filter filter) { public synchronized void removeFilter(final Filter filter) {
if (this.filter == null || filter == null) { if (this.filter == null || filter == null) {
return; return;
} }
if (this.filter == filter || this.filter.equals(filter)) { if (this.filter == filter || this.filter.equals(filter)) {
this.filter = null; this.filter = null;
skipping to change at line 125 skipping to change at line 183
} else if (composite.size() == 1) { } else if (composite.size() == 1) {
final Iterator<Filter> iter = composite.iterator(); final Iterator<Filter> iter = composite.iterator();
this.filter = iter.next(); this.filter = iter.next();
} else { } else {
this.filter = null; this.filter = null;
} }
} }
} }
/** /**
* Determines if a Filter is present.
* @return false if no Filter is present.
*/
@Override
public boolean hasFilter() {
return filter != null;
}
/**
* Make the Filter available for use. * Make the Filter available for use.
*/ */
@Override @Override
public void start() { public void start() {
this.setStarting(); this.setStarting();
if (filter != null) { if (filter != null) {
filter.start(); filter.start();
} }
this.setStarted(); this.setStarted();
} }
skipping to change at line 175 skipping to change at line 224
filter.stop(); filter.stop();
stopped = true; stopped = true;
} }
} }
if (changeLifeCycleState) { if (changeLifeCycleState) {
this.setStopped(); this.setStopped();
} }
return stopped; return stopped;
} }
/** public Property[] getPropertyArray() {
* Determine if the LogEvent should be processed or ignored. return propertyArray;
* @param event The LogEvent.
* @return true if the LogEvent should be processed.
*/
@Override
public boolean isFiltered(final LogEvent event) {
return filter != null && filter.filter(event) == Filter.Result.DENY;
} }
} }
 End of changes. 11 change blocks. 
29 lines changed or deleted 75 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)