You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by David Bennett <da...@yorkage.com> on 2015/10/06 01:37:55 UTC

Does Thrift interoperate with Java beans?

I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.

My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?

Regards
David M Bennett FACS

Andl - A New Database Language - andl.org



RE: Does Thrift interoperate with Java beans?

Posted by David Bennett <da...@yorkage.com>.
Thanks for the answer. I'm not a Java guy and I didn't know that the Thrift compiler had a 'beans' option. Perhaps I forgot to read the documentation?-) 

What I was hoping for is what you've just done: tell them they play kind of OK with a little tweaking. It seems that if I name things right and use the 'beans' option then there is a good chance a lot of the classes/getters/setters will line up and I won't need to write wrappers for the wrappers.

Re Swift: I'm just trying to limit the number of technologies I have to learn, and the answers all seemed to have 'server' and 'generate IDL' in them, which are the bits I don't need. As long as what you said goes for the client end, I'm happy to give it a go. I don't really care if the code is 'clean' yet -- just getting something to work would be nice.

Regards
David M Bennett FACS

Andl - A New Database Language - andl.org


-----Original Message-----
From: BCG [mailto:bgould@hushmail.com] 
Sent: Tuesday, 6 October 2015 11:59 PM
To: user@thrift.apache.org
Subject: Re: Does Thrift interoperate with Java beans?



On 10/06/2015 01:37 AM, David Bennett wrote:
> Thanks for all the helpful responses.
>
> I tried to make it clear that what I have is a client-only problem. The server code is unrelated, not causing any problems and not part of this question. In fact I already have my own IDL generator, so the Swift-related suggestions are not really all that useful.

Swift supports clients as well as servers, so I'm not really sure why you would say the suggestions are not useful just based on that.  
Perhaps that is besides the point though.
>
> The question is specifically about how well the Java generated code can be made to play with bean-ish code on the client side. The context is a desktop or thick client app with a rich Java UI that is built to interact with bean code (which in turn has its own persistence or serialisation or communication layers), and replacing the lower layers with a Thrift API. I fear I'm getting pushed into creating a bean for each Thrift struct, along with wrappers for every ctor, getter and setter, and that's not necessarily a place I'd like to get to. Since beans are fairly common, I wondered if someone had a better answer.

Not trying to beat a dead horse here, just trying to make it clear that this was the question we were trying to answer.  Since you already have IDL, you can use Swift's code generator to automatically create beans for all of your structs.  You *probably* could use the regular Thrift compiler to do that too with the "beans" option to the Java generator, but Swift's "beans" are much cleaner and closer to what you would expect.  That will work well for the structs, so that you don't have to create wrappers for each one.  For the services (whether you use Thrift or Swift proper) you will probably need to write some code to bind the client stubs to some underlying Thrift protocol/transport, but that should be straightforward and if you are just using one endpoint that can use TMultiplexedProtocol, most likely could be generic across all of the whole application.

tl;dr - you probably could do this with the regular Thrift compiler too, but the use case you are describing is pretty much what Swift seems to be have been designed to do.

hth

-- Ben

>
>
> -----Original Message-----
> From: stuart.reynolds@gmail.com [mailto:stuart.reynolds@gmail.com] On 
> Behalf Of Stuart Reynolds
> Sent: Tuesday, 6 October 2015 11:41 AM
> To: user@thrift.apache.org
> Subject: Re: Does Thrift interoperate with Java beans?
>
> Kinda. Sorta.
>
> Vanilla Thrift generates Java data classes that looks pretty beany to me (they have the standard getters and setters). However, I've always felt that there's a big downside to giving up control of your server code - not least, you can't add any additional advanced bean annotations (or any other kind of annotation) to you classes, nor can you directly serialize third party classes not produced by Thrift.
> This often leads to you wrap the serialization, which kinda defeats many of the benefits having it automated and had me banging my head on the table in dispair.
>
> I've since been using Facebook's Swift project. This lets you
> *generate* your thrift IDL from your *existing* server interfaces and bean classes, but also maintain thirft's extremely efficient serialization (via runtime class generation). The project has a few design choices I've not a fan of (export classes but not interfaces, has a HUGE set of dependencies, most unrelated to serialization), but I've made a fork for scala to allow me to work around the bigger issues. For me, its been hugely efficient at letting my export any old interface or data structure with no data marshaling steps.
>
> - Stuart
>
>
>
> On Mon, Oct 5, 2015 at 4:37 PM, David Bennett <da...@yorkage.com> wrote:
>> I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.
>>
>> My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?
>>
>> Regards
>> David M Bennett FACS
>>
>> Andl - A New Database Language - andl.org
>>
>>
>



