Author: shalin
Date: Fri Dec 19 05:22:05 2008
New Revision: 728017
URL: http://svn.apache.org/viewvc?rev=728017&view=rev
Log:
SOLR-885 -- Changing NamedListCodec to return Object
Modified:
lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedListCodec.java
lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java
lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java
lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/impl/BinaryResponseParser.java
lucene/solr/trunk/src/test/org/apache/solr/common/util/TestNamedListCodec.java
lucene/solr/trunk/src/test/org/apache/solr/request/TestBinaryResponseWriter.java
Modified:
lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedListCodec.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedListCodec.java?rev=728017&r1=728016&r2=728017&view=diff
==============================================================================
---
lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedListCodec.java
(original)
+++
lucene/solr/trunk/src/common/org/apache/solr/common/util/NamedListCodec.java
Fri Dec 19 05:22:05 2008
@@ -30,6 +30,9 @@
* It is expected that this class is used on both end of the pipes.
* The class has one read method and one write method for each of the datatypes
*
+ * Note -- Never re-use an instance of this class for more than one marshal or
unmarshall operation.
+ * Always create a new instance.
+ *
*/
public class NamedListCodec {
@@ -63,9 +66,9 @@
EXTERN_STRING = (byte)(7 << 5);
- private byte VERSION = 1;
+ private static byte VERSION = 1;
private ObjectResolver resolver;
- private FastOutputStream daos;
+ protected FastOutputStream daos;
public NamedListCodec() { }
@@ -73,20 +76,24 @@
this.resolver = resolver;
}
- public void marshal(NamedList nl, OutputStream os) throws IOException {
+ public void marshal(Object nl, OutputStream os) throws IOException {
daos = FastOutputStream.wrap(os);
try {
daos.writeByte(VERSION);
- writeNamedList(nl);
+ writeVal(nl);
} finally {
daos.flushBuffer();
}
}
+ byte version;
- public NamedList unmarshal(InputStream is) throws IOException {
+ public Object unmarshal(InputStream is) throws IOException {
FastInputStream dis = FastInputStream.wrap(is);
- byte version = dis.readByte();
- return (NamedList)readVal(dis);
+ version = dis.readByte();
+ if(version != VERSION){
+ throw new RuntimeException("Invalid version or the data in not in
'javabin' format");
+ }
+ return (Object)readVal(dis);
}
@@ -136,7 +143,7 @@
writeVal(val.getClass().getName() + ':' + val.toString());
}
- private static final Object END_OBJ = new Object();
+ protected static final Object END_OBJ = new Object();
byte tagByte;
public Object readVal(FastInputStream dis) throws IOException {
@@ -386,7 +393,7 @@
char[] charArr;
- private String readStr(FastInputStream dis) throws IOException {
+ public String readStr(FastInputStream dis) throws IOException {
int sz = readSize(dis);
if (charArr==null || charArr.length < sz) {
charArr = new char[sz];
Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java?rev=728017&r1=728016&r2=728017&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/SnapPuller.java Fri Dec
19 05:22:05 2008
@@ -171,7 +171,7 @@
throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE,
"Request failed for the url " + method);
}
- return new NamedListCodec().unmarshal(method.getResponseBodyAsStream());
+ return (NamedList) new
NamedListCodec().unmarshal(method.getResponseBodyAsStream());
} finally {
try {
method.releaseConnection();
Modified:
lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java?rev=728017&r1=728016&r2=728017&view=diff
==============================================================================
---
lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java
(original)
+++
lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java
Fri Dec 19 05:22:05 2008
@@ -181,11 +181,10 @@
Resolver resolver = new Resolver(req, rsp.getReturnFields());
ByteArrayOutputStream out = new ByteArrayOutputStream();
- NamedListCodec codec = new NamedListCodec(resolver);
- codec.marshal(rsp.getValues(), out);
+ new NamedListCodec(resolver).marshal(rsp.getValues(), out);
InputStream in = new ByteArrayInputStream(out.toByteArray());
- return codec.unmarshal(in);
+ return (NamedList<Object>) new NamedListCodec(resolver).unmarshal(in);
}
catch (Exception ex) {
throw new RuntimeException(ex);
Modified:
lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/impl/BinaryResponseParser.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/impl/BinaryResponseParser.java?rev=728017&r1=728016&r2=728017&view=diff
==============================================================================
---
lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/impl/BinaryResponseParser.java
(original)
+++
lucene/solr/trunk/src/solrj/org/apache/solr/client/solrj/impl/BinaryResponseParser.java
Fri Dec 19 05:22:05 2008
@@ -36,7 +36,7 @@
public NamedList<Object> processResponse(InputStream body, String encoding) {
try {
- return new NamedListCodec().unmarshal(body);
+ return (NamedList<Object>) new NamedListCodec().unmarshal(body);
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "parsing
error", e);
Modified:
lucene/solr/trunk/src/test/org/apache/solr/common/util/TestNamedListCodec.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/common/util/TestNamedListCodec.java?rev=728017&r1=728016&r2=728017&view=diff
==============================================================================
---
lucene/solr/trunk/src/test/org/apache/solr/common/util/TestNamedListCodec.java
(original)
+++
lucene/solr/trunk/src/test/org/apache/solr/common/util/TestNamedListCodec.java
Fri Dec 19 05:22:05 2008
@@ -79,7 +79,7 @@
new NamedListCodec(null).marshal(nl,baos);
byte[] arr = baos.toByteArray();
- nl = new NamedListCodec().unmarshal(new ByteArrayInputStream(arr));
+ nl = (NamedList) new NamedListCodec().unmarshal(new
ByteArrayInputStream(arr));
assertEquals(3, nl.size());
@@ -119,7 +119,7 @@
new NamedListCodec(null).marshal(nl,baos);
byte[] arr = baos.toByteArray();
- nl = new NamedListCodec().unmarshal(new ByteArrayInputStream(arr));
+ nl = (NamedList) new NamedListCodec().unmarshal(new
ByteArrayInputStream(arr));
List l = (List) nl.get("zzz");
assertEquals(list.size(), l.size());
@@ -143,7 +143,7 @@
byte[] arr = baos.toByteArray();
try {
- NamedList result = new NamedListCodec().unmarshal(new
ByteArrayInputStream(arr));
+ NamedList result = (NamedList) new NamedListCodec().unmarshal(new
ByteArrayInputStream(arr));
assertTrue("result is null and it shouldn't be", result != null);
List keys = (List) result.get("keys");
assertTrue("keys is null and it shouldn't be", keys != null);
@@ -247,7 +247,7 @@
new NamedListCodec(null).marshal(nl,baos);
byte[] arr = baos.toByteArray();
// System.out.println(arr.length);
- res = new NamedListCodec().unmarshal(new ByteArrayInputStream(arr));
+ res = (NamedList) new NamedListCodec().unmarshal(new
ByteArrayInputStream(arr));
cmp = TestDistributedSearch.compare(nl,res, 0, null);
if (cmp != null) {
Modified:
lucene/solr/trunk/src/test/org/apache/solr/request/TestBinaryResponseWriter.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/request/TestBinaryResponseWriter.java?rev=728017&r1=728016&r2=728017&view=diff
==============================================================================
---
lucene/solr/trunk/src/test/org/apache/solr/request/TestBinaryResponseWriter.java
(original)
+++
lucene/solr/trunk/src/test/org/apache/solr/request/TestBinaryResponseWriter.java
Fri Dec 19 05:22:05 2008
@@ -55,7 +55,7 @@
BinaryQueryResponseWriter writer = (BinaryQueryResponseWriter)
h.getCore().getQueryResponseWriter("javabin");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.write(baos, req, rsp);
- NamedList res = new NamedListCodec().unmarshal(new
ByteArrayInputStream(baos.toByteArray()));
+ NamedList res = (NamedList) new NamedListCodec().unmarshal(new
ByteArrayInputStream(baos.toByteArray()));
SolrDocumentList docs = (SolrDocumentList) res.get("response");
for (Object doc : docs) {
SolrDocument document = (SolrDocument) doc;