Return-Path: X-Original-To: apmail-jackrabbit-commits-archive@www.apache.org Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 02CC09D62 for ; Sun, 9 Oct 2011 15:50:32 +0000 (UTC) Received: (qmail 65702 invoked by uid 500); 9 Oct 2011 15:50:31 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 65670 invoked by uid 500); 9 Oct 2011 15:50:31 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 65663 invoked by uid 99); 9 Oct 2011 15:50:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Oct 2011 15:50:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Oct 2011 15:50:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7BA082388847; Sun, 9 Oct 2011 15:50:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1180633 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx: ./ core/ query/ registry/ util/ Date: Sun, 09 Oct 2011 15:50:00 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111009155001.7BA082388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Sun Oct 9 15:49:59 2011 New Revision: 1180633 URL: http://svn.apache.org/viewvc?rev=1180633&view=rev Log: JCR-3040: JMX Stats for the Session Part of a patch by Alex Parvulescu Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/JackrabbitBaseMBean.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/StatManager.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStat.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatImpl.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManager.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManagerMBean.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStat.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDto.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDtoComparator.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatImpl.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManager.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManagerMBean.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistry.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryImpl.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManager.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManagerMBean.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/util/ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/util/CachingOpsPerSecondDto.java (with props) Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/JackrabbitBaseMBean.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/JackrabbitBaseMBean.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/JackrabbitBaseMBean.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/JackrabbitBaseMBean.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,51 @@ +/* + * 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.jackrabbit.core.jmx; + +/** + * This should be the base for any MBean Services built for Jackrabbit + * + */ +public interface JackrabbitBaseMBean { + + String DOMAIN = "org.apache.jackrabbit"; + + /** + * If this service is currently registering stats + * + * @return true if the service is enabled + */ + boolean isEnabled(); + + /** + * Enables the service + * + */ + void enable(); + + /** + * Disables the service + * + */ + void disable(); + + /** + * clears all data + */ + void reset(); + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/JackrabbitBaseMBean.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/StatManager.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/StatManager.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/StatManager.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/StatManager.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,93 @@ +/* + * 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.jackrabbit.core.jmx; + +import org.apache.jackrabbit.core.jmx.core.CoreStat; +import org.apache.jackrabbit.core.jmx.core.CoreStatImpl; +import org.apache.jackrabbit.core.jmx.query.QueryStat; +import org.apache.jackrabbit.core.jmx.query.QueryStatImpl; +import org.apache.jackrabbit.core.jmx.registry.JmxRegistry; +import org.apache.jackrabbit.core.jmx.registry.JmxRegistryImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * StatManager represents a single entry point to the stats objects available.
+ * + * It is disabled by default, and it can be enabled via a system property called + * "enableJmxSupport", like:
+ * + * -DenableJmxSupport=true + * + */ +public class StatManager { + + private static final Logger log = LoggerFactory + .getLogger(StatManager.class); + + private static final Boolean DEFAULT_JMX_SUPPORT = Boolean.valueOf(System + .getProperty("enableJmxSupport", "false")); + + private JmxRegistry jmxRegistry; + + private final boolean enableJmxSupport; + + /* STATS */ + private final QueryStat queryStat = new QueryStatImpl(); + + private final CoreStat coreStat = new CoreStatImpl(); + + public StatManager(final boolean enableJmxSupport) { + this.enableJmxSupport = enableJmxSupport; + } + + public StatManager() { + this(DEFAULT_JMX_SUPPORT); + } + + public void init() { + coreStat.setEnabled(false); + queryStat.setEnabled(false); + if (enableJmxSupport) { + enableJxmRegistry(); + } + log.debug("Started StatManager. Jmx support enabled {}.", + enableJmxSupport); + } + + protected void enableJxmRegistry() { + if (jmxRegistry != null) { + return; + } + jmxRegistry = new JmxRegistryImpl(this); + jmxRegistry.start(); + } + + public void stop() { + if (jmxRegistry != null) { + jmxRegistry.stop(); + } + } + + public CoreStat getCoreStat() { + return coreStat; + } + + public QueryStat getQueryStat() { + return queryStat; + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/StatManager.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStat.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStat.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStat.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStat.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,66 @@ +/* + * 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.jackrabbit.core.jmx.core; + +/** + * Statistics on core JCR operations + * + */ +public interface CoreStat { + + /** -- SESSION INFO -- **/ + + void sessionCreated(); + + void sessionLoggedOut(); + + long getNumberOfSessions(); + + void resetNumberOfSessions(); + + /** + * @param timeNs + * as given by timeNs = System.nanoTime() - timeNs; + */ + void onSessionOperation(boolean isWrite, long timeNs); + + double getReadOpsPerSecond(); + + double getWriteOpsPerSecond(); + + void resetNumberOfOperations(); + + /** + * If this service is currently registering stats + * + * @return true if the service is enabled + */ + boolean isEnabled(); + + /** + * Enables/Disables the service + * + * @param enabled + */ + void setEnabled(boolean enabled); + + /** + * clears all data + */ + void reset(); + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStat.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatImpl.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatImpl.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatImpl.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,102 @@ +/* + * 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.jackrabbit.core.jmx.core; + +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.jackrabbit.core.jmx.util.CachingOpsPerSecondDto; + +/** + * Default CoreStat impl + * + */ +public class CoreStatImpl implements CoreStat { + + /** -- SESSION INFO -- **/ + + private final AtomicLong sessions = new AtomicLong(0); + + private boolean enabled = false; + + private final CachingOpsPerSecondDto reads = new CachingOpsPerSecondDto(); + + private final CachingOpsPerSecondDto writes = new CachingOpsPerSecondDto(); + + public void sessionCreated() { + if (!enabled) { + return; + } + sessions.incrementAndGet(); + } + + public void sessionLoggedOut() { + if (!enabled || sessions.get() == 0) { + return; + } + sessions.decrementAndGet(); + } + + public long getNumberOfSessions() { + return sessions.get(); + } + + public void resetNumberOfSessions() { + sessions.set(0); + } + + public void onSessionOperation(boolean isWrite, long timeNs) { + if (!enabled) { + return; + } + if (isWrite) { + writes.onOp(timeNs); + } else { + reads.onOp(timeNs); + } + } + + public double getReadOpsPerSecond() { + return reads.getOpsPerSecond(); + } + + public double getWriteOpsPerSecond() { + return writes.getOpsPerSecond(); + } + + public void resetNumberOfOperations() { + reads.reset(); + writes.reset(); + } + + /** -- GENERAL INFO -- **/ + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + if (!this.enabled) { + reset(); + } + } + + public void reset() { + resetNumberOfSessions(); + resetNumberOfOperations(); + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatImpl.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManager.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManager.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManager.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManager.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,67 @@ +/* + * 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.jackrabbit.core.jmx.core; + +/** + * The CoreStatManagerMBean default implementation + * + */ +public class CoreStatManager implements CoreStatManagerMBean { + + private final CoreStat coreStat; + + public CoreStatManager(final CoreStat coreStat) { + this.coreStat = coreStat; + } + + public long getNumberOfSessions() { + return coreStat.getNumberOfSessions(); + } + + public void resetNumberOfSessions() { + this.coreStat.resetNumberOfSessions(); + } + + public boolean isEnabled() { + return this.coreStat.isEnabled(); + } + + public void reset() { + this.coreStat.reset(); + } + + public double getReadOpsPerSecond() { + return this.coreStat.getReadOpsPerSecond(); + } + + public double getWriteOpsPerSecond() { + return this.coreStat.getWriteOpsPerSecond(); + } + + public void resetNumberOfOperations() { + this.coreStat.resetNumberOfOperations(); + + } + + public void enable() { + this.coreStat.setEnabled(true); + } + + public void disable() { + this.coreStat.setEnabled(false); + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManager.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManagerMBean.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManagerMBean.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManagerMBean.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManagerMBean.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,39 @@ +/* + * 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.jackrabbit.core.jmx.core; + +import org.apache.jackrabbit.core.jmx.JackrabbitBaseMBean; + +/** + * The CoreStatManagerMBean exposes the CoreStat info via JMX + * + */ +public interface CoreStatManagerMBean extends JackrabbitBaseMBean { + + String NAME = DOMAIN + ":type=CoreStats"; + + long getNumberOfSessions(); + + void resetNumberOfSessions(); + + double getReadOpsPerSecond(); + + double getWriteOpsPerSecond(); + + void resetNumberOfOperations(); + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/core/CoreStatManagerMBean.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStat.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStat.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStat.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStat.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,74 @@ +/* + * 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.jackrabbit.core.jmx.query; + +/** + * Statistics on query operations + * + */ +public interface QueryStat { + + void logQuery(final String language, final String statement, long duration); + + /** Slowest Queries */ + + QueryStatDto[] getSlowQueries(); + + /** + * @return how big the Top X queue is + */ + int getSlowQueriesQueueSize(); + + /** + * Change the Top X queue size + * + * @param size + * the new size + */ + void setSlowQueriesQueueSize(int size); + + /** + * clears the queue + */ + void clearSlowQueriesQueue(); + + double getQueriesPerSecond(); + + double getAvgQueryTime(); + + /** Generic Stats Stuff */ + + /** + * If this service is currently registering stats + * + * @return true if the service is enabled + */ + boolean isEnabled(); + + /** + * Enables/Disables the service + * + * @param enabled + */ + void setEnabled(boolean enabled); + + /** + * clears all data + */ + void reset(); + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStat.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDto.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDto.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDto.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDto.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,97 @@ +/* + * 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.jackrabbit.core.jmx.query; + +import java.io.Serializable; +import java.util.Calendar; +import java.util.Date; + +/** + * Object that holds statistical info about a query. + * + */ +public class QueryStatDto implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * lazy, computed at call time + */ + private long position; + + /** + * the time that the query was created + */ + private final Date creationTime; + + /** + * run duration + */ + private final long duration; + + /** + * query language + */ + private final String language; + + /** + * query statement + */ + private final String statement; + + public QueryStatDto(final String language, final String statement, + long duration) { + this.duration = duration; + this.language = language; + this.statement = statement; + + Calendar c = Calendar.getInstance(); + c.setTimeInMillis(System.currentTimeMillis() - duration); + this.creationTime = c.getTime(); + } + + public long getDuration() { + return duration; + } + + public String getLanguage() { + return language; + } + + public String getStatement() { + return statement; + } + + public String getCreationTime() { + return creationTime.toString(); + } + + public long getPosition() { + return position; + } + + public void setPosition(long position) { + this.position = position; + } + + @Override + public String toString() { + return "QueryStat [creationTime=" + creationTime + ", duration=" + + duration + ", language=" + language + ", statement=" + + statement + "]"; + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDto.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDtoComparator.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDtoComparator.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDtoComparator.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDtoComparator.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,29 @@ +/* + * 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.jackrabbit.core.jmx.query; + +import java.util.Comparator; + +/** + * QueryStatDto comparator by duration + * + */ +public class QueryStatDtoComparator implements Comparator { + public int compare(QueryStatDto o1, QueryStatDto o2) { + return new Long(o1.getDuration()).compareTo(o2.getDuration()); + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatDtoComparator.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatImpl.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatImpl.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatImpl.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,95 @@ +/* + * 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.jackrabbit.core.jmx.query; + +import java.util.Comparator; +import java.util.PriorityQueue; + +import org.apache.jackrabbit.core.jmx.util.CachingOpsPerSecondDto; + +/** + * Default {@link QueryStat} implementation + * + */ +public class QueryStatImpl implements QueryStat { + + private final static Comparator comparator = new QueryStatDtoComparator(); + + private int queueSize = 15; + + private PriorityQueue queries = new PriorityQueue( + queueSize + 1, comparator); + + private CachingOpsPerSecondDto qps = new CachingOpsPerSecondDto(); + + private boolean enabled = false; + + public QueryStatImpl() { + } + + public int getSlowQueriesQueueSize() { + return queueSize; + } + + public synchronized void setSlowQueriesQueueSize(int size) { + this.queueSize = size; + this.queries = new PriorityQueue(this.queueSize + 1, + comparator); + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + this.queries = new PriorityQueue(this.queueSize + 1, + comparator); + } + + public synchronized void logQuery(final String language, + final String statement, long duration) { + if (!enabled) { + return; + } + queries.add(new QueryStatDto(language, statement, duration)); + if (queries.size() > queueSize) { + queries.remove(); + } + qps.onOp(duration * 1000); + } + + public void clearSlowQueriesQueue() { + this.queries.clear(); + } + + public void reset() { + clearSlowQueriesQueue(); + } + + public QueryStatDto[] getSlowQueries() { + return queries.toArray(new QueryStatDto[queries.size()]); + } + + public double getQueriesPerSecond() { + return qps.getOpsPerSecond(); + } + + public double getAvgQueryTime() { + return qps.getOpAvgTime(); + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatImpl.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManager.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManager.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManager.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManager.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,129 @@ +/* + * 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.jackrabbit.core.jmx.query; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; + +import javax.management.openmbean.CompositeDataSupport; +import javax.management.openmbean.CompositeType; +import javax.management.openmbean.OpenDataException; +import javax.management.openmbean.OpenType; +import javax.management.openmbean.SimpleType; +import javax.management.openmbean.TabularData; +import javax.management.openmbean.TabularDataSupport; +import javax.management.openmbean.TabularType; + +/** + * The QueryStatManagerMBean default implementation + * + */ +public class QueryStatManager implements QueryStatManagerMBean { + + private final QueryStat queryStat; + + private final static Comparator comparatorRev = Collections + .reverseOrder(new QueryStatDtoComparator()); + + public QueryStatManager(final QueryStat queryStat) { + this.queryStat = queryStat; + } + + public boolean isEnabled() { + return this.queryStat.isEnabled(); + } + + public void enable() { + this.queryStat.setEnabled(true); + } + + public void disable() { + this.queryStat.setEnabled(false); + } + + public void reset() { + this.queryStat.reset(); + } + + public int getQueueSize() { + return queryStat.getSlowQueriesQueueSize(); + } + + public void setQueueSize(int size) { + this.queryStat.setSlowQueriesQueueSize(size); + } + + public void clearQueue() { + this.queryStat.clearSlowQueriesQueue(); + } + + public QueryStatDto[] getTopQueries() { + QueryStatDto[] top = this.queryStat.getSlowQueries(); + Arrays.sort(top, comparatorRev); + for (int i = 0; i < top.length; i++) { + top[i].setPosition(i + 1); + } + return top; + } + + public TabularData getQueries() { + TabularDataSupport tds = null; + try { + CompositeType ct = QueryStatCompositeTypeFactory.getCompositeType(); + + TabularType tt = new TabularType(QueryStatDto.class.getName(), + "Query History", ct, QueryStatCompositeTypeFactory.index); + tds = new TabularDataSupport(tt); + + for (QueryStatDto q : getTopQueries()) { + tds.put(new CompositeDataSupport(ct, + QueryStatCompositeTypeFactory.names, + QueryStatCompositeTypeFactory.getValues(q))); + } + return tds; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + private static class QueryStatCompositeTypeFactory { + + private final static String[] index = { "position" }; + + private final static String[] names = { "position", "duration", + "language", "statement", "creationTime" }; + + private final static String[] descriptions = { "position", "duration", + "language", "statement", "creationTime" }; + + private final static OpenType[] types = { SimpleType.LONG, + SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, + SimpleType.STRING }; + + public static CompositeType getCompositeType() throws OpenDataException { + return new CompositeType(QueryStat.class.getName(), + QueryStat.class.getName(), names, descriptions, types); + } + + public static Object[] getValues(QueryStatDto q) { + return new Object[] { q.getPosition(), q.getDuration(), + q.getLanguage(), q.getStatement(), q.getCreationTime() }; + } + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManager.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManagerMBean.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManagerMBean.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManagerMBean.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManagerMBean.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,50 @@ +/* + * 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.jackrabbit.core.jmx.query; + +import javax.management.openmbean.TabularData; + +import org.apache.jackrabbit.core.jmx.JackrabbitBaseMBean; + +/** + * JMX Bindings for {@link QueryStat}. + * + */ +public interface QueryStatManagerMBean extends JackrabbitBaseMBean { + + String NAME = DOMAIN + ":type=QueryStats"; + + TabularData getQueries(); + + /** + * @return how big the Top X queue is + */ + int getQueueSize(); + + /** + * Change the Top X queue size + * + * @param size + * the new size + */ + void setQueueSize(int size); + + /** + * clears the queue + */ + void clearQueue(); +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/query/QueryStatManagerMBean.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistry.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistry.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistry.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistry.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,61 @@ +/* + * 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.jackrabbit.core.jmx.registry; + +import javax.management.ObjectName; + +import org.apache.jackrabbit.core.jmx.JackrabbitBaseMBean; + +/** + * JMX Mbean dynamic registration service + * + */ +public interface JmxRegistry { + + /** + * starts the service + */ + void start(); + + /** + * stops the service + */ + void stop(); + + /** + * Registers a new MBEan under the given name + * + * @param bean + * to be registered + * @param name + * @throws Exception + */ + void register(JackrabbitBaseMBean bean, ObjectName name) throws Exception; + + /** + * Unregisters a bean + * + * @param name + * @throws Exception + */ + void unregister(ObjectName name) throws Exception; + + void enableCoreStatJmx(); + + void enableQueryStatJmx(); + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistry.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryImpl.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryImpl.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryImpl.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,157 @@ +/* + * 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.jackrabbit.core.jmx.registry; + +import java.lang.management.ManagementFactory; +import java.util.ArrayList; +import java.util.List; + +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import org.apache.jackrabbit.core.jmx.JackrabbitBaseMBean; +import org.apache.jackrabbit.core.jmx.StatManager; +import org.apache.jackrabbit.core.jmx.core.CoreStatManager; +import org.apache.jackrabbit.core.jmx.core.CoreStatManagerMBean; +import org.apache.jackrabbit.core.jmx.query.QueryStatManager; +import org.apache.jackrabbit.core.jmx.query.QueryStatManagerMBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * JmxRegistry default implementation + * + */ +public class JmxRegistryImpl implements JmxRegistry { + + private static Logger log = LoggerFactory.getLogger(JmxRegistryImpl.class); + + /* JMX */ + private MBeanServer server; + + private final List registry = new ArrayList(); + + /* Stats */ + private final StatManager statManager; + + public JmxRegistryImpl(final StatManager statManager) { + this.statManager = statManager; + } + + /* + * (non-Javadoc) + * + * @see org.apache.jackrabbit.core.jmx.JmxRegistry#start() + */ + public void start() { + server = ManagementFactory.getPlatformMBeanServer(); + enableRegistry(); + log.debug("Started JMX Registry."); + } + + public void enableRegistry() { + if (server == null) { + return; + } + try { + register(new JmxRegistryManager(this), new ObjectName( + JmxRegistryManagerMBean.NAME)); + log.debug("JMX Registry - registered DynamicRegistry."); + } catch (Exception e) { + log.error("JMX Registry - Unable to register DynamicRegistry.", e); + } + } + + public void enableCoreStatJmx() { + if (server == null) { + return; + } + try { + register(new CoreStatManager(statManager.getCoreStat()), + new ObjectName(CoreStatManagerMBean.NAME)); + log.debug("JMX Registry - registered CoreStats."); + } catch (Exception e) { + log.error("JMX Registry - Unable to register CoreStats.", e); + } + } + + public void enableQueryStatJmx() { + if (server == null) { + return; + } + try { + register(new QueryStatManager(statManager.getQueryStat()), + new ObjectName(QueryStatManagerMBean.NAME)); + log.debug("JMX Registry - registered QueryStats."); + } catch (Exception e) { + log.error("JMX Registry - Unable to register CoreStats.", e); + } + } + + /* + * (non-Javadoc) + * + * @see org.apache.jackrabbit.core.jmx.JmxRegistry#stop() + */ + public void stop() { + if (server == null) { + return; + } + + List registryCopy = new ArrayList(registry); + for (ObjectName o : registryCopy) { + try { + unregister(o); + } catch (Exception e) { + e.printStackTrace(); + } + } + registry.clear(); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.jackrabbit.core.jmx.JmxRegistry#register(org.apache.jackrabbit + * .core.jmx.JackrabbitMBean, javax.management.ObjectName) + */ + public void register(JackrabbitBaseMBean bean, ObjectName name) + throws Exception { + if (server == null || server.isRegistered(name)) { + return; + } + this.server.registerMBean(bean, name); + this.registry.add(name); + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.jackrabbit.core.jmx.JmxRegistry#unregister(javax.management + * .ObjectName) + */ + public void unregister(ObjectName name) throws Exception { + if (server == null || !server.isRegistered(name)) { + return; + } + registry.remove(name); + server.unregisterMBean(name); + } + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryImpl.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManager.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManager.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManager.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManager.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,54 @@ +/* + * 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.jackrabbit.core.jmx.registry; + +/** + * JmxRegistryManagerMBean default implementation + * + */ +public class JmxRegistryManager implements JmxRegistryManagerMBean { + + private final JmxRegistry jmxRegistry; + + public JmxRegistryManager(final JmxRegistry jmxRegistry) { + this.jmxRegistry = jmxRegistry; + } + + public void enableCoreStatJmx() { + jmxRegistry.enableCoreStatJmx(); + } + + public void enableQueryStatJmx() { + jmxRegistry.enableQueryStatJmx(); + } + + public boolean isEnabled() { + return true; + } + + public void reset() { + throw new UnsupportedOperationException(); + } + + public void enable() { + throw new UnsupportedOperationException(); + } + + public void disable() { + throw new UnsupportedOperationException(); + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManager.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManagerMBean.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManagerMBean.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManagerMBean.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManagerMBean.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,33 @@ +/* + * 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.jackrabbit.core.jmx.registry; + +import org.apache.jackrabbit.core.jmx.JackrabbitBaseMBean; + +/** + * JmxRegistry JMX MBean public operations + * + */ +public interface JmxRegistryManagerMBean extends JackrabbitBaseMBean { + + String NAME = DOMAIN + ":type=DynamicRegistry"; + + void enableCoreStatJmx(); + + void enableQueryStatJmx(); + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/registry/JmxRegistryManagerMBean.java ------------------------------------------------------------------------------ svn:executable = * Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/util/CachingOpsPerSecondDto.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/util/CachingOpsPerSecondDto.java?rev=1180633&view=auto ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/util/CachingOpsPerSecondDto.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/util/CachingOpsPerSecondDto.java Sun Oct 9 15:49:59 2011 @@ -0,0 +1,152 @@ +/* + * 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.jackrabbit.core.jmx.util; + +import java.math.BigDecimal; +import java.math.MathContext; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +/** + * Statistical data structure, use to compute stats on operations + * + */ +public class CachingOpsPerSecondDto { + + // @ 1 min + public static long DEFAULT_UPDATE_FREQ_MS = 1000 * 60 * 1; + + private final long updateFreqMs; + + private final ReadWriteLock rwl = new ReentrantReadWriteLock(); + private final Lock r = rwl.readLock(); + private final Lock w = rwl.writeLock(); + + // intermediary values + + private long lastUpdate = System.currentTimeMillis(); + + private long startMs = System.currentTimeMillis(); + + private long operations = 0; + + private long totalTimeNs = 0; + + // cached stats + + private double opsPerSecond = 0; + + private double opAvgTime = 0; + + public CachingOpsPerSecondDto(long updateFreqMs) { + this.updateFreqMs = updateFreqMs; + } + + public CachingOpsPerSecondDto() { + this(DEFAULT_UPDATE_FREQ_MS); + } + + public void onOp(long timeNs) { + w.lock(); + try { + final long localStart = System.currentTimeMillis() - timeNs / 1000; + if (localStart < startMs) { + startMs = localStart; + } + operations++; + totalTimeNs += timeNs; + } finally { + w.unlock(); + } + } + + public double getOpsPerSecond() { + checkUpdate(false); + return opsPerSecond; + } + + public double getOpAvgTime() { + checkUpdate(false); + return opAvgTime; + } + + private void checkUpdate(boolean forceUpdate) { + r.lock(); + final long now = System.currentTimeMillis(); + try { + if (!forceUpdate && now - lastUpdate < updateFreqMs) { + return; + } + } finally { + r.unlock(); + } + w.lock(); + try { + if (!forceUpdate && now - lastUpdate < updateFreqMs) { + return; + } + update(now); + } finally { + w.unlock(); + } + } + + private final static BigDecimal thousand = BigDecimal.valueOf(1000); + + private final static MathContext DEFAULT_CONTEXT = new MathContext(3); + + private void update(long now) { + if (operations == 0) { + opsPerSecond = 0; + opAvgTime = 0; + return; + } + long durationMs = now - startMs; + if (durationMs == 0) { + durationMs = 1000; + } + opsPerSecond = BigDecimal.valueOf(operations).multiply(thousand) + .divide(BigDecimal.valueOf(durationMs), DEFAULT_CONTEXT) + .doubleValue(); + opAvgTime = BigDecimal.valueOf(totalTimeNs) + .divide(BigDecimal.valueOf(operations), DEFAULT_CONTEXT) + .doubleValue(); + // reset if needed + if (operations > Long.MAX_VALUE - 5000) { + reset(); + } + } + + public void reset() { + w.lock(); + try { + opsPerSecond = 0; + opAvgTime = 0; + lastUpdate = System.currentTimeMillis(); + operations = 0; + startMs = lastUpdate; + totalTimeNs = 0; + } finally { + w.unlock(); + } + } + + protected void refresh() { + checkUpdate(true); + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/util/CachingOpsPerSecondDto.java ------------------------------------------------------------------------------ svn:executable = *