Re: Does Thrift interoperate with Java beans?

Posted by BCG <bg...@hushmail.com>.

On 10/06/2015 01:37 AM, David Bennett wrote:
> Thanks for all the helpful responses.
>
> I tried to make it clear that what I have is a client-only problem. The server code is unrelated, not causing any problems and not part of this question. In fact I already have my own IDL generator, so the Swift-related suggestions are not really all that useful.

Swift supports clients as well as servers, so I'm not really sure why 
you would say the suggestions are not useful just based on that.  
Perhaps that is besides the point though.
>
> The question is specifically about how well the Java generated code can be made to play with bean-ish code on the client side. The context is a desktop or thick client app with a rich Java UI that is built to interact with bean code (which in turn has its own persistence or serialisation or communication layers), and replacing the lower layers with a Thrift API. I fear I'm getting pushed into creating a bean for each Thrift struct, along with wrappers for every ctor, getter and setter, and that's not necessarily a place I'd like to get to. Since beans are fairly common, I wondered if someone had a better answer.

Not trying to beat a dead horse here, just trying to make it clear that 
this was the question we were trying to answer.  Since you already have 
IDL, you can use Swift's code generator to automatically create beans 
for all of your structs.  You *probably* could use the regular Thrift 
compiler to do that too with the "beans" option to the Java generator, 
but Swift's "beans" are much cleaner and closer to what you would 
expect.  That will work well for the structs, so that you don't have to 
create wrappers for each one.  For the services (whether you use Thrift 
or Swift proper) you will probably need to write some code to bind the 
client stubs to some underlying Thrift protocol/transport, but that 
should be straightforward and if you are just using one endpoint that 
can use TMultiplexedProtocol, most likely could be generic across all of 
the whole application.

tl;dr - you probably could do this with the regular Thrift compiler too, 
but the use case you are describing is pretty much what Swift seems to 
be have been designed to do.

hth

-- Ben

>
>
> -----Original Message-----
> From: stuart.reynolds@gmail.com [mailto:stuart.reynolds@gmail.com] On Behalf Of Stuart Reynolds
> Sent: Tuesday, 6 October 2015 11:41 AM
> To: user@thrift.apache.org
> Subject: Re: Does Thrift interoperate with Java beans?
>
> Kinda. Sorta.
>
> Vanilla Thrift generates Java data classes that looks pretty beany to me (they have the standard getters and setters). However, I've always felt that there's a big downside to giving up control of your server code - not least, you can't add any additional advanced bean annotations (or any other kind of annotation) to you classes, nor can you directly serialize third party classes not produced by Thrift.
> This often leads to you wrap the serialization, which kinda defeats many of the benefits having it automated and had me banging my head on the table in dispair.
>
> I've since been using Facebook's Swift project. This lets you
> *generate* your thrift IDL from your *existing* server interfaces and bean classes, but also maintain thirft's extremely efficient serialization (via runtime class generation). The project has a few design choices I've not a fan of (export classes but not interfaces, has a HUGE set of dependencies, most unrelated to serialization), but I've made a fork for scala to allow me to work around the bigger issues. For me, its been hugely efficient at letting my export any old interface or data structure with no data marshaling steps.
>
> - Stuart
>
>
>
> On Mon, Oct 5, 2015 at 4:37 PM, David Bennett <da...@yorkage.com> wrote:
>> I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.
>>
>> My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?
>>
>> Regards
>> David M Bennett FACS
>>
>> Andl - A New Database Language - andl.org
>>
>>
>



