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 Balatero <db...@gmail.com> on 2008/12/16 01:25:27 UTC

Defining a base service in thrift?

I want to set up the following type of service structure:

Thrift
---------------------------
service ServiceBase {
  // A generic method to ping if a service is up?
  bool ping(),

  // How long has this service been up?
  i64 uptime()
}

service CalculatorService extends ServiceBase {
  // Adds two ints together.
  int add(int a, int b)
}

I want to implement the ServiceBase methods only once, so that all
services can be ping()able, and all services can be queried about
their uptime(). This way, any service under my infrastructure only has
to implement its special methods (CalculatorService::add(), for
example).

However, there doesn't seem to be a clean way for me to provide a base
implementation with my C++ services, and have the auto-generated
implementations also inherit from my base implementation.

How have other people solved this problem? I was trying to poke into
fb303, but I wasn't able to gain any more insight in accomplishing
this. Maybe I missed something, though? Any help would be appreciated.

Thanks!
David Balatero

Re: Defining a base service in thrift?

Posted by David Balatero <db...@gmail.com>.
Ok cool -- I actually ended up doing that right after I emailed the
list, and it works. Thanks :)

- David

On Mon, Dec 15, 2008 at 5:42 PM, Mark Slee <ms...@facebook.com> wrote:
> Just have your CalculatorServiceHandler inherit from ServiceBaseHandler.
>
> Fb303 example would look like:
> class CalculatorHandler : virtual public CalculatorServiceIf, public FacebookBase {
> }
>
> By inheriting public from FacebookBase you get the base method implementations.
>
>
> -----Original Message-----
> From: David Balatero [mailto:dbalatero@gmail.com]
> Sent: Monday, December 15, 2008 4:25 PM
> To: thrift-user@incubator.apache.org
> Subject: Defining a base service in thrift?
>
> I want to set up the following type of service structure:
>
> Thrift
> ---------------------------
> service ServiceBase {
>  // A generic method to ping if a service is up?
>  bool ping(),
>
>  // How long has this service been up?
>  i64 uptime()
> }
>
> service CalculatorService extends ServiceBase {
>  // Adds two ints together.
>  int add(int a, int b)
> }
>
> I want to implement the ServiceBase methods only once, so that all services can be ping()able, and all services can be queried about their uptime(). This way, any service under my infrastructure only has to implement its special methods (CalculatorService::add(), for example).
>
> However, there doesn't seem to be a clean way for me to provide a base implementation with my C++ services, and have the auto-generated implementations also inherit from my base implementation.
>
> How have other people solved this problem? I was trying to poke into fb303, but I wasn't able to gain any more insight in accomplishing this. Maybe I missed something, though? Any help would be appreciated.
>
> Thanks!
> David Balatero
>

RE: Defining a base service in thrift?

Posted by Mark Slee <ms...@facebook.com>.
Just have your CalculatorServiceHandler inherit from ServiceBaseHandler.

Fb303 example would look like:
class CalculatorHandler : virtual public CalculatorServiceIf, public FacebookBase {
}

By inheriting public from FacebookBase you get the base method implementations.


-----Original Message-----
From: David Balatero [mailto:dbalatero@gmail.com] 
Sent: Monday, December 15, 2008 4:25 PM
To: thrift-user@incubator.apache.org
Subject: Defining a base service in thrift?

I want to set up the following type of service structure:

Thrift
---------------------------
service ServiceBase {
  // A generic method to ping if a service is up?
  bool ping(),

  // How long has this service been up?
  i64 uptime()
}

service CalculatorService extends ServiceBase {
  // Adds two ints together.
  int add(int a, int b)
}

I want to implement the ServiceBase methods only once, so that all services can be ping()able, and all services can be queried about their uptime(). This way, any service under my infrastructure only has to implement its special methods (CalculatorService::add(), for example).

However, there doesn't seem to be a clean way for me to provide a base implementation with my C++ services, and have the auto-generated implementations also inherit from my base implementation.

How have other people solved this problem? I was trying to poke into fb303, but I wasn't able to gain any more insight in accomplishing this. Maybe I missed something, though? Any help would be appreciated.

Thanks!
David Balatero