Blame liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/session/EventRule.java

Packit c04fcb
/*
Packit c04fcb
 * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
Packit c04fcb
 *
Packit c04fcb
 * This library is free software; you can redistribute it and/or modify it
Packit c04fcb
 * under the terms of the GNU Lesser General Public License, version 2.1 only,
Packit c04fcb
 * as published by the Free Software Foundation.
Packit c04fcb
 *
Packit c04fcb
 * This library is distributed in the hope that it will be useful, but WITHOUT
Packit c04fcb
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit c04fcb
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
Packit c04fcb
 * for more details.
Packit c04fcb
 *
Packit c04fcb
 * You should have received a copy of the GNU Lesser General Public License
Packit c04fcb
 * along with this library; if not, write to the Free Software Foundation,
Packit c04fcb
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Packit c04fcb
 */
Packit c04fcb
Packit c04fcb
package org.lttng.ust.agent.session;
Packit c04fcb
Packit c04fcb
/**
Packit c04fcb
 * Event filtering rule present in a tracing session.
Packit c04fcb
 *
Packit c04fcb
 * It typically comes from a "lttng enable-event" command, and contains a
Packit c04fcb
 * domain, event name, log level and filter string.
Packit c04fcb
 *
Packit c04fcb
 * @author Alexandre Montplaisir
Packit c04fcb
 */
Packit c04fcb
public class EventRule {
Packit c04fcb
Packit c04fcb
	private final String eventName;
Packit c04fcb
	private final LogLevelSelector logLevelSelector;
Packit c04fcb
	private final String filterString;
Packit c04fcb
Packit c04fcb
	/**
Packit c04fcb
	 * Constructor.
Packit c04fcb
	 *
Packit c04fcb
	 * @param eventName
Packit c04fcb
	 *            The name of the tracepoint
Packit c04fcb
	 * @param logLevelSelector
Packit c04fcb
	 *            The log level of the event rule
Packit c04fcb
	 * @param filterString
Packit c04fcb
	 *            The filtering string. May be null if there is no extra filter.
Packit c04fcb
	 */
Packit c04fcb
	public EventRule(String eventName, LogLevelSelector logLevelSelector, String filterString) {
Packit c04fcb
		this.eventName = eventName;
Packit c04fcb
		this.logLevelSelector = logLevelSelector;
Packit c04fcb
		this.filterString = filterString;
Packit c04fcb
	}
Packit c04fcb
Packit c04fcb
	/**
Packit c04fcb
	 * Get the event name of this rule.
Packit c04fcb
	 *
Packit c04fcb
	 * @return The event name
Packit c04fcb
	 */
Packit c04fcb
	public String getEventName() {
Packit c04fcb
		return eventName;
Packit c04fcb
	}
Packit c04fcb
Packit c04fcb
	/**
Packit c04fcb
	 * Get the log level filter configuration of the rule.
Packit c04fcb
	 *
Packit c04fcb
	 * @return The log level selector
Packit c04fcb
	 */
Packit c04fcb
	public LogLevelSelector getLogLevelSelector() {
Packit c04fcb
		return logLevelSelector;
Packit c04fcb
	}
Packit c04fcb
Packit c04fcb
	/**
Packit c04fcb
	 * Get the filter string associated with this rule.
Packit c04fcb
	 *
Packit c04fcb
	 * @return The filter string, may be null for no filter string.
Packit c04fcb
	 */
Packit c04fcb
	public String getFilterString() {
Packit c04fcb
		return filterString;
Packit c04fcb
	}
Packit c04fcb
Packit c04fcb
	// ------------------------------------------------------------------------
Packit c04fcb
	// Methods from Object
Packit c04fcb
	// ------------------------------------------------------------------------
Packit c04fcb
Packit c04fcb
	@Override
Packit c04fcb
	public int hashCode() {
Packit c04fcb
		final int prime = 31;
Packit c04fcb
		int result = 1;
Packit c04fcb
		result = prime * result + ((eventName == null) ? 0 : eventName.hashCode());
Packit c04fcb
		result = prime * result + ((filterString == null) ? 0 : filterString.hashCode());
Packit c04fcb
		result = prime * result + ((logLevelSelector == null) ? 0 : logLevelSelector.hashCode());
Packit c04fcb
		return result;
Packit c04fcb
	}
Packit c04fcb
Packit c04fcb
	@Override
Packit c04fcb
	public boolean equals(Object obj) {
Packit c04fcb
		if (this == obj) {
Packit c04fcb
			return true;
Packit c04fcb
		}
Packit c04fcb
		if (obj == null) {
Packit c04fcb
			return false;
Packit c04fcb
		}
Packit c04fcb
		if (getClass() != obj.getClass()) {
Packit c04fcb
			return false;
Packit c04fcb
		}
Packit c04fcb
		EventRule other = (EventRule) obj;
Packit c04fcb
Packit c04fcb
		if (eventName == null) {
Packit c04fcb
			if (other.eventName != null) {
Packit c04fcb
				return false;
Packit c04fcb
			}
Packit c04fcb
		} else if (!eventName.equals(other.eventName)) {
Packit c04fcb
			return false;
Packit c04fcb
		}
Packit c04fcb
		/* else, continue */
Packit c04fcb
Packit c04fcb
		if (filterString == null) {
Packit c04fcb
			if (other.filterString != null) {
Packit c04fcb
				return false;
Packit c04fcb
			}
Packit c04fcb
		} else if (!filterString.equals(other.filterString)) {
Packit c04fcb
			return false;
Packit c04fcb
		}
Packit c04fcb
		/* else, continue */
Packit c04fcb
Packit c04fcb
		if (logLevelSelector == null) {
Packit c04fcb
			if (other.logLevelSelector != null) {
Packit c04fcb
				return false;
Packit c04fcb
			}
Packit c04fcb
		} else if (!logLevelSelector.equals(other.logLevelSelector)) {
Packit c04fcb
			return false;
Packit c04fcb
		}
Packit c04fcb
		/* else, continue */
Packit c04fcb
Packit c04fcb
		return true;
Packit c04fcb
	}
Packit c04fcb
Packit c04fcb
	@Override
Packit c04fcb
	public String toString() {
Packit c04fcb
		return "Event name = " + getEventName() +
Packit c04fcb
		", Log level selector = (" + getLogLevelSelector().toString() + ")" +
Packit c04fcb
		", Filter string = " + getFilterString();
Packit c04fcb
	}
Packit c04fcb
}