org.apache.jcs.utils.discovery
Class UDPDiscoveryService

java.lang.Object
  extended by org.apache.jcs.utils.discovery.UDPDiscoveryService
All Implemented Interfaces:
IRequireScheduler, IShutdownObserver

public class UDPDiscoveryService
extends Object
implements IShutdownObserver, IRequireScheduler

This service creates a listener that can create lateral caches and add them to the no wait list.

It also creates a sender that periodically broadcasts its availability.

The sender also broadcasts a request for other caches to broadcast their addresses.

Author:
Aaron Smuts

Constructor Summary
UDPDiscoveryService(UDPDiscoveryAttributes attributes, ICacheEventLogger cacheEventLogger)
           
 
Method Summary
 boolean addDiscoveryListener(IDiscoveryListener listener)
          Adds a listener.
protected  void addOrUpdateService(DiscoveredService discoveredService)
          Add a service to the list.
 void addParticipatingCacheName(String cacheName)
          Adds a region to the list that is participating in discovery.
protected  void finalize()
          Call shutdown to be safe.
protected  ArrayList<String> getCacheNames()
          Get all the cache names we have facades for.
 Set<IDiscoveryListener> getCopyOfDiscoveryListeners()
           
 Set<DiscoveredService> getDiscoveredServices()
           
 UDPDiscoveryAttributes getUdpDiscoveryAttributes()
           
 void removeDiscoveredService(DiscoveredService service)
          Removes the discovered service from the list and calls the discovery listener.
 boolean removeDiscoveryListener(IDiscoveryListener listener)
          Removes a listener.
protected  void serviceRequestBroadcast()
          Send a passive broadcast in response to a request broadcast.
 void setDiscoveredServices(Set<DiscoveredService> discoveredServices)
           
 void setScheduledExecutorService(ScheduledExecutorService scheduledExecutor)
          Inject an instance of a central ScheduledExecutorService
 void setUdpDiscoveryAttributes(UDPDiscoveryAttributes attr)
           
 void shutdown()
          Shuts down the receiver.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPDiscoveryService

public UDPDiscoveryService(UDPDiscoveryAttributes attributes,
                           ICacheEventLogger cacheEventLogger)
Parameters:
attributes -
cacheEventLogger -
Method Detail

setScheduledExecutorService

public void setScheduledExecutorService(ScheduledExecutorService scheduledExecutor)
Description copied from interface: IRequireScheduler
Inject an instance of a central ScheduledExecutorService

Specified by:
setScheduledExecutorService in interface IRequireScheduler
See Also:
IRequireScheduler.setScheduledExecutorService(java.util.concurrent.ScheduledExecutorService)

serviceRequestBroadcast

protected void serviceRequestBroadcast()
Send a passive broadcast in response to a request broadcast. Never send a request for a request. We can respond to our own requests, since a request broadcast is not intended as a connection request. We might want to only send messages, so we would send a request, but never a passive broadcast.


addParticipatingCacheName

public void addParticipatingCacheName(String cacheName)
Adds a region to the list that is participating in discovery.

Parameters:
cacheName -

removeDiscoveredService

public void removeDiscoveredService(DiscoveredService service)
Removes the discovered service from the list and calls the discovery listener.

Parameters:
service -

addOrUpdateService

protected void addOrUpdateService(DiscoveredService discoveredService)
Add a service to the list. Update the held copy if we already know about it.

Parameters:
discoveredService - discovered service

getCacheNames

protected ArrayList<String> getCacheNames()
Get all the cache names we have facades for.

Returns:
ArrayList

setUdpDiscoveryAttributes

public void setUdpDiscoveryAttributes(UDPDiscoveryAttributes attr)
Parameters:
attr - The UDPDiscoveryAttributes to set.

getUdpDiscoveryAttributes

public UDPDiscoveryAttributes getUdpDiscoveryAttributes()
Returns:
Returns the lca.

shutdown

public void shutdown()
Shuts down the receiver.

Specified by:
shutdown in interface IShutdownObserver

finalize

protected void finalize()
                 throws Throwable
Call shutdown to be safe.

Overrides:
finalize in class Object
Throws:
Throwable - on error

setDiscoveredServices

public void setDiscoveredServices(Set<DiscoveredService> discoveredServices)
Parameters:
discoveredServices - The discoveredServices to set.

getDiscoveredServices

public Set<DiscoveredService> getDiscoveredServices()
Returns:
Returns the discoveredServices.

getCopyOfDiscoveryListeners

public Set<IDiscoveryListener> getCopyOfDiscoveryListeners()
Returns:
the discoveryListeners

addDiscoveryListener

public boolean addDiscoveryListener(IDiscoveryListener listener)
Adds a listener.

Parameters:
listener -
Returns:
true if it wasn't already in the set

removeDiscoveryListener

public boolean removeDiscoveryListener(IDiscoveryListener listener)
Removes a listener.

Parameters:
listener -
Returns:
true if it was in the set


Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.