com.bigdata.service
Class AbstractService

java.lang.Object
  extended by com.bigdata.service.AbstractService
All Implemented Interfaces:
IService, Remote
Direct Known Subclasses:
AbstractServicesManagerService, AbstractTransactionService, ClientService, DataService, LoadBalancerService

public abstract class AbstractService
extends Object
implements IService

Abstract base class defines protocols for setting the service UUID, etc.

Version:
$Id: AbstractService.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected static org.apache.log4j.Logger log
           
 
Constructor Summary
protected AbstractService()
           
 
Method Summary
protected  void clearLoggingContext()
          Clear the logging context.
 void destroy()
          Destroy the service.
abstract  AbstractFederation getFederation()
          Return the proxy used to access other services in the federation.
 String getHostname()
          The host on which this service is running.
abstract  Class getServiceIface()
          Return the most interesting interface for the service.
 String getServiceName()
          Note: This is overridden in the jini integration to return a configured name for the service.
 UUID getServiceUUID()
          The unique identifier for this service.
 void setServiceUUID(UUID serviceUUID)
          This method must be invoked to set the service UUID.
protected  void setupLoggingContext()
          Sets up the MDC logging context.
 void shutdown()
           
 void shutdownNow()
           
abstract  AbstractService start()
          Starts the AbstractService.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log
Constructor Detail

AbstractService

protected AbstractService()
Method Detail

setServiceUUID

public void setServiceUUID(UUID serviceUUID)
                    throws IllegalStateException
This method must be invoked to set the service UUID.

Note: This method gets invoked at different times depending on whether the service is embedded (generally invoked from the service constructor) or written against a service discovery framework (invoked once the service has been assigned a UUID by a registrar or during re-start since the service UUID is read from a local file).

Several things depend on when this method is invoked, including the setup of the per-service CounterSet reported by the service to the ILoadBalancerService.

Parameters:
serviceUUID - The UUID assigned to the service.
Throws:
IllegalArgumentException - if the parameter is null.
IllegalStateException - if the service UUID has already been set to a different value.

getServiceUUID

public final UUID getServiceUUID()
Description copied from interface: IService
The unique identifier for this service.

Note: Some service discovery frameworks (Jini) will assign the service a UUID asynchronously after a new service starts, in which case this method will return null until the service UUID has been assigned.

Specified by:
getServiceUUID in interface IService
Returns:
The unique data service identifier.

getServiceIface

public abstract Class getServiceIface()
Return the most interesting interface for the service.

Specified by:
getServiceIface in interface IService

start

public abstract AbstractService start()
Starts the AbstractService.

Note: A start() is required in order to give subclasses an opportunity to be fully initialized before they are required to begin operations. It is impossible to encapsulate the startup logic cleanly without this ctor() + start() pattern. Those familiar with Objective-C will recognized this.

Returns:
this (the return type should be strengthened by the concrete implementation to return the actual type).

getFederation

public abstract AbstractFederation getFederation()
Return the proxy used to access other services in the federation.


getHostname

public final String getHostname()
Description copied from interface: IService
The host on which this service is running.

Specified by:
getHostname in interface IService

shutdown

public void shutdown()

shutdownNow

public void shutdownNow()

destroy

public void destroy()
Description copied from interface: IService
Destroy the service. If the service is running, it is shutdown immediately and then destroyed. This method has the same signature as DestroyAdmin.destroy().

Specified by:
destroy in interface IService

getServiceName

public String getServiceName()
Note: This is overridden in the jini integration to return a configured name for the service.

Specified by:
getServiceName in interface IService

setupLoggingContext

protected void setupLoggingContext()
Sets up the MDC logging context. You should do this on every client facing point of entry and then call clearLoggingContext() in a finally clause. You can extend this method to add additional context.

This implementation adds the following parameters to the MDC.

serviceName
The serviceName is typically a configuration property for the service. This datum can be injected into log messages using %X{serviceName} in your log4j pattern layout.
serviceUUID
The serviceUUID is, in general, assigned asynchronously by the service registrar. Once the serviceUUID becomes available it will be added to the MDC. This datum can be injected into log messages using %X{serviceUUID} in your log4j pattern layout.
hostname
The hostname statically determined. This datum can be injected into log messages using %X{hostname} in your log4j pattern layout.


clearLoggingContext

protected void clearLoggingContext()
Clear the logging context.



Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.