Methods Summary |
---|
public org.apache.catalina.tribes.Member | findMemberByName(java.lang.String name)Return the member by name
Member[] currentMembers = getMembers();
for (int i = 0; i < currentMembers.length; i++) {
if (name.equals(currentMembers[i].toString()))
return currentMembers[i];
}
return null;
|
public java.lang.String | getAddress()
return properties.getProperty("mcastAddress");
|
public java.lang.String | getBind()
return properties.getProperty("mcastBindAddress");
|
public byte[] | getDomain()
return domain;
|
public long | getDropTime()
String p = properties.getProperty("memberDropTime");
return new Long(p).longValue();
|
public long | getFrequency()
String p = properties.getProperty("mcastFrequency");
return new Long(p).longValue();
|
public java.lang.String | getInfo()Return descriptive information about this implementation and the
corresponding version number, in the format
<description>/<version> .
return (info);
|
public org.apache.catalina.tribes.Member | getLocalMember(boolean alive)Return the local member
if ( alive && localMember != null && impl != null) localMember.setMemberAliveTime(System.currentTimeMillis()-impl.getServiceStartTime());
return localMember;
|
public java.lang.String | getLocalMemberName()Return the local member name
return localMember.toString() ;
|
public java.lang.String | getMcastAddr()
return getAddress();
|
public java.lang.String | getMcastBindAddress()
return getBind();
|
public long | getMcastDropTime()
return getDropTime();
|
public long | getMcastFrequency()
return getFrequency();
|
public int | getMcastPort()
return getPort();
|
public int | getMcastSoTimeout()
return getSoTimeout();
|
public int | getMcastTTL()
return getTtl();
|
public org.apache.catalina.tribes.Member | getMember(org.apache.catalina.tribes.Member mbr)
if ( impl == null || impl.membership == null ) return null;
return impl.membership.getMember(mbr);
|
public org.apache.catalina.tribes.Member[] | getMembers()
if ( impl == null || impl.membership == null ) return EMPTY_MEMBERS;
return impl.membership.getMembers();
|
public java.lang.String[] | getMembersByName()Return all the members by name
Member[] currentMembers = getMembers();
String [] membernames ;
if(currentMembers != null) {
membernames = new String[currentMembers.length];
for (int i = 0; i < currentMembers.length; i++) {
membernames[i] = currentMembers[i].toString() ;
}
} else
membernames = new String[0] ;
return membernames ;
|
public byte[] | getPayload()
return payload;
|
public int | getPort()
String p = properties.getProperty("mcastPort");
return new Integer(p).intValue();
|
public java.util.Properties | getProperties()Return the properties, see setProperties
return properties;
|
public int | getSoTimeout()
return mcastSoTimeout;
|
public int | getTtl()
return mcastTTL;
|
public boolean | hasMembers()has members?
if ( impl == null || impl.membership == null ) return false;
return impl.membership.hasMembers();
|
protected void | hasProperty(java.util.Properties properties, java.lang.String name)Check if a required property is available.
if ( properties.getProperty(name)==null) throw new IllegalArgumentException("McastService:Required property \""+name+"\" is missing.");
|
public static void | main(java.lang.String[] args)Simple test program
if(log.isInfoEnabled())
log.info("Usage McastService hostname tcpport");
McastService service = new McastService();
java.util.Properties p = new java.util.Properties();
p.setProperty("mcastPort","5555");
p.setProperty("mcastAddress","224.10.10.10");
p.setProperty("mcastClusterDomain","catalina");
p.setProperty("bindAddress","localhost");
p.setProperty("memberDropTime","3000");
p.setProperty("mcastFrequency","500");
p.setProperty("tcpListenPort","4000");
p.setProperty("tcpListenHost","127.0.0.1");
service.setProperties(p);
service.start();
Thread.sleep(60*1000*60);
|
public void | memberAdded(org.apache.catalina.tribes.Member member)
if ( listener!=null ) listener.memberAdded(member);
|
public void | memberDisappeared(org.apache.catalina.tribes.Member member)Callback from the impl when a new member has been received
if ( listener!=null ) listener.memberDisappeared(member);
|
public void | removeMembershipListener()Remove the membership listener
listener = null;
|
public void | setAddress(java.lang.String addr)
properties.setProperty("mcastAddress", addr);
|
public void | setBind(java.lang.String bindaddr)
properties.setProperty("mcastBindAddress", bindaddr);
|
public void | setDomain(byte[] domain)
this.domain = domain;
if ( localMember != null ) {
localMember.setDomain(domain);
localMember.getData(true,true);
try {
if (impl != null) impl.send(false);
}catch ( Exception x ) {
log.error("Unable to send domain update.",x);
}
}
|
public void | setDropTime(long time)
properties.setProperty("memberDropTime", String.valueOf(time));
|
public void | setFrequency(long time)
properties.setProperty("mcastFrequency", String.valueOf(time));
|
public void | setLocalMemberProperties(java.lang.String listenHost, int listenPort)Sets the local member properties for broadcasting
properties.setProperty("tcpListenHost",listenHost);
properties.setProperty("tcpListenPort",String.valueOf(listenPort));
try {
if (localMember != null) {
localMember.setHostname(listenHost);
localMember.setPort(listenPort);
} else {
localMember = new MemberImpl(listenHost, listenPort, 0);
localMember.setUniqueId(UUIDGenerator.randomUUID(true));
localMember.setPayload(getPayload());
localMember.setDomain(getDomain());
}
localMember.getData(true, true);
}catch ( IOException x ) {
throw new IllegalArgumentException(x);
}
|
public void | setMcastAddr(java.lang.String addr)
setAddress(addr);
|
public void | setMcastBindAddress(java.lang.String bindaddr)
setBind(bindaddr);
|
public void | setMcastDropTime(long time)
setDropTime(time);
|
public void | setMcastFrequency(long time)
setFrequency(time);
|
public void | setMcastPort(int port)
setPort(port);
|
public void | setMcastSoTimeout(int mcastSoTimeout)
setSoTimeout(mcastSoTimeout);
|
public void | setMcastTTL(int mcastTTL)
setTtl(mcastTTL);
|
public void | setMembershipListener(org.apache.catalina.tribes.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.
this.listener = listener;
|
public void | setPayload(byte[] payload)
this.payload = payload;
if ( localMember != null ) {
localMember.setPayload(payload);
localMember.getData(true,true);
try {
if (impl != null) impl.send(false);
}catch ( Exception x ) {
log.error("Unable to send payload update.",x);
}
}
|
public void | setPort(int port)
properties.setProperty("mcastPort", String.valueOf(port));
|
public void | setProperties(java.util.Properties properties)
hasProperty(properties,"mcastPort");
hasProperty(properties,"mcastAddress");
hasProperty(properties,"memberDropTime");
hasProperty(properties,"mcastFrequency");
hasProperty(properties,"tcpListenPort");
hasProperty(properties,"tcpListenHost");
this.properties = properties;
|
public void | setSoTimeout(int mcastSoTimeout)
this.mcastSoTimeout = mcastSoTimeout;
properties.setProperty("mcastSoTimeout", String.valueOf(mcastSoTimeout));
|
public void | setTtl(int mcastTTL)
this.mcastTTL = mcastTTL;
properties.setProperty("mcastTTL", String.valueOf(mcastTTL));
|
public void | start()Start broadcasting and listening to membership pings
start(MembershipService.MBR_RX);
start(MembershipService.MBR_TX);
|
public void | start(int level)
hasProperty(properties,"mcastPort");
hasProperty(properties,"mcastAddress");
hasProperty(properties,"memberDropTime");
hasProperty(properties,"mcastFrequency");
hasProperty(properties,"tcpListenPort");
hasProperty(properties,"tcpListenHost");
if ( impl != null ) {
impl.start(level);
return;
}
String host = getProperties().getProperty("tcpListenHost");
int port = Integer.parseInt(getProperties().getProperty("tcpListenPort"));
if ( localMember == null ) {
localMember = new MemberImpl(host, port, 100);
localMember.setUniqueId(UUIDGenerator.randomUUID(true));
} else {
localMember.setHostname(host);
localMember.setPort(port);
localMember.setMemberAliveTime(100);
}
if ( this.payload != null ) localMember.setPayload(payload);
if ( this.domain != null ) localMember.setDomain(domain);
localMember.setServiceStartTime(System.currentTimeMillis());
java.net.InetAddress bind = null;
if ( properties.getProperty("mcastBindAddress")!= null ) {
bind = java.net.InetAddress.getByName(properties.getProperty("mcastBindAddress"));
}
int ttl = -1;
int soTimeout = -1;
if ( properties.getProperty("mcastTTL") != null ) {
try {
ttl = Integer.parseInt(properties.getProperty("mcastTTL"));
} catch ( Exception x ) {
log.error("Unable to parse mcastTTL="+properties.getProperty("mcastTTL"),x);
}
}
if ( properties.getProperty("mcastSoTimeout") != null ) {
try {
soTimeout = Integer.parseInt(properties.getProperty("mcastSoTimeout"));
} catch ( Exception x ) {
log.error("Unable to parse mcastSoTimeout="+properties.getProperty("mcastSoTimeout"),x);
}
}
impl = new McastServiceImpl((MemberImpl)localMember,Long.parseLong(properties.getProperty("mcastFrequency")),
Long.parseLong(properties.getProperty("memberDropTime")),
Integer.parseInt(properties.getProperty("mcastPort")),
bind,
java.net.InetAddress.getByName(properties.getProperty("mcastAddress")),
ttl,
soTimeout,
this);
impl.start(level);
|
public void | stop(int svc)Stop broadcasting and listening to membership pings
try {
if ( impl != null && impl.stop(svc) ) impl = null;
} catch ( Exception x) {
log.error("Unable to stop the mcast service, level:"+svc+".",x);
}
|