org.jgroups.service

Class AbstractService

Implemented Interfaces:
MembershipListener
Known Direct Subclasses:
LeaseFactoryService

public abstract class AbstractService
extends java.lang.Object
implements MembershipListener

AbstractService is a superclass for all service implementations. Each service has two communication channels: one for inter-service communication with group memebership enabled, and one for client communication witout group membership. This allows creation of full featured services with replication and load balancing and light-weight clients that can call service methods by sending specific messages.
Author:
Roman Rokytskyy (rrokytskyy@acm.org)

Field Summary

protected Object
blockMonitor
protected boolean
blocked
protected Channel
clientChannel
protected Log
log
protected LinkedList
members
protected boolean
runThread
protected PullPushAdapter
serviceAdapter
protected Channel
serviceChannel
protected Object
threadMonitor

Constructor Summary

AbstractService(Channel serviceChannel, Channel clientChannel)
Main constructor to create services.

Method Summary

void
block()
This method is called when service is supposed to stop sending messages to channel until new view is installed.
Address
getAddress()
Get address of this service in service group.
abstract String
getName()
Get name of this service.
boolean
isBlocked()
This method returns true if inter-service communication processes should temporarily stop sending messages to service channel.
boolean
isCoordinator()
Check if this service is a coordinator of service group.
protected void
setMessageListener(MessageListener listener)
Set message listener for service message channel.
void
start()
Start standalone thread that will run until explicitly stopped.
void
stop()
Stop standalone thread started with start() method.
void
suspect(Address suspectedMember)
This method is called when a member of service group is suspected to be failed.
void
viewAccepted(View view)
This method is called when new view is installed.
void
waitOnBlocked()
Stop current thread's execution until inter-service channel is unblocked.

Field Details

blockMonitor

protected Object blockMonitor

blocked

protected boolean blocked

clientChannel

protected Channel clientChannel

log

protected Log log

members

protected LinkedList members

runThread

protected boolean runThread

serviceAdapter

protected PullPushAdapter serviceAdapter

serviceChannel

protected Channel serviceChannel

threadMonitor

protected Object threadMonitor

Constructor Details

AbstractService

public AbstractService(Channel serviceChannel,
                       Channel clientChannel)
Main constructor to create services. It creates instance of service class, registers PullPushAdapter for inter-service channel and tries to retrive initial service state.
Parameters:
serviceChannel - instance of Channel class that will be used for inter-service communication. This channel must provide group membership service and reliable group multicast.
clientChannel - instance of Channel class that will be used for client-service communication. This channel should provide reliable group multicast and unicast, but specific service implementation might put weaker requirements.

Method Details

block

public void block()
This method is called when service is supposed to stop sending messages to channel until new view is installed. Services that use inter-service communication should respect this method.
Specified by:
block in interface MembershipListener

getAddress

public Address getAddress()
Get address of this service in service group.

getName

public abstract String getName()
Returns:
name of this service.

isBlocked

public boolean isBlocked()
This method returns true if inter-service communication processes should temporarily stop sending messages to service channel.

isCoordinator

public boolean isCoordinator()
Check if this service is a coordinator of service group.
Returns:
true if this service is a coordinator of service group.

setMessageListener

protected void setMessageListener(MessageListener listener)
Set message listener for service message channel.

start

public void start()
Start standalone thread that will run until explicitly stopped. This allows running this service as standalone process.

stop

public void stop()
Stop standalone thread started with start() method. If no thread were started this method does nothing.

suspect

public void suspect(Address suspectedMember)
This method is called when a member of service group is suspected to be failed.
Specified by:
suspect in interface MembershipListener

viewAccepted

public void viewAccepted(View view)
This method is called when new view is installed. We make local copy of view members. If any other information is needed, it can be accessed via getChannel() method.
Specified by:
viewAccepted in interface MembershipListener
Parameters:
view - new view that was accepted.

waitOnBlocked

public void waitOnBlocked()
            throws InterruptedException
Stop current thread's execution until inter-service channel is unblocked. This is a service method to simplify development of channel management in subclasses.

Copyright B) 2001,2002 www.jgroups.com . All Rights Reserved.