You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-dev@lucene.apache.org by "Luke Lu (JIRA)" <ji...@apache.org> on 2007/10/21 03:05:50 UTC

[jira] Updated: (SOLR-388) Refactor ResponseWriters and Friends.

     [ https://issues.apache.org/jira/browse/SOLR-388?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luke Lu updated SOLR-388:
-------------------------

    Description: 
When developing custom request handlers, it's often necessary to create corresponding response writers that extends existing ones. In our case, we want to augment the result list (more attributes other than numFound, maxScore, on the fly per doc attributes that are not fields etc.) , only to find JSONWriter and friends are private to the package. We could copy the whole thing and modify it, but it wouldn't take advantage of recent fixes like Yonik's FastWriter changes without tedious manual intervention. I hope that we can can *at least* extends it and overrides writeVal() to add a new result type to call writeMyType. 

Ideally the ResponseWriter hierarchy could be rewritten to take advantage of a double dispatching trick to get rid of the ugly if something is instance of someclass else ... list, as it clearly doesn't scale well with number of types (_n_) and depth (_d_) of the writer hierarchy, as the complexity would be O(nd), which is obviously inferior to the O(1) double dispatching mechanism. Some pseudo code here:

{code:title=SomeResponseWriter.java}
// a list of overloaded write method
public void write(SomeType t) {
  // implementation
}
{code}

{code:title=ResponseWritable.java}
// an interface for object that support the scheme
public interface ResponseWritable {
  public abstract void write(ResponseWriter writer);
}
{code}

{code:title=SomeType.java}
// Sometype needs to implement the ResponseWritable interface
// to facilitate double dispatching
public void write(ResponseWriter writer) {
  writer.write(this);
}
{code}

So when adding a new MyType and MySomeResponseWriter, we only need to add these two files without having to muck with the writeVal if-then-else list. Note, you still need to use the if else list for builtin types and any types that you can't modify in the write(Object) method. 

{code:title=MyType.java}
// implements the ResponseWritable interface
public write(ResponseWriter writer) {
  writer.write(this);
}
{code}

{code:title=MySomeResponseWriter.java}
//  only need to implement this method
public void write(MyType t) {
  // implementation
}
{code}



  was:
When developing custom request handlers, it's often necessary to create corresponding response writers that extends existing ones. In our case, we want to augment the result list (more attributes other than numFound, maxScore, on the fly per doc attributes that are not fields etc.) , only to find JSONWriter and friends are private to the package. We could copy the whole thing and modify it, but it wouldn't take advantage of recent fixes like Yonik's FastWriter changes without tedious manual intervention. I hope that we can can *at least* extends it and overrides writeVal() to add a new result type to call writeMyType. 

Ideally the ResponseWriter hierarchy could be rewritten to take advantage of a double dispatching trick to get rid of the ugly if something is instance of someclass else ... list, as it clearly doesn't scale well with number of types (n) and depth (d) of the writer hierarchy, as the complexity would be O(nd), which is obviously inferior to the O(1) double dispatching mechanism. Some pseudo code here:

{code:title=SomeResponseWriter.java}
// a list of overloaded write method
public void write(SomeType t) {
  // implementation
}
{code}

{code:title=ResponseWritable.java}
// an interface for object that support the scheme
public interface ResponseWritable {
  public abstract void write(ResponseWriter writer);
}
{code}

{code:title=SomeType.java}
// Sometype needs to implement the ResponseWritable interface
// to facilitate double dispatching
public void write(ResponseWriter writer) {
  writer.write(this);
}
{code}

So when adding a new MyType and MySomeResponseWriter, we only need to add these two files without having to muck with the writeVal if-then-else list. Note, you still need to use the if else list for builtin types and any types that you can't modify in the write(Object) method. 

{code:title=MyType}
// implements the ResponseWritable interface
public write(ResponseWriter writer) {
  writer.write(this);
}

{code:title=MySomeResponseWriter.java}
//  only need to implement this method
public void write(MyType t) {
  // implementation
}
{code}




> Refactor ResponseWriters and Friends.
> -------------------------------------
>
>                 Key: SOLR-388
>                 URL: https://issues.apache.org/jira/browse/SOLR-388
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>    Affects Versions: 1.2, 1.3
>            Reporter: Luke Lu
>
> When developing custom request handlers, it's often necessary to create corresponding response writers that extends existing ones. In our case, we want to augment the result list (more attributes other than numFound, maxScore, on the fly per doc attributes that are not fields etc.) , only to find JSONWriter and friends are private to the package. We could copy the whole thing and modify it, but it wouldn't take advantage of recent fixes like Yonik's FastWriter changes without tedious manual intervention. I hope that we can can *at least* extends it and overrides writeVal() to add a new result type to call writeMyType. 
> Ideally the ResponseWriter hierarchy could be rewritten to take advantage of a double dispatching trick to get rid of the ugly if something is instance of someclass else ... list, as it clearly doesn't scale well with number of types (_n_) and depth (_d_) of the writer hierarchy, as the complexity would be O(nd), which is obviously inferior to the O(1) double dispatching mechanism. Some pseudo code here:
> {code:title=SomeResponseWriter.java}
> // a list of overloaded write method
> public void write(SomeType t) {
>   // implementation
> }
> {code}
> {code:title=ResponseWritable.java}
> // an interface for object that support the scheme
> public interface ResponseWritable {
>   public abstract void write(ResponseWriter writer);
> }
> {code}
> {code:title=SomeType.java}
> // Sometype needs to implement the ResponseWritable interface
> // to facilitate double dispatching
> public void write(ResponseWriter writer) {
>   writer.write(this);
> }
> {code}
> So when adding a new MyType and MySomeResponseWriter, we only need to add these two files without having to muck with the writeVal if-then-else list. Note, you still need to use the if else list for builtin types and any types that you can't modify in the write(Object) method. 
> {code:title=MyType.java}
> // implements the ResponseWritable interface
> public write(ResponseWriter writer) {
>   writer.write(this);
> }
> {code}
> {code:title=MySomeResponseWriter.java}
> //  only need to implement this method
> public void write(MyType t) {
>   // implementation
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.