Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2A34F1062C for ; Thu, 7 Nov 2013 13:57:00 +0000 (UTC) Received: (qmail 60307 invoked by uid 500); 7 Nov 2013 13:54:54 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 59861 invoked by uid 500); 7 Nov 2013 13:54:14 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 58905 invoked by uid 99); 7 Nov 2013 13:53:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Nov 2013 13:53:26 +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; Thu, 07 Nov 2013 13:53:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4E9E923888A6; Thu, 7 Nov 2013 13:53:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1539640 - in /jackrabbit/oak/trunk/oak-core/src/main: java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java resources/OSGI-INF/metatype/metatype.properties Date: Thu, 07 Nov 2013 13:53:01 -0000 To: oak-commits@jackrabbit.apache.org From: mreutegg@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131107135301.4E9E923888A6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mreutegg Date: Thu Nov 7 13:53:00 2013 New Revision: 1539640 URL: http://svn.apache.org/r1539640 Log: OAK-1080: MongoMK: improved concurrency - expose MongoNodeStore as OSGi service Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java (with props) Modified: jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java?rev=1539640&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java Thu Nov 7 13:53:00 2013 @@ -0,0 +1,166 @@ +/* + * 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.oak.plugins.mongomk; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.ConfigurationPolicy; +import org.apache.felix.scr.annotations.Property; +import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean; +import org.apache.jackrabbit.oak.plugins.mongomk.util.MongoConnection; +import org.apache.jackrabbit.oak.spi.state.NodeStore; +import org.apache.jackrabbit.oak.spi.whiteboard.OsgiWhiteboard; +import org.apache.jackrabbit.oak.spi.whiteboard.Registration; +import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard; +import org.apache.sling.commons.osgi.PropertiesUtil; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.annotations.Deactivate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.mongodb.DB; + +import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean; + +/** + * The OSGi service to start/stop a MongoNodeStore instance. + */ +@Component(metatype = true, + label = "%oak.mongons.label", + description = "%oak.mongons.description", + policy = ConfigurationPolicy.REQUIRE +) +public class MongoNodeStoreService { + + private static final String DEFAULT_HOST = "localhost"; + private static final int DEFAULT_PORT = 27017; + private static final String DEFAULT_DB = "oak"; + private static final int DEFAULT_CACHE = 256; + + @Property(value = DEFAULT_HOST) + private static final String PROP_HOST = "host"; + + @Property(intValue = DEFAULT_PORT) + private static final String PROP_PORT = "port"; + + @Property(value = DEFAULT_DB) + private static final String PROP_DB = "db"; + + @Property(intValue = DEFAULT_CACHE) + private static final String PROP_CACHE = "cache"; + private static final long MB = 1024 * 1024; + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + private ServiceRegistration reg; + private MongoNodeStore store; + private final List registrations = new ArrayList(); + + @Activate + private void activate(BundleContext context, Map config) + throws Exception { + String host = PropertiesUtil.toString(config.get(PROP_HOST), DEFAULT_HOST); + int port = PropertiesUtil.toInteger(config.get(PROP_PORT), DEFAULT_PORT); + String db = PropertiesUtil.toString(config.get(PROP_DB), DEFAULT_DB); + int cacheSize = PropertiesUtil.toInteger(config.get(PROP_CACHE), DEFAULT_CACHE); + + logger.info("Starting MongoDB NodeStore with host={}, port={}, db={}", + new Object[] {host, port, db}); + + MongoConnection connection = new MongoConnection(host, port, db); + DB mongoDB = connection.getDB(); + + logger.info("Connected to database {}", mongoDB); + + MongoMK mk = new MongoMK.Builder() + .memoryCacheSize(cacheSize * MB) + .setMongoDB(mongoDB) + .open(); + store = mk.getNodeStore(); + + registerJMXBeans(mk, context); + + reg = context.registerService(NodeStore.class.getName(), store, new Properties()); + } + + private void registerJMXBeans(MongoMK mk, BundleContext context) { + Whiteboard wb = new OsgiWhiteboard(context); + registrations.add( + registerMBean(wb, + CacheStatsMBean.class, + mk.getNodeCacheStats(), + CacheStatsMBean.TYPE, + mk.getNodeCacheStats().getName()) + ); + registrations.add( + registerMBean(wb, + CacheStatsMBean.class, + mk.getNodeChildrenCacheStats(), + CacheStatsMBean.TYPE, + mk.getNodeChildrenCacheStats().getName()) + ); + registrations.add( + registerMBean(wb, + CacheStatsMBean.class, + mk.getDiffCacheStats(), + CacheStatsMBean.TYPE, + mk.getDiffCacheStats().getName()) + ); + registrations.add( + registerMBean(wb, + CacheStatsMBean.class, + mk.getDocChildrenCacheStats(), + CacheStatsMBean.TYPE, + mk.getDocChildrenCacheStats().getName()) + ); + + DocumentStore ds = mk.getDocumentStore(); + if (ds instanceof MongoDocumentStore) { + MongoDocumentStore mds = (MongoDocumentStore) ds; + registrations.add( + registerMBean(wb, + CacheStatsMBean.class, + mds.getCacheStats(), + CacheStatsMBean.TYPE, + mds.getCacheStats().getName()) + ); + } + } + + @Deactivate + private void deactivate() { + for (Registration r : registrations) { + r.unregister(); + } + + if (reg != null) { + reg.unregister(); + } + + if (store != null) { + store.dispose(); + } + } +} Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/mongomk/MongoNodeStoreService.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1539640&r1=1539639&r2=1539640&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties (original) +++ jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties Thu Nov 7 13:53:00 2013 @@ -21,6 +21,10 @@ oak.mongomk.label=Apache Jackrabbit Oak oak.mongomk.description= Configure an instance of the MongoDB \ based MicroKernel implementation +oak.mongons.label=Apache Jackrabbit Oak MongoNodeStore Service +oak.mongons.description= Configure an instance of the MongoDB \ + based MongoNodeStore implementation + host.name = MongoDB Host host.description = The host to connect to.