Re: Does Thrift interoperate with Java beans?

Posted by Matt Chambers <mv...@me.com>.
> On Oct 6, 2015, at 9:26 AM, David Bennett <da...@yorkage.com> wrote:
> 
> Yes, I get that. The problem is what to do to make them interoperate directly without having to write wrappers for the wrappers. It seems that with the 'beans' option (which I didn't notice) the naming and calling conventions should be close enough. [Just because there are getters and setters doesn't mean the names are generated the same way.]

The names are generated the same way because the bean spec defines how the getters and setters are named.

> 
> I'm still at the stage of working out exactly what kind of IDL to generate (with what naming conventions) so I can't yet answer your question.
> 
> Regards
> David M Bennett FACS
> 
> Andl - A New Database Language - andl.org
> 
> 
> -----Original Message-----
> From: Matt Chambers [mailto:mvchambers@me.com] 
> Sent: Tuesday, 6 October 2015 11:43 PM
> To: user@thrift.apache.org
> Subject: Re: Does Thrift interoperate with Java beans?
> 
> I’m confused on what you mean by “bean”.  A bean is just a class with getters/setters for each property, a no arg constructor, that is serializable.  The thrift generated code meets #1, and #2, probably not #3 but they are thrift serializable so maybe that can be considered an equivalent.  
> 
> What about the thrift generated classes doesn’t work with your code?
> 
> -Matt
> 


RE: Does Thrift interoperate with Java beans?

Posted by David Bennett <da...@yorkage.com>.
Yes, I get that. The problem is what to do to make them interoperate directly without having to write wrappers for the wrappers. It seems that with the 'beans' option (which I didn't notice) the naming and calling conventions should be close enough. [Just because there are getters and setters doesn't mean the names are generated the same way.]

I'm still at the stage of working out exactly what kind of IDL to generate (with what naming conventions) so I can't yet answer your question.

Regards
David M Bennett FACS

Andl - A New Database Language - andl.org


-----Original Message-----
From: Matt Chambers [mailto:mvchambers@me.com] 
Sent: Tuesday, 6 October 2015 11:43 PM
To: user@thrift.apache.org
Subject: Re: Does Thrift interoperate with Java beans?

I’m confused on what you mean by “bean”.  A bean is just a class with getters/setters for each property, a no arg constructor, that is serializable.  The thrift generated code meets #1, and #2, probably not #3 but they are thrift serializable so maybe that can be considered an equivalent.  

What about the thrift generated classes doesn’t work with your code?

-Matt

For client side code I just use the thrift

