public class Learner extends ElectionAgentThread
Modifier and Type | Class and Description |
---|---|
static interface |
Learner.Listener |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SERVICE_NAME |
channelQueue, formatter, logger, protocol
envImpl
Constructor and Description |
---|
Learner(Protocol protocol,
RepNode repNode) |
Learner(Protocol protocol,
ServiceDispatcher serviceDispatcher)
Creates an instance of a Learner which will listen for and propagate
messages to local Listeners.
|
Modifier and Type | Method and Description |
---|---|
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,
java.util.Set<java.net.InetSocketAddress> learnerSockets,
java.util.logging.Logger logger,
RepImpl repImpl,
java.util.logging.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 java.util.logging.Logger |
getLogger() |
static void |
informLearners(java.util.Set<java.net.InetSocketAddress> learners,
Proposer.WinningProposal winningProposal,
Protocol protocol,
java.util.concurrent.ExecutorService threadPool,
java.util.logging.Logger logger,
RepImpl repImpl,
java.util.logging.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(java.util.Set<java.net.InetSocketAddress> learnerSockets)
Queries other learners, in parallel, to determine whether they know of
an existing master in the group.
|
void |
reinformLearners(java.util.Set<java.net.InetSocketAddress> learners,
java.util.concurrent.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.
|
initiateSoftShutdown, shutdown
cleanup, getSavedShutdownException, getTotalCpuTime, getTotalUserTime, isShutdown, saveShutdownException, setExceptionListener, shutdownDone, shutdownThread
activeCount, checkAccess, clone, 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
public static final java.lang.String SERVICE_NAME
public Learner(Protocol protocol, ServiceDispatcher serviceDispatcher) throws java.io.IOException
protocol
- the protocol used for message exchange.java.io.IOException
- if the listener socket could not be established.public void addListener(Learner.Listener listener)
listener
- the new listener to be addedvoid removeListener(Learner.Listener listener)
listener
- the listener to be removed.public void processResult(Proposer.Proposal proposal, Protocol.Value value)
proposal
- the winning proposalvalue
- the winning valuepublic void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void queryForMaster(java.util.Set<java.net.InetSocketAddress> learnerSockets)
processResult(com.sleepycat.je.rep.elections.Proposer.Proposal, com.sleepycat.je.rep.elections.Protocol.Value)
as though it were an election
result that was sent to the Learner, resulting in the node transitioning
to the master or replica state as appropriate.
Note that this node itself is not allowed to become a master as a result of such a query. It must only do so via an election.
learnerSockets
- the sockets associated with learners at other
nodes. The nodes are queried on these sockets.public static MasterValue findMaster(Protocol protocol, java.util.Set<java.net.InetSocketAddress> learnerSockets, java.util.logging.Logger logger, RepImpl repImpl, java.util.logging.Formatter formatter) throws UnknownMasterException
protocol
- the protocol to be used when determining the masterlearnerSockets
- the learner to be queried for the masterlogger
- for log messagesUnknownMasterException
- if no master could be establishedpublic void reinformLearners(java.util.Set<java.net.InetSocketAddress> learners, java.util.concurrent.ExecutorService threadPool)
learners
- the learners that must be informedthreadPool
- the pool used to dispatch broadcast requests in
in parallelpublic static void informLearners(java.util.Set<java.net.InetSocketAddress> learners, Proposer.WinningProposal winningProposal, Protocol protocol, java.util.concurrent.ExecutorService threadPool, java.util.logging.Logger logger, RepImpl repImpl, java.util.logging.Formatter formatter)
learners
- that need to be informed.winningProposal
- the result that needs to be propagatedprotocol
- to be used for communicationthreadPool
- used to supply threads for the broadcastprotected java.util.logging.Logger getLogger()
getLogger
in class ElectionAgentThread
StoppableThread.getLogger()
Copyright (c) 2004-2012 Oracle. All rights reserved.