// Path: moneta-core/src/main/java/org/moneta/error/MonetaException.java
// public class MonetaException extends ContextedRuntimeException {
// 
// 	private static final long serialVersionUID = -682655095144383360L;
// 
// 	public MonetaException(String message) {
// 		super(message);
// 	}
// 
// //	public MonetaException(Throwable cause) {
// //		super(cause);
// //	}
// 
// 	public MonetaException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/topic/Topic.java
// public class Topic extends BaseType implements Comparable<Topic> {
// 	
// 	private String topicName;
// 	private String pluralName;
// 	private String dataSourceName;
// 	private String schemaName;
// 	private String catalogName;
// 	private String tableName;
// 	private Boolean readOnly = Boolean.FALSE;
// 	
// 	private Map<String,String> aliasMap = new HashMap<String,String>();
// 	private List<TopicKeyField> keyFieldList = new ArrayList<TopicKeyField>();
// 	
// 	public String getTopicName() {
// 		return topicName;
// 	}
// 	
// 	public void setTopicName(String topicName) {
// 		this.topicName = topicName;
// 	}
// 	
// 	public String getTableName() {
// 		return tableName;
// 	}
// 	
// 	public void setTableName(String tableName) {
// 		this.tableName = tableName;
// 	}
// 
// 	public String getSchemaName() {
// 		return schemaName;
// 	}
// 
// 	public void setSchemaName(String schemaName) {
// 		this.schemaName = schemaName;
// 	}
// 
// 	public Boolean getReadOnly() {
// 		return readOnly;
// 	}
// 
// 	public void setReadOnly(Boolean readOnly) {
// 		this.readOnly = readOnly;
// 	}
// 
// 	public String getDataSourceName() {
// 		return dataSourceName;
// 	}
// 
// 	public void setDataSourceName(String dataSourceName) {
// 		this.dataSourceName = dataSourceName;
// 	}
// 
// 	public String getCatalogName() {
// 		return catalogName;
// 	}
// 
// 	public void setCatalogName(String catalogName) {
// 		this.catalogName = catalogName;
// 	}
// 
// 	public Map<String, String> getAliasMap() {
// 		return aliasMap;
// 	}
// 
// 	public List<TopicKeyField> getKeyFieldList() {
// 		return keyFieldList;
// 	}
// 
// 	public int compareTo(Topic other) {
// 		return new CompareToBuilder()
// 			.append(this.topicName, other.getTopicName())
// 			.toComparison();
// 	}
// 
// 	public String getPluralName() {
// 		return pluralName;
// 	}
// 
// 	public void setPluralName(String pluralName) {
// 		this.pluralName = pluralName;
// 	}
// 
// }


import org.moneta.types.topic.Topic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import net.admin4j.timer.TaskTimer;
import net.admin4j.timer.TaskTimerFactory;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang3.StringUtils;
import org.moneta.error.MonetaException;

/*
 * This software is licensed under the Apache License, Version 2.0
 * (the "License") agreement; 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.moneta;





/**
 * Monitors performance for 
 * @author D. Ashmore
 *
 */
public class MonetaPerformanceFilter implements Filter {
	
	public static final String PARM_MAX_TRNASACTION_TIME_THRESHOLD_IN_MILLIS="max.transaction.time.millis";
	
