com.sleepycat.je.rep.elections
Class Learner

java.lang.Object
  extended by java.lang.Thread
      extended by com.sleepycat.je.utilint.StoppableThread
          extended by com.sleepycat.je.rep.elections.ElectionAgentThread
              extended by com.sleepycat.je.rep.elections.Learner
All Implemented Interfaces:
ExceptionListenerUser, Runnable

public class Learner
extends ElectionAgentThread

The Learner agent. It runs in its own dedicated thread, listening for messages announcing the results of elections. The Learner in turn invokes Listeners within the process to propagate the result.


Nested Class Summary
static interface Learner.Listener
           
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static String SERVICE_NAME
           
 
Fields inherited from class com.sleepycat.je.rep.elections.ElectionAgentThread
channelQueue, formatter, logger, protocol
 
Fields inherited from class com.sleepycat.je.utilint.StoppableThread
envImpl
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Learner(Protocol protocol, RepNode repNode)
           
Learner(Protocol protocol, ServiceDispatcher serviceDispatcher, NameIdPair nameIdPair)
          Creates an instance of a Learner which will listen for and propagate messages to local Listeners.
 
Method Summary
 void addListener(Learner.Listener listener)
          Adds a Listener to the existing set of listeners, so that it can be informed of the outcome of election results.
static MasterValue findMaster(Protocol protocol, Set<InetSocketAddress> learnerSockets, Logger logger, RepImpl repImpl, Formatter formatter)
          Returns the socket address for the current master, or null if one could not be determined from the available set of learners.
protected  Logger getLogger()
           
static void informLearners(Set<InetSocketAddress> learners, Proposer.WinningProposal winningProposal, Protocol protocol, ExecutorService threadPool, Logger logger, RepImpl repImpl, Formatter formatter)
          A utility method used to broadcast the results of an election to Listeners.
 void processResult(Proposer.Proposal proposal, Protocol.Value value)
          Processes a result message
 void queryForMaster(Set<InetSocketAddress> learnerSockets)
          Queries other learners to determine whether they know of a master in the group.
 void reinformLearners(Set<InetSocketAddress> learners, ExecutorService threadPool)
          A method to re-broadcast this Learner's notion of the master.
(package private)  void removeListener(Learner.Listener listener)
          Removes a Listeners from the existing set of listeners.
 void run()
          The main Learner loop.
 
Methods inherited from class com.sleepycat.je.rep.elections.ElectionAgentThread
initiateSoftShutdown, shutdown
 
Methods inherited from class com.sleepycat.je.utilint.StoppableThread
cleanup, getSavedShutdownException, getTotalCpuTime, getTotalUserTime, isShutdown, saveShutdownException, setExceptionListener, shutdownDone, shutdownThread
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SERVICE_NAME

public static final String SERVICE_NAME
See Also:
Constant Field Values
Constructor Detail

Learner

public Learner(Protocol protocol,
               ServiceDispatcher serviceDispatcher,
               NameIdPair nameIdPair)
        throws IOException
Creates an instance of a Learner which will listen for and propagate messages to local Listeners. Note that this constructor, does not take a repNode as an argument, so that it can be used as the basis for the standalone Monitor.

Parameters:
protocol - the protocol used for message exchange.
nameIdPair - a unique identifier for this election module
Throws:
IOException - if the listener socket could not be established.

Learner

public Learner(Protocol protocol,
               RepNode repNode)
Method Detail

addListener

public void addListener(Learner.Listener listener)
Adds a Listener to the existing set of listeners, so that it can be informed of the outcome of election results.

Parameters:
listener - the new listener to be added

removeListener

void removeListener(Learner.Listener listener)
Removes a Listeners from the existing set of listeners.

Parameters:
listener - the listener to be removed.

processResult

public void processResult(Proposer.Proposal proposal,
                          Protocol.Value value)
Processes a result message

Parameters:
proposal - the winning proposal
value - the winning value

run

public void run()
The main Learner loop. It accepts requests and propagates them to its Listeners, if the proposal isn't out of date.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

queryForMaster

public void queryForMaster(Set<InetSocketAddress> learnerSockets)
Queries other learners to determine whether they know of a master in the group.

Parameters:
learnerSockets -

findMaster

public static MasterValue findMaster(Protocol protocol,
                                     Set<InetSocketAddress> learnerSockets,
                                     Logger logger,
                                     RepImpl repImpl,
                                     Formatter formatter)
                              throws UnknownMasterException
Returns the socket address for the current master, or null if one could not be determined from the available set of learners. This API is suitable for tools which need to contact the master for a specific service, e.g. to delete a replication node, or to add a monitor. This method could be used in principle to establish other types of nodes as well via a tool, but that is currently done by the handshake process.

Parameters:
protocol - the protocol to be used when determining the master
learnerSockets - the learner to be queried for the master
logger - for log messages
Returns:
the MasterValue identifying the master
Throws:
UnknownMasterException - if no master could be established

reinformLearners

public void reinformLearners(Set<InetSocketAddress> learners,
                             ExecutorService threadPool)
A method to re-broadcast this Learner's notion of the master. This re-broadcast is done primarily to inform an obsolete master that it's no longer the current master. Obsolete master situations arise in network partition scenarios, where a current master is not able to participate in an election, nor is it informed about the results. The re-broadcast is the mechanism for rectifying such a situation. When the obsolete master receives the new results after the network partition has been fixed, it will revert to being a replica.

Parameters:
learners - the learners that must be informed
threadPool - the pool used to dispatch broadcast requests in in parallel

informLearners

public static void informLearners(Set<InetSocketAddress> learners,
                                  Proposer.WinningProposal winningProposal,
                                  Protocol protocol,
                                  ExecutorService threadPool,
                                  Logger logger,
                                  RepImpl repImpl,
                                  Formatter formatter)
A utility method used to broadcast the results of an election to Listeners.

Parameters:
learners - that need to be informed.
winningProposal - the result that needs to be propagated
protocol - to be used for communication
threadPool - used to supply threads for the broadcast

getLogger

protected Logger getLogger()
Overrides:
getLogger in class ElectionAgentThread
Returns:
a logger to use when logging uncaught exceptions.
See Also:
StoppableThread.getLogger()


Copyright (c) 2004-2010 Oracle. All rights reserved.