> On Oct 6, 2015, at 1:37 AM, David Bennett <da...@yorkage.com> wrote:
> 
> Thanks for all the helpful responses. 
> 
> I tried to make it clear that what I have is a client-only problem. The server code is unrelated, not causing any problems and not part of this question. In fact I already have my own IDL generator, so the Swift-related suggestions are not really all that useful.
> 
> The question is specifically about how well the Java generated code can be made to play with bean-ish code on the client side. The context is a desktop or thick client app with a rich Java UI that is built to interact with bean code (which in turn has its own persistence or serialisation or communication layers), and replacing the lower layers with a Thrift API. I fear I'm getting pushed into creating a bean for each Thrift struct, along with wrappers for every ctor, getter and setter, and that's not necessarily a place I'd like to get to. Since beans are fairly common, I wondered if someone had a better answer.
> 
> Regards
> David M Bennett FACS
> 
> Andl - A New Database Language - andl.org
> 
> 
> -----Original Message-----
> From: stuart.reynolds@gmail.com [mailto:stuart.reynolds@gmail.com] On Behalf Of Stuart Reynolds
> Sent: Tuesday, 6 October 2015 11:41 AM
> To: user@thrift.apache.org
> Subject: Re: Does Thrift interoperate with Java beans?
> 
> Kinda. Sorta.
> 
> Vanilla Thrift generates Java data classes that looks pretty beany to me (they have the standard getters and setters). However, I've always felt that there's a big downside to giving up control of your server code - not least, you can't add any additional advanced bean annotations (or any other kind of annotation) to you classes, nor can you directly serialize third party classes not produced by Thrift.
> This often leads to you wrap the serialization, which kinda defeats many of the benefits having it automated and had me banging my head on the table in dispair.
> 
> I've since been using Facebook's Swift project. This lets you
> *generate* your thrift IDL from your *existing* server interfaces and bean classes, but also maintain thirft's extremely efficient serialization (via runtime class generation). The project has a few design choices I've not a fan of (export classes but not interfaces, has a HUGE set of dependencies, most unrelated to serialization), but I've made a fork for scala to allow me to work around the bigger issues. For me, its been hugely efficient at letting my export any old interface or data structure with no data marshaling steps.
> 
> - Stuart
> 
> 
> 
> On Mon, Oct 5, 2015 at 4:37 PM, David Bennett <da...@yorkage.com> wrote:
>> I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.
>> 
>> My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?
>> 
>> Regards
>> David M Bennett FACS
>> 
>> Andl - A New Database Language - andl.org
>> 
>> 
> 


Re: Does Thrift interoperate with Java beans?

Posted by Matt Chambers <mv...@me.com>.
I’m confused on what you mean by “bean”.  A bean is just a class with getters/setters for each property, a no arg constructor, that is serializable.  The thrift generated code meets #1, and #2, probably not #3 but they are thrift serializable so maybe that can be considered an equivalent.  

What about the thrift generated classes doesn’t work with your code?

-Matt

For client side code I just use the thrift

> On Oct 6, 2015, at 1:37 AM, David Bennett <da...@yorkage.com> wrote:
> 
> Thanks for all the helpful responses. 
> 
> I tried to make it clear that what I have is a client-only problem. The server code is unrelated, not causing any problems and not part of this question. In fact I already have my own IDL generator, so the Swift-related suggestions are not really all that useful.
> 
> The question is specifically about how well the Java generated code can be made to play with bean-ish code on the client side. The context is a desktop or thick client app with a rich Java UI that is built to interact with bean code (which in turn has its own persistence or serialisation or communication layers), and replacing the lower layers with a Thrift API. I fear I'm getting pushed into creating a bean for each Thrift struct, along with wrappers for every ctor, getter and setter, and that's not necessarily a place I'd like to get to. Since beans are fairly common, I wondered if someone had a better answer.
> 
> Regards
> David M Bennett FACS
> 
> Andl - A New Database Language - andl.org
> 
> 
> -----Original Message-----
> From: stuart.reynolds@gmail.com [mailto:stuart.reynolds@gmail.com] On Behalf Of Stuart Reynolds
> Sent: Tuesday, 6 October 2015 11:41 AM
> To: user@thrift.apache.org
> Subject: Re: Does Thrift interoperate with Java beans?
> 
> Kinda. Sorta.
> 
> Vanilla Thrift generates Java data classes that looks pretty beany to me (they have the standard getters and setters). However, I've always felt that there's a big downside to giving up control of your server code - not least, you can't add any additional advanced bean annotations (or any other kind of annotation) to you classes, nor can you directly serialize third party classes not produced by Thrift.
> This often leads to you wrap the serialization, which kinda defeats many of the benefits having it automated and had me banging my head on the table in dispair.
> 
> I've since been using Facebook's Swift project. This lets you
> *generate* your thrift IDL from your *existing* server interfaces and bean classes, but also maintain thirft's extremely efficient serialization (via runtime class generation). The project has a few design choices I've not a fan of (export classes but not interfaces, has a HUGE set of dependencies, most unrelated to serialization), but I've made a fork for scala to allow me to work around the bigger issues. For me, its been hugely efficient at letting my export any old interface or data structure with no data marshaling steps.
> 
> - Stuart
> 
> 
> 
> On Mon, Oct 5, 2015 at 4:37 PM, David Bennett <da...@yorkage.com> wrote:
>> I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.
>> 
>> My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?
>> 
>> Regards
>> David M Bennett FACS
>> 
>> Andl - A New Database Language - andl.org
>> 
>> 
> 


