org.javagroups.service
Class AbstractService

java.lang.Object
  |
  +--org.javagroups.service.AbstractService
All Implemented Interfaces:
MembershipListener
Direct Known 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  boolean blocked
           
protected  java.lang.Object blockMonitor
           
protected  Channel clientChannel
           
protected  java.util.LinkedList members
           
protected  boolean runThread
           
protected  PullPushAdapter serviceAdapter
           
protected  Channel serviceChannel
           
protected  java.lang.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  java.lang.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serviceChannel

protected Channel serviceChannel

serviceAdapter

protected PullPushAdapter serviceAdapter

clientChannel

protected Channel clientChannel

members

protected java.util.LinkedList members

blocked

protected boolean blocked

blockMonitor

protected java.lang.Object blockMonitor

threadMonitor

protected java.lang.Object threadMonitor

runThread

protected boolean runThread
Constructor Detail

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 Detail

getName

public abstract java.lang.String getName()
Get name of this service. Name of the service determines service type, but not an instance. Instance of the service is uniquely determined by getAddress() value.
Returns:
name of this service.

setMessageListener

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

getAddress

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

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.

isBlocked

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

waitOnBlocked

public void waitOnBlocked()
                   throws java.lang.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.

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

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.

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.


Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.