org.apache.catalina.cluster.mcast
Class McastService

java.lang.Object
  extended byorg.apache.catalina.cluster.mcast.McastService
All Implemented Interfaces:
MembershipListener, MembershipService

public class McastService
extends java.lang.Object
implements MembershipService, MembershipListener

A membership implementation using simple multicast. This is the representation of a multicast membership service. This class is responsible for maintaining a list of active cluster nodes in the cluster. If a node fails to send out a heartbeat, the node will be dismissed.

Version:
$Revision: 1.13 $, $Date: 2004/11/11 14:47:26 $
Author:
Filip Hanik

Field Summary
protected  McastServiceImpl impl
          A handle to the actual low level implementation
protected  MembershipListener listener
          A membership listener delegate (should be the cluster :)
protected  McastMember localMember
          The local member
protected  java.util.Properties properties
          The implementation specific properties
 
Constructor Summary
McastService()
          Create a membership service.
 
Method Summary
 void addMembershipListener(MembershipListener listener)
          Add a membership listener, this version only supports one listener per service, so calling this method twice will result in only the second listener being active.
 Member getLocalMember()
          Return the local member
 java.lang.String getMcastAddr()
           
 java.lang.String getMcastBindAddress()
           
 long getMcastDropTime()
           
 long getMcastFrequency()
           
 int getMcastPort()
           
 int getMcastSoTimeout()
           
 int getMcastTTL()
           
 Member[] getMembers()
          Return all the members
 java.util.Properties getProperties()
          Return the properties, see setProperties
protected  void hasProperty(java.util.Properties properties, java.lang.String name)
          Check if a required property is available.
static void main(java.lang.String[] args)
          Simple test program
 void memberAdded(Member member)
           
 void memberDisappeared(Member member)
          Callback from the impl when a new member has been received
 void removeMembershipListener()
          Remove the membership listener
 void setLocalMemberProperties(java.lang.String listenHost, int listenPort)
          Sets the local member properties for broadcasting
 void setMcastAddr(java.lang.String addr)
           
 void setMcastBindAddress(java.lang.String bindaddr)
           
 void setMcastDropTime(long time)
           
 void setMcastFrequency(long time)
           
 void setMcastPort(int port)
           
 void setMcastSoTimeout(int mcastSoTimeout)
           
 void setMcastTTL(int mcastTTL)
           
 void setProperties(java.util.Properties properties)
          Sets the properties for the membership service.
 void start()
          Start broadcasting and listening to membership pings
 void start(int level)
          Starts the membership service.
 void stop()
          Stop broadcasting and listening to membership pings
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected java.util.Properties properties
The implementation specific properties


impl

protected McastServiceImpl impl
A handle to the actual low level implementation


listener

protected MembershipListener listener
A membership listener delegate (should be the cluster :)


localMember

protected McastMember localMember
The local member

Constructor Detail

McastService

public McastService()
Create a membership service.

Method Detail

setProperties

public void setProperties(java.util.Properties properties)
Description copied from interface: MembershipService
Sets the properties for the membership service. This must be called before the start() method is called. The properties are implementation specific.

Specified by:
setProperties in interface MembershipService
Parameters:
properties - - to be used to configure the membership service.
Throws:
java.lang.IllegalArgumentException - if a property is missing.

getProperties

public java.util.Properties getProperties()
Return the properties, see setProperties

Specified by:
getProperties in interface MembershipService

getLocalMember

public Member getLocalMember()
Return the local member

Specified by:
getLocalMember in interface MembershipService

setLocalMemberProperties

public void setLocalMemberProperties(java.lang.String listenHost,
                                     int listenPort)
Sets the local member properties for broadcasting

Specified by:
setLocalMemberProperties in interface MembershipService

setMcastAddr

public void setMcastAddr(java.lang.String addr)

getMcastAddr

public java.lang.String getMcastAddr()

setMcastBindAddress

public void setMcastBindAddress(java.lang.String bindaddr)

getMcastBindAddress

public java.lang.String getMcastBindAddress()

setMcastPort

public void setMcastPort(int port)

getMcastPort

public int getMcastPort()

setMcastFrequency

public void setMcastFrequency(long time)

getMcastFrequency

public long getMcastFrequency()

setMcastDropTime

public void setMcastDropTime(long time)

getMcastDropTime

public long getMcastDropTime()

hasProperty

protected void hasProperty(java.util.Properties properties,
                           java.lang.String name)
Check if a required property is available.

Parameters:
properties - The set of properties
name - The property to check for

start

public void start()
           throws java.lang.Exception
Start broadcasting and listening to membership pings

Specified by:
start in interface MembershipService
Throws:
java.lang.Exception - if a IO error occurs

start

public void start(int level)
           throws java.lang.Exception
Description copied from interface: MembershipService
Starts the membership service. If a membership listeners is added the listener will start to receive membership events.

Specified by:
start in interface MembershipService
Parameters:
level - - level 1 starts listening for members, level 2 starts broad casting the server
Throws:
java.lang.Exception - if the service fails to start.

stop

public void stop()
Stop broadcasting and listening to membership pings

Specified by:
stop in interface MembershipService

getMembers

public Member[] getMembers()
Return all the members

Specified by:
getMembers in interface MembershipService

addMembershipListener

public void addMembershipListener(MembershipListener listener)
Add a membership listener, this version only supports one listener per service, so calling this method twice will result in only the second listener being active.

Specified by:
addMembershipListener in interface MembershipService
Parameters:
listener - The listener

removeMembershipListener

public void removeMembershipListener()
Remove the membership listener

Specified by:
removeMembershipListener in interface MembershipService

memberAdded

public void memberAdded(Member member)
Specified by:
memberAdded in interface MembershipListener

memberDisappeared

public void memberDisappeared(Member member)
Callback from the impl when a new member has been received

Specified by:
memberDisappeared in interface MembershipListener
Parameters:
member - The member

getMcastSoTimeout

public int getMcastSoTimeout()

setMcastSoTimeout

public void setMcastSoTimeout(int mcastSoTimeout)

getMcastTTL

public int getMcastTTL()

setMcastTTL

public void setMcastTTL(int mcastTTL)

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Simple test program

Parameters:
args - Command-line arguments
Throws:
java.lang.Exception - If an error occurs


Copyright © 2000-2005 Apache Software Foundation. All Rights Reserved.