lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1195963 - in /lucene/dev/branches/lucene2621/lucene: contrib/misc/src/java/org/apache/lucene/index/codecs/spi/ contrib/misc/src/resources/META-INF/services/ src/java/org/apache/lucene/index/codecs/ src/java/org/apache/lucene/index/codecs/l...
Date Tue, 01 Nov 2011 12:38:42 GMT
Author: uschindler
Date: Tue Nov  1 12:38:41 2011
New Revision: 1195963

URL: http://svn.apache.org/viewvc?rev=1195963&view=rev
Log:
LUCENE-3490: Remove CodecProvider again by enforcing parameter-less ctors for Codecs and PostingFormats.

Added:
    lucene/dev/branches/lucene2621/lucene/contrib/misc/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/NamedSPILoader.java
  (with props)
    lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
    lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat
    lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
    lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat
Removed:
    lucene/dev/branches/lucene2621/lucene/contrib/misc/src/java/org/apache/lucene/index/codecs/spi/
    lucene/dev/branches/lucene2621/lucene/contrib/misc/src/resources/META-INF/services/org.apache.lucene.index.codecs.spi.CodecProvider
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/spi/
    lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.spi.CodecProvider
    lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/spi/
    lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.spi.CodecProvider
Modified:
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/Codec.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/PostingsFormat.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40Codec.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsFormat.java
    lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockPostingsFormat.java
    lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockPostingsFormat.java

Added: lucene/dev/branches/lucene2621/lucene/contrib/misc/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/contrib/misc/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec?rev=1195963&view=auto
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/contrib/misc/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
(added)
+++ lucene/dev/branches/lucene2621/lucene/contrib/misc/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
Tue Nov  1 12:38:41 2011
@@ -0,0 +1,16 @@
+#  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.
+
+org.apache.lucene.index.codecs.appending.AppendingCodec

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/Codec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/Codec.java?rev=1195963&r1=1195962&r2=1195963&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/Codec.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/Codec.java
Tue Nov  1 12:38:41 2011
@@ -21,19 +21,24 @@ import java.io.IOException;
 import java.util.Set;
 
 import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.index.codecs.spi.CodecLoader;
+import org.apache.lucene.util.NamedSPILoader;
 import org.apache.lucene.store.Directory;
 
 /**
  * Encodes/decodes an inverted index segment
  */
