jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1451558 - in /jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr: OakSolrUtils.java index/SolrIndexHookProvider.java query/SolrQueryIndex.java query/SolrQueryIndexProvider.java
Date Fri, 01 Mar 2013 10:33:39 GMT
Author: tommaso
Date: Fri Mar  1 10:33:38 2013
New Revision: 1451558

URL: http://svn.apache.org/r1451558
Log:
OAK-651 - added null checks, added OSU adaption methods for SSP and OSC, set incorrect info
logging to debug

Modified:
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java?rev=1451558&r1=1451557&r2=1451558&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
Fri Mar  1 10:33:38 2013
@@ -52,11 +52,19 @@ public class OakSolrUtils {
      * @return a {@link SolrIndexHookProvider}
      */
     public static IndexHookProvider adaptOsgiIndexHookProvider() {
-        BundleContext ctx = BundleReference.class.cast(SolrIndexHookProvider.class
-                .getClassLoader()).getBundle().getBundleContext();
+        IndexHookProvider indexHookProvider = null;
+        try {
+            BundleContext ctx = BundleReference.class.cast(SolrIndexHookProvider.class
+                    .getClassLoader()).getBundle().getBundleContext();
 
-        ServiceReference serviceReference = ctx.getServiceReference(SolrIndexHookProvider.class.getName());
-        return SolrIndexHookProvider.class.cast(ctx.getService(serviceReference));
+            ServiceReference serviceReference = ctx.getServiceReference(IndexHookProvider.class.getName());
+            if (serviceReference != null) {
+                indexHookProvider = IndexHookProvider.class.cast(ctx.getService(serviceReference));
+            }
+        } catch (Throwable e) {
+            // do nothing
+        }
+        return indexHookProvider;
     }
 
     /**
@@ -65,11 +73,91 @@ public class OakSolrUtils {
      * @return a {@link SolrQueryIndexProvider}
      */
     public static QueryIndexProvider adaptOsgiQueryIndexProvider() {
-        BundleContext ctx = BundleReference.class.cast(SolrQueryIndexProvider.class
-                .getClassLoader()).getBundle().getBundleContext();
+        QueryIndexProvider queryIndexProvider = null;
+        try {
+            BundleContext ctx = BundleReference.class.cast(SolrQueryIndexProvider.class
+                    .getClassLoader()).getBundle().getBundleContext();
+
+            ServiceReference serviceReference = ctx.getServiceReference(QueryIndexProvider.class.getName());
+            if (serviceReference != null) {
+                queryIndexProvider = QueryIndexProvider.class.cast(ctx.getService(serviceReference));
+            }
+        } catch (Throwable e) {
+            // do nothing
+        }
+        return queryIndexProvider;
+    }
+
+    /**
+     * adapt the OSGi Solr {@link SolrServerProvider} service of a given extending class
+     * and tries to instantiate it if non existing.
+     *
+     * @param providerClass the {@link Class} extending {@link SolrServerProvider}
+     *                      to adapt or instantiate
+     * @param <T>           the {@link SolrServerProvider} extension
+     * @return a {@link SolrServerProvider} adapted from the OSGi service, or a
+     *         directly instantiated one or <code>null</code> if both failed
+     */
+    public static <T extends SolrServerProvider> SolrServerProvider adaptOsgiSolrServerProvider(Class<T>
providerClass) {
+        SolrServerProvider solrServerProvider = null;
+        try {
+            BundleContext ctx = BundleReference.class.cast(providerClass
+                    .getClassLoader()).getBundle().getBundleContext();
+            ServiceReference serviceReference = ctx.getServiceReference(SolrServerProvider.class.getName());
+            if (serviceReference != null) {
+                solrServerProvider = SolrServerProvider.class.cast(ctx.getService(serviceReference));
+            }
+        } catch (Exception e) {
+            // do nothing
+        }
+
+        if (solrServerProvider == null && providerClass != null) {
+            try {
+                solrServerProvider = providerClass.newInstance();
+            } catch (InstantiationException e) {
+                // do nothing
+            } catch (IllegalAccessException e) {
+                // do nothing
+            }
+        }
+
+        return solrServerProvider;
+    }
+
+    /**
+     * adapt the OSGi Solr {@link OakSolrConfigurationProvider} service of a given
+     * extending class and tries to instantiate it if non existing.
+     *
+     * @param providerClass the {@link Class} extending {@link OakSolrConfigurationProvider}
+     *                      to adapt or instantiate
+     * @param <T>           the {@link OakSolrConfigurationProvider} extension
+     * @return a {@link OakSolrConfigurationProvider} adapted from the OSGi service, or a
+     *         directly instantiated one or <code>null</code> if both failed
+     */
+    public static <T extends OakSolrConfigurationProvider> OakSolrConfigurationProvider
adaptOsgiOakSolrConfigurationProvider(Class<T> providerClass) {
+        OakSolrConfigurationProvider oakSolrConfigurationProvider = null;
+        try {
+            BundleContext ctx = BundleReference.class.cast(providerClass
+                    .getClassLoader()).getBundle().getBundleContext();
+            ServiceReference serviceReference = ctx.getServiceReference(OakSolrConfigurationProvider.class.getName());
+            if (serviceReference != null) {
+                oakSolrConfigurationProvider = OakSolrConfigurationProvider.class.cast(ctx.getService(serviceReference));
+            }
+        } catch (Exception e) {
+            // do nothing
+        }
+
+        if (oakSolrConfigurationProvider == null && providerClass != null) {
+            try {
+                oakSolrConfigurationProvider = providerClass.newInstance();
+            } catch (InstantiationException e) {
+                // do nothing
+            } catch (IllegalAccessException e) {
+                // do nothing
+            }
+        }
 
-        ServiceReference serviceReference = ctx.getServiceReference(SolrQueryIndexProvider.class.getName());
-        return SolrQueryIndexProvider.class.cast(ctx.getService(serviceReference));
+        return oakSolrConfigurationProvider;
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java?rev=1451558&r1=1451557&r2=1451558&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java
Fri Mar  1 10:33:38 2013
@@ -63,11 +63,12 @@ public class SolrIndexHookProvider imple
     @Override
     @Nonnull
     public List<? extends IndexHook> getIndexHooks(String type, NodeBuilder builder)
{
-        if (SolrQueryIndex.TYPE.equals(type)) {
-            if (log.isInfoEnabled()) {
-                log.info("Creating a Solr index hook");
-            }
+
+        if (SolrQueryIndex.TYPE.equals(type) && solrServerProvider != null &&
oakSolrConfigurationProvider != null) {
             try {
+                if (log.isDebugEnabled()) {
+                    log.debug("Creating a Solr index hook");
+                }
                 IndexHook indexHook = new SolrIndexDiff(builder, solrServerProvider.getSolrServer(),
oakSolrConfigurationProvider.getConfiguration());
                 return ImmutableList.of(indexHook);
             } catch (Exception e) {

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java?rev=1451558&r1=1451557&r2=1451558&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
Fri Mar  1 10:33:38 2013
@@ -150,8 +150,8 @@ public class SolrQueryIndex implements Q
         String escapedQuery = queryBuilder.toString();
         solrQuery.setQuery(escapedQuery);
 
-        if (log.isInfoEnabled()) {
-            log.info(new StringBuilder("JCR query: \n" + filter.getQueryStatement() + " \nhas
been converted to Solr query: \n").
+        if (log.isDebugEnabled()) {
+            log.debug(new StringBuilder("JCR query: \n" + filter.getQueryStatement() + "
\nhas been converted to Solr query: \n").
                     append(solrQuery.toString()).toString());
         }
 

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java?rev=1451558&r1=1451557&r2=1451558&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndexProvider.java
Fri Mar  1 10:33:38 2013
@@ -65,11 +65,13 @@ public class SolrQueryIndexProvider impl
         List<QueryIndex> tempIndexes = new ArrayList<QueryIndex>();
         for (IndexDefinition child : buildIndexDefinitions(nodeState, "/",
                 SolrQueryIndex.TYPE)) {
-            if (log.isInfoEnabled()) {
-                log.info("found a Solr index definition {}", child);
+            if (log.isDebugEnabled()) {
+                log.debug("found a Solr index definition {}", child);
             }
             try {
-                tempIndexes.add(new SolrQueryIndex(child, solrServerProvider.getSolrServer(),
oakSolrConfigurationProvider.getConfiguration()));
+                if (solrServerProvider != null && oakSolrConfigurationProvider !=
null) {
+                    tempIndexes.add(new SolrQueryIndex(child, solrServerProvider.getSolrServer(),
oakSolrConfigurationProvider.getConfiguration()));
+                }
             } catch (Exception e) {
                 log.error("unable to create Solr query index at {} due to {}", new Object[]{child.getPath(),
e});
             }



Mime
View raw message