Skip to content

Service

borud edited this page Dec 10, 2011 · 2 revisions

What is a service?

A service is just a fancy name for "server process". A service typically offers some networked API through which other services or applications can speak to it. In a large system you might have a lot of services.

If you are running on a "cloud infrastructure", such as Amazon EC2 or if you have a very dynamic system where you need to bring up and take down services according to varying needs, managing where things are can get quite tedious. You have to know on which machine the service runs, which ports the different endpoints offered by the service are listening to etc.

Services in Cloudname are addressed by Coordinates.

Lifecycle of a service.

Create the coordinates

The first thing you do when you want to fire up a service is to define a coordinate for it. Let's say you have a service for processing payments that should have 3 instances. You would perhaps define the following coordinates for it:

  • 0.payment-processor.prod.xx
  • 1.payment-processor.prod.xx
  • 2.payment-processor.prod.xx

TODO(borud): INSERT DESCRIPTION OF COORDINATE CREATION

Claim coordinate

The first thing a service does when starting up is to claim its coordinate. If some other process has already claimed this coordinate, claiming the coordinate a second time will fail. This is by design: you do not want two services to think that they own the same coordinate at the same time.

Once a service has successfully claimed a coordinate it will get a ServiceHandle object back. This is the API the service uses to communicate with Cloudname.

// Claim the coordinate
ServiceHandle handle = cn.claim("0.payment-processor.prod.xx");

Update status

Some services may need to execute some time-consuming initialization before they are ready to serve. A service is not considered ready until it explicitly says so.

// Update status to indicate we are busy
handle.setStatus(new ServiceStatus(ServiceState.STARTING, "Initializing"));
// perform initialization
handle.setStatus(new ServiceStatus(ServiceState.RUNNING, "Ready	for action"));

Per default new services start with ServiceState.UNASSIGNED which means that the service hasn't even gotten around to updating its status.

Note that you have to update your status if you want the Resolver to find your service. The resolver will only resolve endpoints of services that are running and which have their state set to ServiceState.RUNNING.

Publish endpoints

Most services provide some networked API. Cloudname provides a mechanism for publishing named endpoints so that clients can look these up.

// Publish endpoint for REST interface
handle.putEndPoint("restport", new Endpoint(...));

Clone this wiki locally