does java api have something like DescriptorPool

409 views
Skip to first unread message

Romain François

unread,
Dec 9, 2009, 8:13:55 AM12/9/09
to Protocol Buffers
Hello,

Given a service/method full name, I'd like to get hold of the
ServiceDescriptor, or MethodDescriptor. In C++ I would use the
DescriptorPool, but I don't see this in the java api.

Is there a way ?

Romain


--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/Gq7i : ohloh
|- http://tr.im/FtUu : new package : highlight
`- http://tr.im/EAD5 : LondonR slides

Jason Hsueh

unread,
Dec 9, 2009, 1:16:14 PM12/9/09
to Romain François, Protocol Buffers
No, there isn't an equivalent to the DescriptorPool in Java. If you know the types that you want you can build a mapping yourself. Or if you'd be interested in porting the C++ DescriptorPool to java that would be great!

2009/12/9 Romain François <francoi...@free.fr>

--

You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.



Kenton Varda

unread,
Dec 9, 2009, 3:00:34 PM12/9/09
to Jason Hsueh, Romain François, Protocol Buffers
Actually I don't think we need DescriptorPool in Java.  DescriptorPool was primarily written for the purpose of memory management, but Java handles that for us.  If all you need is the mapping aspect, just build a Map<String, ServiceDescriptor> yourself and use it.

True, in C++ there is the "global pool" which is automatically populated with everything compiled into the binary.  This wouldn't work in Java because classes are not loaded until they are first accessed, so there is no way to populate this pool.  Besides, singletons are evil.  I honestly wish that I'd never introduced the global pool in C++; it has lead to too many subtle singleton problems.

2009/12/9 Jason Hsueh <jas...@google.com>

Romain François

unread,
Dec 10, 2009, 3:34:35 AM12/10/09
to Kenton Varda, Jason Hsueh, Protocol Buffers
On 12/09/2009 09:00 PM, Kenton Varda wrote:
> Actually I don't think we need DescriptorPool in Java. DescriptorPool
> was primarily written for the purpose of memory management, but Java
> handles that for us. If all you need is the mapping aspect, just build
> a Map<String, ServiceDescriptor> yourself and use it.

This is close to what I do now. Next question is : can I get hold of the
java class that is associated with a Descriptor.

From the service descriptor, I can get to the MethodDescriptor I am
interested in, and then I can get the Descriptor of the input type of
the method, but at that point I would like to create a builder for the
input message. Should I also maintain a Map<String,Descriptor>

One thing I thought of would be to go back to the file descriptor
associated with the input message type descriptor, check the two java
options, and use java reflection. would this work ?

It is a shame the java class name is not the same as the message type
full name.

> True, in C++ there is the "global pool" which is automatically populated
> with everything compiled into the binary. This wouldn't work in Java
> because classes are not loaded until they are first accessed, so there
> is no way to populate this pool. Besides, singletons are evil. I
> honestly wish that I'd never introduced the global pool in C++; it has
> lead to too many subtle singleton problems.
>
> 2009/12/9 Jason Hsueh <jas...@google.com <mailto:jas...@google.com>>
>
> No, there isn't an equivalent to the DescriptorPool in Java. If you
> know the types that you want you can build a mapping yourself. Or if
> you'd be interested in porting the C++ DescriptorPool to java that
> would be great!
>
> 2009/12/9 Romain Fran�ois <francoi...@free.fr
> <mailto:francoi...@free.fr>>

Kenton Varda

unread,
Dec 10, 2009, 4:13:05 AM12/10/09
to Romain François, Jason Hsueh, Protocol Buffers
Is this for the RPC system?  I think you're making this a lot harder than it needs to be.

On the server side, when someone wants to export a service, they will construct a service implementation and pass it to your system.  The com.google.protobuf.Service interface has methods getDescriptor(), getRequestPrototype(), and getResponsePrototype(), to get the ServiceDescriptor, request message class, and response message class respectively.  So, you don't need to consult any tables.

On the client side, your RPC implementation should merely provide the user with an object implementing com.google.protobuf.RpcChannel.  The caller then calls MyServiceType.newStub(channel) to construct a type-safe stub.  The RPC system does not need to know what kind of service it is.

2009/12/10 Romain François <francoi...@free.fr>
On 12/09/2009 09:00 PM, Kenton Varda wrote:
Actually I don't think we need DescriptorPool in Java.  DescriptorPool
was primarily written for the purpose of memory management, but Java
handles that for us.  If all you need is the mapping aspect, just build
a Map<String, ServiceDescriptor> yourself and use it.

This is close to what I do now. Next question is : can I get hold of the java class that is associated with a Descriptor.

From the service descriptor, I can get to the MethodDescriptor I am interested in, and then I can get the Descriptor of the input type of the method, but at that point I would like to create a builder for the input message. Should I also maintain a Map<String,Descriptor>

One thing I thought of would be to go back to the file descriptor associated with the input message type descriptor, check the two java options, and use java reflection. would this work ?

It is a shame the java class name is not the same as the message type full name.

True, in C++ there is the "global pool" which is automatically populated
with everything compiled into the binary.  This wouldn't work in Java
because classes are not loaded until they are first accessed, so there
is no way to populate this pool.  Besides, singletons are evil.  I
honestly wish that I'd never introduced the global pool in C++; it has
lead to too many subtle singleton problems.

2009/12/9 Jason Hsueh <jas...@google.com <mailto:jas...@google.com>>


   No, there isn't an equivalent to the DescriptorPool in Java. If you
   know the types that you want you can build a mapping yourself. Or if
   you'd be interested in porting the C++ DescriptorPool to java that
   would be great!

   2009/12/9 Romain François <francoi...@free.fr
   <mailto:francoi...@free.fr>>


       Hello,

       Given a service/method full name, I'd like to get hold of the
       ServiceDescriptor, or MethodDescriptor. In C++ I would use the
       DescriptorPool, but I don't see this in the java api.

       Is there a way ?

       Romain

Romain François

unread,
Dec 10, 2009, 4:38:20 AM12/10/09
to Kenton Varda, Jason Hsueh, Protocol Buffers
On 12/10/2009 10:13 AM, Kenton Varda wrote:
> Is this for the RPC system?

yes

> I think you're making this a lot harder
> than it needs to be.

ah.

> On the server side, when someone wants to export a service, they will
> construct a service implementation and pass it to your system. The
> com.google.protobuf.Service interface has methods getDescriptor(),
> getRequestPrototype(), and getResponsePrototype(), to get the
> ServiceDescriptor, request message class, and response message class
> respectively. So, you don't need to consult any tables.

Right. That's what I needed. Thanks. Sorry.

> On the client side, your RPC implementation should merely provide the
> user with an object implementing com.google.protobuf.RpcChannel. The
> caller then calls MyServiceType.newStub(channel) to construct a
> type-safe stub. The RPC system does not need to know what kind of
> service it is.

I'm not using this since you said this will disapear at some point...

> 2009/12/10 Romain Fran�ois <francoi...@free.fr
> <mailto:francoi...@free.fr>>
> <mailto:jas...@google.com> <mailto:jas...@google.com
> <mailto:jas...@google.com>>>
>
>
> No, there isn't an equivalent to the DescriptorPool in Java.
> If you
> know the types that you want you can build a mapping
> yourself. Or if
> you'd be interested in porting the C++ DescriptorPool to
> java that
> would be great!
>
> 2009/12/9 Romain Fran�ois <francoi...@free.fr
> <mailto:francoi...@free.fr>
> <mailto:francoi...@free.fr <mailto:francoi...@free.fr>>>

Kenton Varda

unread,
Dec 10, 2009, 5:07:26 AM12/10/09
to Romain François, Jason Hsueh, Protocol Buffers


2009/12/10 Romain François <francoi...@free.fr>

On 12/10/2009 10:13 AM, Kenton Varda wrote:
Is this for the RPC system?

yes


I think you're making this a lot harder
than it needs to be.

ah.


On the server side, when someone wants to export a service, they will
construct a service implementation and pass it to your system.  The
com.google.protobuf.Service interface has methods getDescriptor(),
getRequestPrototype(), and getResponsePrototype(), to get the
ServiceDescriptor, request message class, and response message class
respectively.  So, you don't need to consult any tables.

Right. That's what I needed. Thanks. Sorry.


On the client side, your RPC implementation should merely provide the
user with an object implementing com.google.protobuf.RpcChannel.  The
caller then calls MyServiceType.newStub(channel) to construct a
type-safe stub.  The RPC system does not need to know what kind of
service it is.

I'm not using this since you said this will disapear at some point...

Well, com.google.protobuf.Service is "going away" at some point too.  But for now these are the only option.
 

2009/12/10 Romain François <francoi...@free.fr
           2009/12/9 Romain François <francoi...@free.fr
       <mailto:francoi...@free.fr>
       <mailto:francoi...@free.fr <mailto:francoi...@free.fr>>>



               Hello,

               Given a service/method full name, I'd like to get hold
       of the
               ServiceDescriptor, or MethodDescriptor. In C++ I would
       use the
               DescriptorPool, but I don't see this in the java api.

               Is there a way ?

               Romain
Reply all
Reply to author
Forward
0 new messages