RE: Does Thrift interoperate with Java beans?

Posted by David Bennett <da...@yorkage.com>.
Thanks for all the helpful responses. 

I tried to make it clear that what I have is a client-only problem. The server code is unrelated, not causing any problems and not part of this question. In fact I already have my own IDL generator, so the Swift-related suggestions are not really all that useful.

The question is specifically about how well the Java generated code can be made to play with bean-ish code on the client side. The context is a desktop or thick client app with a rich Java UI that is built to interact with bean code (which in turn has its own persistence or serialisation or communication layers), and replacing the lower layers with a Thrift API. I fear I'm getting pushed into creating a bean for each Thrift struct, along with wrappers for every ctor, getter and setter, and that's not necessarily a place I'd like to get to. Since beans are fairly common, I wondered if someone had a better answer.

Regards
David M Bennett FACS

Andl - A New Database Language - andl.org


-----Original Message-----
From: stuart.reynolds@gmail.com [mailto:stuart.reynolds@gmail.com] On Behalf Of Stuart Reynolds
Sent: Tuesday, 6 October 2015 11:41 AM
To: user@thrift.apache.org
Subject: Re: Does Thrift interoperate with Java beans?

Kinda. Sorta.

Vanilla Thrift generates Java data classes that looks pretty beany to me (they have the standard getters and setters). However, I've always felt that there's a big downside to giving up control of your server code - not least, you can't add any additional advanced bean annotations (or any other kind of annotation) to you classes, nor can you directly serialize third party classes not produced by Thrift.
This often leads to you wrap the serialization, which kinda defeats many of the benefits having it automated and had me banging my head on the table in dispair.

I've since been using Facebook's Swift project. This lets you
*generate* your thrift IDL from your *existing* server interfaces and bean classes, but also maintain thirft's extremely efficient serialization (via runtime class generation). The project has a few design choices I've not a fan of (export classes but not interfaces, has a HUGE set of dependencies, most unrelated to serialization), but I've made a fork for scala to allow me to work around the bigger issues. For me, its been hugely efficient at letting my export any old interface or data structure with no data marshaling steps.

- Stuart



On Mon, Oct 5, 2015 at 4:37 PM, David Bennett <da...@yorkage.com> wrote:
> I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.
>
> My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?
>
> Regards
> David M Bennett FACS
>
> Andl - A New Database Language - andl.org
>
>


Re: Does Thrift interoperate with Java beans?

