public class McastService extends java.lang.Object implements MembershipService, MembershipListener, MessageListener
Modifier and Type | Field and Description |
---|---|
protected byte[] |
domain |
protected static Member[] |
EMPTY_MEMBERS
Return all the members
|
protected McastServiceImpl |
impl
A handle to the actual low level implementation
|
protected MembershipListener |
listener
A membership listener delegate (should be the cluster :)
|
protected MemberImpl |
localMember
The local member
|
protected MessageListener |
msglistener
A message listener delegate for broadcasts
|
protected byte[] |
payload |
protected java.util.Properties |
properties
The implementation specific properties
|
protected static StringManager |
sm
The string manager for this package.
|
MBR_RX, MBR_TX
Constructor and Description |
---|
McastService()
Create a membership service.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(ChannelMessage msg) |
void |
broadcast(ChannelMessage message)
Broadcasts a message to all members
|
Member |
findMemberByName(java.lang.String name)
Return the member by name
|
java.lang.String |
getAddress() |
java.lang.String |
getBind() |
Channel |
getChannel() |
byte[] |
getDomain() |
long |
getDropTime() |
long |
getFrequency() |
boolean |
getLocalLoopbackDisabled() |
Member |
getLocalMember(boolean alive)
Return the local member
|
java.lang.String |
getLocalMemberName()
Return the local member name
|
Member |
getMember(Member mbr) |
Member[] |
getMembers()
Returns a list of all the members in the cluster.
|
java.lang.String[] |
getMembersByName()
Return all the members by name
|
byte[] |
getPayload() |
int |
getPort() |
java.util.Properties |
getProperties()
Return the properties, see setProperties
|
int |
getRecoveryCounter() |
boolean |
getRecoveryEnabled() |
long |
getRecoverySleepTime() |
int |
getSoTimeout() |
int |
getTtl() |
boolean |
hasMembers()
has members?
|
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)
A member was added to the group
|
void |
memberDisappeared(Member member)
Callback from the impl when a new member has been received
|
void |
messageReceived(ChannelMessage msg)
Receive a message from the IO components in the Channel stack
|
void |
removeMembershipListener()
Remove the membership listener
|
void |
removeMessageListener() |
void |
setAddress(java.lang.String addr) |
void |
setBind(java.lang.String bindaddr) |
void |
setChannel(Channel channel) |
protected void |
setDefaults(java.util.Properties properties) |
void |
setDomain(byte[] domain) |
void |
setDomain(java.lang.String domain) |
void |
setDropTime(long time) |
void |
setFrequency(long time) |
void |
setLocalLoopbackDisabled(boolean localLoopbackDisabled) |
void |
setLocalMemberProperties(java.lang.String listenHost,
int listenPort,
int securePort,
int udpPort)
Sets the local member properties for broadcasting
|
void |
setMcastBindAddress(java.lang.String bindaddr) |
void |
setMcastDropTime(long time) |
void |
setMembershipListener(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.
|
void |
setMessageListener(MessageListener listener) |
void |
setPayload(byte[] payload)
Set a payload to be broadcasted with each membership
broadcast.
|
void |
setPort(int port) |
void |
setProperties(java.util.Properties properties)
Sets the properties for the membership service.
|
void |
setRecoveryCounter(int recoveryCounter) |
void |
setRecoveryEnabled(boolean recoveryEnabled) |
void |
setRecoverySleepTime(long recoverySleepTime) |
void |
setSoTimeout(int mcastSoTimeout) |
void |
setTtl(int mcastTTL) |
void |
start()
Start broadcasting and listening to membership pings
|
void |
start(int level)
Starts the membership service.
|
void |
stop(int svc)
Stop broadcasting and listening to membership pings
|
protected static final StringManager sm
protected java.util.Properties properties
protected McastServiceImpl impl
protected volatile MembershipListener listener
protected MessageListener msglistener
protected MemberImpl localMember
protected byte[] payload
protected byte[] domain
protected static final Member[] EMPTY_MEMBERS
public void setProperties(java.util.Properties properties)
MembershipService
start()
method is called.
The properties are implementation specific.setProperties
in interface MembershipService
properties
- java.lang.IllegalArgumentException
- if a property is missing.public java.util.Properties getProperties()
getProperties
in interface MembershipService
public java.lang.String getLocalMemberName()
public Member getLocalMember(boolean alive)
getLocalMember
in interface MembershipService
public void setLocalMemberProperties(java.lang.String listenHost, int listenPort, int securePort, int udpPort)
setLocalMemberProperties
in interface MembershipService
public void setAddress(java.lang.String addr)
public java.lang.String getAddress()
public void setMcastBindAddress(java.lang.String bindaddr)
public void setBind(java.lang.String bindaddr)
public java.lang.String getBind()
public void setPort(int port)
public void setRecoveryCounter(int recoveryCounter)
public int getRecoveryCounter()
public void setRecoveryEnabled(boolean recoveryEnabled)
public boolean getRecoveryEnabled()
public void setRecoverySleepTime(long recoverySleepTime)
public long getRecoverySleepTime()
public void setLocalLoopbackDisabled(boolean localLoopbackDisabled)
public boolean getLocalLoopbackDisabled()
public int getPort()
public void setFrequency(long time)
public long getFrequency()
public void setMcastDropTime(long time)
public void setDropTime(long time)
public long getDropTime()
protected void hasProperty(java.util.Properties properties, java.lang.String name)
properties
- The set of propertiesname
- The property to check forpublic void start() throws java.lang.Exception
start
in interface MembershipService
java.lang.Exception
- if a IO error occurspublic void start(int level) throws java.lang.Exception
MembershipService
start
in interface MembershipService
level
- - level MBR_RX starts listening for members, level MBR_TX
starts broad casting the serverjava.lang.Exception
- if the service fails to start.java.lang.IllegalArgumentException
- if the level is incorrect.public void stop(int svc)
stop
in interface MembershipService
svc
- - level MBR_RX stops listening for members, level MBR_TX
stops broad casting the serverpublic java.lang.String[] getMembersByName()
getMembersByName
in interface MembershipService
public Member findMemberByName(java.lang.String name)
findMemberByName
in interface MembershipService
public boolean hasMembers()
hasMembers
in interface MembershipService
public Member getMember(Member mbr)
getMember
in interface MembershipService
mbr
- Memberpublic Member[] getMembers()
MembershipService
getMembers
in interface MembershipService
public void setMembershipListener(MembershipListener listener)
setMembershipListener
in interface MembershipService
listener
- The listenerpublic void setMessageListener(MessageListener listener)
public void removeMessageListener()
public void removeMembershipListener()
removeMembershipListener
in interface MembershipService
public void memberAdded(Member member)
MembershipListener
memberAdded
in interface MembershipListener
member
- Member - the member that was addedpublic void memberDisappeared(Member member)
memberDisappeared
in interface MembershipListener
member
- The memberMember.SHUTDOWN_PAYLOAD
public void messageReceived(ChannelMessage msg)
MessageListener
messageReceived
in interface MessageListener
msg
- ChannelMessagepublic boolean accept(ChannelMessage msg)
accept
in interface MessageListener
public void broadcast(ChannelMessage message) throws ChannelException
MembershipService
broadcast
in interface MembershipService
ChannelException
public int getSoTimeout()
public void setSoTimeout(int mcastSoTimeout)
public int getTtl()
public byte[] getPayload()
public byte[] getDomain()
public void setTtl(int mcastTTL)
public void setPayload(byte[] payload)
MembershipService
setPayload
in interface MembershipService
payload
- byte[]public void setDomain(byte[] domain)
setDomain
in interface MembershipService
public void setDomain(java.lang.String domain)
public Channel getChannel()
public void setChannel(Channel channel)
protected void setDefaults(java.util.Properties properties)
public static void main(java.lang.String[] args) throws java.lang.Exception
args
- Command-line argumentsjava.lang.Exception
- If an error occursCopyright © 2000-2018 Apache Software Foundation. All Rights Reserved.