here it is ...

1) I take aan object
2) get its interfaces using reflection
3) get the interfaces those interfaces extend (if any)
4) until I find an interface that extends Remote
5) and that's the one I use to create the name of the stub

it gives a little screenoutput with how long it takes to come up with the
name. On my machine (P3 whatever) it takes <1 (0) millis.


Rob van Oostrum wrote:

> hang on I'll do a quick-and-dirty benchmark. I've done scarier things with
> reflection than this, and I wouldn't categorize them as "extremely" slow.
> I suspect just looking up an implemented interface shouldn't cause too
> much problems
>
> Stefan Bodewig wrote:
>
> > Rob van Oostrum <[EMAIL PROTECTED]> wrote:
> >
> > > I'm not 100% sure on this, but I thought the convention is to always
> > > call your implementation InterfaceNameImpl. If this is true, you
> > > could just do a straight-forward text treatment and drop de Impl
> > > from the implementation class.
> >
> > Possible, but I wouldn't want to rely on this.  I fear using
> > reflection here would be extremely slow.
> >
> > Stefan
import java.rmi.Remote;

public class ReflectionTest
{
  public static void main( String args[] )
  {
    FooImpl myFoo = new FooImpl();
    
    long begin = System.currentTimeMillis();
    String stubName = getStubName( myFoo );
    long duration  = System.currentTimeMillis() - begin;

    System.out.println( stubName + " in " + duration + " millis." );
  }

  public static String getStubName( Object object )
  {
    Class[] interfaces = object.getClass().getInterfaces();
    for ( int i = 0; i < interfaces.length; i++ )
    {
      Class[] extendedInterfaces = interfaces[i].getInterfaces();

      for ( int j = 0; j < extendedInterfaces.length; j++ )
      {
        if ( extendedInterfaces[j].equals( Remote.class ) )
        {
          return ( interfaces[i].toString() + "_Stub" );
        }
      }
    }

    return null;
  }
}
import java.rmi.Remote;

public interface Foo extends Remote
{
}

Êþº¾-
<init>()VCodeLineNumberTableLocalVariableTablethis    
 LFooImpl;
SourceFileFooImpl.java
FooImpljava/lang/ObjectFoo!/*·±
     

public class FooImpl implements Foo
{
}

ReflectionTest.class

Êþº¾-       
SourceFileFoo.javaFoojava/lang/Objectjava/rmi/Remote

Reply via email to