-public abstract class Codec {
+public abstract class Codec implements NamedSPILoader.NamedSPI {
+
+  private static final NamedSPILoader<Codec> loader =
+    new NamedSPILoader<Codec>(Codec.class);
+
   private final String name;
 
   public Codec(String name) {
     this.name = name;
   }
   
+  @Override
   public String getName() {
     return name;
   }
@@ -63,7 +68,12 @@ public abstract class Codec {
   
   /** looks up a codec by name */
   public static Codec forName(String name) {
-    return CodecLoader.lookupCodec(name);
+    return loader.lookup(name);
+  }
+  
+  /** returns a list of all available codec names */
+  public static Set<String> availableCodecs() {
+    return loader.availableServices();
   }
   
   private static Codec defaultCodec = Codec.forName("Lucene40");

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/PostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/PostingsFormat.java?rev=1195963&r1=1195962&r2=1195963&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/PostingsFormat.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/PostingsFormat.java
Tue Nov  1 12:38:41 2011
@@ -23,21 +23,32 @@ import java.util.Set;
 import org.apache.lucene.index.SegmentInfo;
 import org.apache.lucene.index.SegmentWriteState;
 import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.codecs.spi.CodecLoader;
+import org.apache.lucene.util.NamedSPILoader;
 
 import org.apache.lucene.store.Directory;
 
 /** @lucene.experimental */
-public abstract class PostingsFormat {
+public abstract class PostingsFormat implements NamedSPILoader.NamedSPI {
+
+  private static final NamedSPILoader<PostingsFormat> loader =
+    new NamedSPILoader<PostingsFormat>(PostingsFormat.class);
+
   public static final PostingsFormat[] EMPTY = new PostingsFormat[0];
   /** Unique name that's used to retrieve this codec when
-   *  reading the index */
+   *  reading the index.
+   * nocommit: Make private
+   */
   public final String name;
   
   protected PostingsFormat(String name) {
     this.name = name;
   }
 
+  @Override
+  public String getName() {
+    return name;
+  }
+  
   /** Writes a new segment */
   public abstract FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException;
 
@@ -61,7 +72,14 @@ public abstract class PostingsFormat {
     return "PostingsFormat(name=" + name + ")";
   }
   
+  /** looks up a codec by name */
   public static PostingsFormat forName(String name) {
-    return CodecLoader.lookupPostingsFormat(name);
+    return loader.lookup(name);
+  }
+  
+  /** returns a list of all available codec names */
+  public static Set<String> availablePostingsFormats() {
+    return loader.availableServices();
   }
+  
 }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40Codec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40Codec.java?rev=1195963&r1=1195962&r2=1195963&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40Codec.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40Codec.java
Tue Nov  1 12:38:41 2011
@@ -72,6 +72,5 @@ public class Lucene40Codec extends Codec
     return defaultFormat;
   }
   
-  // TODO: PostingsFormat.forName("Lucene40") does not work because of Chicken-and-Egg problem:
-  private final PostingsFormat defaultFormat = new Lucene40PostingsFormat();
+  private final PostingsFormat defaultFormat = PostingsFormat.forName("Lucene40");
 }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsFormat.java?rev=1195963&r1=1195962&r2=1195963&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsFormat.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/pulsing/PulsingPostingsFormat.java
Tue Nov  1 12:38:41 2011
@@ -31,6 +31,7 @@ import org.apache.lucene.index.codecs.Po
 import org.apache.lucene.index.codecs.PostingsFormat;
 import org.apache.lucene.index.codecs.FieldsConsumer;
 import org.apache.lucene.index.codecs.FieldsProducer;
+import org.apache.lucene.index.codecs.lucene40.Lucene40PostingsBaseFormat;
 import org.apache.lucene.store.Directory;
 
 /** This postings format "inlines" the postings for terms that have
@@ -50,6 +51,11 @@ public class PulsingPostingsFormat exten
   private final int minBlockSize;
   private final int maxBlockSize;
   private final PostingsBaseFormat wrappedPostingsBaseFormat;
+  
+  // nocommit: maybe create subclass with Lucene40 postings, e.g. Lucene40PulsingPostingsFormat
-- se above comment
+  public PulsingPostingsFormat() {
+    this(new Lucene40PostingsBaseFormat(), 1);
+  }
 
   public PulsingPostingsFormat(PostingsBaseFormat wrappedPostingsBaseFormat, int freqCutoff)
{
     this(wrappedPostingsBaseFormat, freqCutoff, BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE,
BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE);

Added: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/NamedSPILoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/NamedSPILoader.java?rev=1195963&view=auto
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/NamedSPILoader.java
(added)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/util/NamedSPILoader.java
Tue Nov  1 12:38:41 2011
@@ -0,0 +1,73 @@
+package org.apache.lucene.util;
+
+/**
+ * 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.
+ */
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.LinkedHashMap;
+import java.util.Set;
+import java.util.ServiceLoader;
+
+/**
+ * Helper class for loading named SPIs from classpath (e.g. Codec, PostingsFormat).
+ * @lucene.internal
+ */
+public final class NamedSPILoader<S extends NamedSPILoader.NamedSPI> implements Iterable<S>
{
+
+  private final Map<String,S> services;
+  private final Class<S> clazz;
+
+  public NamedSPILoader(Class<S> clazz) {
+    this.clazz = clazz;
+    final ServiceLoader<S> loader = ServiceLoader.load(clazz);
+    final LinkedHashMap<String,S> services = new LinkedHashMap<String,S>();
+    for (final S service : loader) {
+      final String name = service.getName();
+      // only add the first one for each name, later services will be ignored
+      // this allows to place services before others in classpath to make 
+      // them used instead of others
+      if (!services.containsKey(name)) {
+        services.put(name, service);
+      }
+    }
+    this.services = Collections.unmodifiableMap(services);
+    System.out.println("Loaded SPIs of type "+clazz.getName()+": "+services);
+  }
+  
+  public S lookup(String name) {
+    final S service = services.get(name);
+    if (service != null) return service;
+    throw new IllegalArgumentException("A SPI class of type "+clazz.getName()+" with name
'"+name+"' does not exist. "+
+     "You need to add the corresponding JAR file supporting this SPI to your classpath."+
+     "The current classpath supports the following names: "+availableServices());
+  }
+
+  public Set<String> availableServices() {
+    return services.keySet();
+  }
+  
+  public Iterator<S> iterator() {
+    return services.values().iterator();
+  }
+  
+  public static interface NamedSPI {
+    String getName();
+  }
+  
+}

Added: lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec?rev=1195963&view=auto
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
(added)
+++ lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
Tue Nov  1 12:38:41 2011
@@ -0,0 +1,17 @@
+#  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.
+
+org.apache.lucene.index.codecs.lucene40.Lucene40Codec
+org.apache.lucene.index.codecs.lucene3x.Lucene3xCodec

Added: lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat?rev=1195963&view=auto
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat
(added)
+++ lucene/dev/branches/lucene2621/lucene/src/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat
Tue Nov  1 12:38:41 2011
@@ -0,0 +1,19 @@
+#  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.
+
+org.apache.lucene.index.codecs.lucene40.Lucene40PostingsFormat
+org.apache.lucene.index.codecs.pulsing.PulsingPostingsFormat
+org.apache.lucene.index.codecs.simpletext.SimpleTextPostingsFormat
+org.apache.lucene.index.codecs.memory.MemoryPostingsFormat

Modified: lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockPostingsFormat.java?rev=1195963&r1=1195962&r2=1195963&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockPostingsFormat.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockFixedIntBlockPostingsFormat.java
Tue Nov  1 12:38:41 2011
@@ -62,6 +62,10 @@ public class MockFixedIntBlockPostingsFo
 
   private final int blockSize;
 
+  public MockFixedIntBlockPostingsFormat() {
+    this(1);
+  }
+
   public MockFixedIntBlockPostingsFormat(int blockSize) {
     super("MockFixedIntBlock");
     this.blockSize = blockSize;

Modified: lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockPostingsFormat.java?rev=1195963&r1=1195962&r2=1195963&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockPostingsFormat.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mockintblock/MockVariableIntBlockPostingsFormat.java
Tue Nov  1 12:38:41 2011
@@ -65,6 +65,10 @@ import org.apache.lucene.util.IOUtils;
 public class MockVariableIntBlockPostingsFormat extends PostingsFormat {
   private final int baseBlockSize;
   
+  public MockVariableIntBlockPostingsFormat() {
+    this(1);
+  }
+
   public MockVariableIntBlockPostingsFormat(int baseBlockSize) {
     super("MockVariableIntBlock");
     this.baseBlockSize = baseBlockSize;

Added: lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.Codec?rev=1195963&view=auto
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
(added)
+++ lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.Codec
Tue Nov  1 12:38:41 2011
@@ -0,0 +1,16 @@
+#  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.
+
+org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec

Added: lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat?rev=1195963&view=auto
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat
(added)
+++ lucene/dev/branches/lucene2621/lucene/src/test-framework/resources/META-INF/services/org.apache.lucene.index.codecs.PostingsFormat
Tue Nov  1 12:38:41 2011
@@ -0,0 +1,19 @@
+#  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.
+
+org.apache.lucene.index.codecs.mockintblock.MockFixedIntBlockPostingsFormat
+org.apache.lucene.index.codecs.mockintblock.MockVariableIntBlockPostingsFormat
+org.apache.lucene.index.codecs.mockrandom.MockRandomPostingsFormat
+org.apache.lucene.index.codecs.mocksep.MockSepPostingsFormat



Mime
View raw message