Posted by BCG <bg...@hushmail.com>.
Swift is good for this; also I have a fork that allows for annotating 
interfaces for structs and unions instead of just classes 
(https://github.com/bgould/swift) and I've made a pull request to the 
Swift team (https://github.com/facebook/swift/pull/257) but I'm not 
holding my breath because it seems that if you don't work at Facebook 
they can't hear you that well.

I've found that using interfaces for structs provides the flexibility 
needed for the original question.  You can do the same with classes to 
but with interfaces you can use all your favorite Gang of Four stuff or 
whatever, and in case your existing data model doesn't match up with the 
Thrift model very well, using Java interfaces with builders make it 
easier to meet in the middle.

In any case, I agree that Swift is a good option for the original 
question in this thread.  URL for Swift proper is here: 
http://github.com/facebook/swift, or you can find my fork at the URL 
referenced above

On 10/05/2015 08:41 PM, Stuart Reynolds wrote:
> Kinda. Sorta.
>
> Vanilla Thrift generates Java data classes that looks pretty beany to
> me (they have the standard getters and setters). However, I've always
> felt that there's a big downside to giving up control of your server
> code - not least, you can't add any additional advanced bean
> annotations (or any other kind of annotation) to you classes, nor can
> you directly serialize third party classes not produced by Thrift.
> This often leads to you wrap the serialization, which kinda defeats
> many of the benefits having it automated and had me banging my head on
> the table in dispair.
>
> I've since been using Facebook's Swift project. This lets you
> *generate* your thrift IDL from your *existing* server interfaces and
> bean classes, but also maintain thirft's extremely efficient
> serialization (via runtime class generation). The project has a few
> design choices I've not a fan of (export classes but not interfaces,
> has a HUGE set of dependencies, most unrelated to serialization), but
> I've made a fork for scala to allow me to work around the bigger
> issues. For me, its been hugely efficient at letting my export any old
> interface or data structure with no data marshaling steps.
>
> - Stuart
>
>
>
> On Mon, Oct 5, 2015 at 4:37 PM, David Bennett <da...@yorkage.com> wrote:
>> I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.
>>
>> My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?
>>
>> Regards
>> David M Bennett FACS
>>
>> Andl - A New Database Language - andl.org
>>
>>



Re: Does Thrift interoperate with Java beans?

Posted by Stuart Reynolds <st...@stureynolds.com>.
Kinda. Sorta.

Vanilla Thrift generates Java data classes that looks pretty beany to
me (they have the standard getters and setters). However, I've always
felt that there's a big downside to giving up control of your server
code - not least, you can't add any additional advanced bean
annotations (or any other kind of annotation) to you classes, nor can
you directly serialize third party classes not produced by Thrift.
This often leads to you wrap the serialization, which kinda defeats
many of the benefits having it automated and had me banging my head on
the table in dispair.

I've since been using Facebook's Swift project. This lets you
*generate* your thrift IDL from your *existing* server interfaces and
bean classes, but also maintain thirft's extremely efficient
serialization (via runtime class generation). The project has a few
design choices I've not a fan of (export classes but not interfaces,
has a HUGE set of dependencies, most unrelated to serialization), but
I've made a fork for scala to allow me to work around the bigger
issues. For me, its been hugely efficient at letting my export any old
interface or data structure with no data marshaling steps.

- Stuart



On Mon, Oct 5, 2015 at 4:37 PM, David Bennett <da...@yorkage.com> wrote:
> I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.
>
> My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?
>
> Regards
> David M Bennett FACS
>
> Andl - A New Database Language - andl.org
>
>

Re: Does Thrift interoperate with Java beans?

Posted by Matt Chambers <mv...@me.com>.
It would be great if we could add java annotations to properties and stuff, it wouldn’t be a hard patch to do I don’t think.  One thing I’d particularly like would be the ability to change the implementation of a list or map, for example if I wanted to force LinkedHashMap where the order of the elements matter. 

I tend to keep the thrift stuff separate from the application internals.  I have a set of lighter weight classes I use for internal business logic.  I can stop using thrift and business logic doesn’t have to change.  I like it this way.  For a little extra work I get some speed and flexibility, plus I can hold a lot more of these little internal objects in memcached.  My thrift structs generally have every property the client side might need (and it can be large amounts of data) but the internal classes just have the unique Id and maybe one or two other immutable fields. 

-Matt

> On Oct 5, 2015, at 7:37 PM, David Bennett <da...@yorkage.com> wrote:
> 
> I have some lumps of code in different languages that I'd like to get to talk to each other. The server is OK, but the client code makes heavy use of Java beans.
> 
> My question, to those who knows a lot more about Java than I do, is whether there is some clever way to get Thrift and Java beans to play together, or whether this is an invitation to getter/setter hell?
> 
> Regards
> David M Bennett FACS
> 
> Andl - A New Database Language - andl.org
> 
>