	private Long transactionTimeThreshold = null;
	private static Logger perfLogger = LoggerFactory.getLogger("Performance");
	private static Logger logger = LoggerFactory.getLogger(MonetaPerformanceFilter.class);

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {

		TaskTimer perfMonitor = null;
		SearchRequestFactory searchRequestFactory = null;
		Topic searchTopic = null;
		
		long startTimeMillis = System.currentTimeMillis();
		try {
			searchRequestFactory = new SearchRequestFactory();
			String[] uriNodes = searchRequestFactory.deriveSearchNodes( (HttpServletRequest)request);
			if ( !ArrayUtils.isEmpty(uriNodes)) {
				searchTopic = searchRequestFactory.findSearchTopic(uriNodes[0], false);
				if (searchTopic == null) {
					perfMonitor = TaskTimerFactory.start( this.deriveTimerLabel((HttpServletRequest)request) );
				}
				else {
					perfMonitor = TaskTimerFactory.start(searchTopic.getTopicName());
				}
			}
			

// Path: moneta-core/src/main/java/org/moneta/error/MonetaException.java
// public class MonetaException extends ContextedRuntimeException {
// 
// 	private static final long serialVersionUID = -682655095144383360L;
// 
// 	public MonetaException(String message) {
// 		super(message);
// 	}
// 
// //	public MonetaException(Throwable cause) {
// //		super(cause);
// //	}
// 
// 	public MonetaException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// }
// 
// Path: moneta-core/src/main/java/org/moneta/types/topic/Topic.java
// public class Topic extends BaseType implements Comparable<Topic> {
// 	
// 	private String topicName;
// 	private String pluralName;
// 	private String dataSourceName;
// 	private String schemaName;
// 	private String catalogName;
// 	private String tableName;
// 	private Boolean readOnly = Boolean.FALSE;
// 	
// 	private Map<String,String> aliasMap = new HashMap<String,String>();
// 	private List<TopicKeyField> keyFieldList = new ArrayList<TopicKeyField>();
// 	
// 	public String getTopicName() {
// 		return topicName;
// 	}
// 	
// 	public void setTopicName(String topicName) {
// 		this.topicName = topicName;
// 	}
// 	
// 	public String getTableName() {
// 		return tableName;
// 	}
// 	
// 	public void setTableName(String tableName) {
// 		this.tableName = tableName;
// 	}
// 
// 	public String getSchemaName() {
// 		return schemaName;
// 	}
// 
// 	public void setSchemaName(String schemaName) {
// 		this.schemaName = schemaName;
// 	}
// 
// 	public Boolean getReadOnly() {
// 		return readOnly;
// 	}
// 
// 	public void setReadOnly(Boolean readOnly) {
// 		this.readOnly = readOnly;
// 	}
// 
// 	public String getDataSourceName() {
// 		return dataSourceName;
// 	}
// 
// 	public void setDataSourceName(String dataSourceName) {
// 		this.dataSourceName = dataSourceName;
// 	}
// 
// 	public String getCatalogName() {
// 		return catalogName;
// 	}
// 
// 	public void setCatalogName(String catalogName) {
// 		this.catalogName = catalogName;
// 	}
// 
// 	public Map<String, String> getAliasMap() {
// 		return aliasMap;
// 	}
// 
// 	public List<TopicKeyField> getKeyFieldList() {
// 		return keyFieldList;
// 	}
// 
// 	public int compareTo(Topic other) {
// 		return new CompareToBuilder()
// 			.append(this.topicName, other.getTopicName())
// 			.toComparison();
// 	}
// 
// 	public String getPluralName() {
// 		return pluralName;
// 	}
// 
// 	public void setPluralName(String pluralName) {
// 		this.pluralName = pluralName;
// 	}
// 
// }


// Path: moneta-core/src/main/java/org/moneta/MonetaPerformanceFilter.java
import org.moneta.types.topic.Topic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import net.admin4j.timer.TaskTimer;
import net.admin4j.timer.TaskTimerFactory;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang3.StringUtils;
import org.moneta.error.MonetaException;

/*
 * This software is licensed under the Apache License, Version 2.0
 * (the "License") agreement; 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.moneta;





/**
 * Monitors performance for 
 * @author D. Ashmore
 *
 */
public class MonetaPerformanceFilter implements Filter {
	
	public static final String PARM_MAX_TRNASACTION_TIME_THRESHOLD_IN_MILLIS="max.transaction.time.millis";
	
	private Long transactionTimeThreshold = null;
	private static Logger perfLogger = LoggerFactory.getLogger("Performance");
	private static Logger logger = LoggerFactory.getLogger(MonetaPerformanceFilter.class);

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {

		TaskTimer perfMonitor = null;
		SearchRequestFactory searchRequestFactory = null;
		Topic searchTopic = null;
		
		long startTimeMillis = System.currentTimeMillis();
		try {
			searchRequestFactory = new SearchRequestFactory();
			String[] uriNodes = searchRequestFactory.deriveSearchNodes( (HttpServletRequest)request);
			if ( !ArrayUtils.isEmpty(uriNodes)) {
				searchTopic = searchRequestFactory.findSearchTopic(uriNodes[0], false);
				if (searchTopic == null) {
					perfMonitor = TaskTimerFactory.start( this.deriveTimerLabel((HttpServletRequest)request) );
				}
				else {
					perfMonitor = TaskTimerFactory.start(searchTopic.getTopicName());
				}
			}
			

			chain.doFilter(request, response);
