Class MulticastDiscoveryAgent
- java.lang.Object
-
- org.apache.qpid.jms.provider.discovery.multicast.MulticastDiscoveryAgent
-
- All Implemented Interfaces:
Runnable,DiscoveryAgent
public class MulticastDiscoveryAgent extends Object implements DiscoveryAgent, Runnable
Discovery agent that listens on a multicast address for new Broker advisories.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_DISCOVERY_URI_STRINGstatic StringDEFAULT_HOST_IPstatic StringDEFAULT_HOST_STRstatic intDEFAULT_PORT
-
Constructor Summary
Constructors Constructor Description MulticastDiscoveryAgent(URI discoveryURI)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Stops the agent after which no new remote peers will be found.DiscoveryListenergetDiscoveryListener()URIgetDiscvoeryURI()StringgetGroup()longgetKeepAliveInterval()PacketParsergetParser()StringgetService()Returns the name of the service that is providing the discovery data for this agent such as ActiveMQ.intgetTimeToLive()booleanisLoopBackMode()booleanisSchedulerRequired()Indicates if this DiscoveryAgent requires a ScheduledExecutorService in order to perform its discovery work.voidresume()Resumes discovery by this agent if it was previously suspended.voidrun()voidsetDiscoveryListener(DiscoveryListener listener)Sets the discovery listenervoidsetGroup(String group)Sets the multicast group this agent is assigned to.voidsetInterface(String mcInterface)voidsetJoinNetworkInterface(String mcJoinNetwrokInterface)voidsetKeepAliveInterval(long keepAliveInterval)voidsetLoopBackMode(boolean loopBackMode)voidsetNetworkInterface(String mcNetworkInterface)voidsetParser(PacketParser parser)Sets the datagram packet parser used to read the discovery data broadcast by the service being monitored for remote peers.voidsetScheduler(ScheduledExecutorService scheduler)Provider a ScheduledExecutorService to the DiscoveryAgent that requires a scheduler to perform its discovery work.voidsetService(String name)Sets the name of the service that is providing the remote peer discovery data.voidsetTimeToLive(int timeToLive)voidstart()Starts the agent after which new remote peers can start to be found.voidsuspend()Suspends the Agent which suppresses any new attempts to discover remote peers until the agent is resumed.StringtoString()static voidtrySetNetworkInterface(MulticastSocket mcastSock)
-
-
-
Field Detail
-
DEFAULT_DISCOVERY_URI_STRING
public static final String DEFAULT_DISCOVERY_URI_STRING
- See Also:
- Constant Field Values
-
DEFAULT_HOST_STR
public static final String DEFAULT_HOST_STR
- See Also:
- Constant Field Values
-
DEFAULT_HOST_IP
public static final String DEFAULT_HOST_IP
-
DEFAULT_PORT
public static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MulticastDiscoveryAgent
public MulticastDiscoveryAgent(URI discoveryURI)
-
-
Method Detail
-
setDiscoveryListener
public void setDiscoveryListener(DiscoveryListener listener)
Description copied from interface:DiscoveryAgentSets the discovery listener- Specified by:
setDiscoveryListenerin interfaceDiscoveryAgent- Parameters:
listener- the listener to notify on discovery events, or null to clear.
-
getDiscoveryListener
public DiscoveryListener getDiscoveryListener()
-
setScheduler
public void setScheduler(ScheduledExecutorService scheduler)
Description copied from interface:DiscoveryAgentProvider a ScheduledExecutorService to the DiscoveryAgent that requires a scheduler to perform its discovery work. If the agent performs long polling style operations such as a socket read then it should not use the provided scheduler as that could block other agents from performing their own work.- Specified by:
setSchedulerin interfaceDiscoveryAgent- Parameters:
scheduler- An initialized Scheduler service that this agent can use for its work.
-
isSchedulerRequired
public boolean isSchedulerRequired()
Description copied from interface:DiscoveryAgentIndicates if this DiscoveryAgent requires a ScheduledExecutorService in order to perform its discovery work.- Specified by:
isSchedulerRequiredin interfaceDiscoveryAgent- Returns:
- true if the agent requires that its parent provide it with a scheduler.
-
start
public void start() throws ProviderException, IllegalStateExceptionDescription copied from interface:DiscoveryAgentStarts the agent after which new remote peers can start to be found.- Specified by:
startin interfaceDiscoveryAgent- Throws:
ProviderException- if an IO error occurs while starting the agent.IllegalStateException- if the agent is not properly configured.
-
close
public void close()
Description copied from interface:DiscoveryAgentStops the agent after which no new remote peers will be found. This method should attempt to close any agent resources and if an error occurs it should handle it and not re-throw to the calling entity.- Specified by:
closein interfaceDiscoveryAgent
-
suspend
public void suspend()
Description copied from interface:DiscoveryAgentSuspends the Agent which suppresses any new attempts to discover remote peers until the agent is resumed. If the service is not able to be suspended then this method should not throw an Exception, simply return as if successful.- Specified by:
suspendin interfaceDiscoveryAgent
-
resume
public void resume()
Description copied from interface:DiscoveryAgentResumes discovery by this agent if it was previously suspended. If the agent does not support being suspended or is closed this method should simply return without throwing any exceptions.- Specified by:
resumein interfaceDiscoveryAgent
-
getDiscvoeryURI
public URI getDiscvoeryURI()
- Returns:
- the original URI used to create the Discovery Agent.
-
isLoopBackMode
public boolean isLoopBackMode()
- Returns:
- Returns the loopBackMode.
-
setLoopBackMode
public void setLoopBackMode(boolean loopBackMode)
- Parameters:
loopBackMode- The loopBackMode to set.
-
getTimeToLive
public int getTimeToLive()
- Returns:
- Returns the timeToLive.
-
setTimeToLive
public void setTimeToLive(int timeToLive)
- Parameters:
timeToLive- The timeToLive to set.
-
getKeepAliveInterval
public long getKeepAliveInterval()
-
setKeepAliveInterval
public void setKeepAliveInterval(long keepAliveInterval)
-
setInterface
public void setInterface(String mcInterface)
-
setNetworkInterface
public void setNetworkInterface(String mcNetworkInterface)
-
setJoinNetworkInterface
public void setJoinNetworkInterface(String mcJoinNetwrokInterface)
-
getGroup
public String getGroup()
- Returns:
- the multicast group this agent is assigned to.
-
setGroup
public void setGroup(String group)
Sets the multicast group this agent is assigned to. The group can only be set prior to starting the agent, once started the group change will never take effect.- Parameters:
group- the multicast group the agent is assigned to.
-
getService
public String getService()
Returns the name of the service that is providing the discovery data for this agent such as ActiveMQ.- Returns:
- the name of the service that is advertising remote peer data.
-
setService
public void setService(String name)
Sets the name of the service that is providing the remote peer discovery data.- Parameters:
name- the name of the service that provides this agent with remote peer data.
-
getParser
public PacketParser getParser()
- Returns:
- the currently configured datagram packet parser for this agent.
-
setParser
public void setParser(PacketParser parser)
Sets the datagram packet parser used to read the discovery data broadcast by the service being monitored for remote peers.- Parameters:
parser- the datagram packet parser to use.
-
trySetNetworkInterface
public static void trySetNetworkInterface(MulticastSocket mcastSock) throws SocketException
- Throws:
SocketException
-
-