public abstract class AbstractLBSPolicy extends Object implements IHALoadBalancerPolicy, QuorumListener, Serializable
Modifier and Type | Class and Description |
---|---|
static interface |
AbstractLBSPolicy.InitParams |
Modifier and Type | Field and Description |
---|---|
protected AtomicReference<WeakReference<IHAJournal>> |
journalRef
|
protected AtomicReference<UUID> |
serviceIDRef
The
UUID of the HAJournalServer. |
protected AtomicReference<ServiceScore[]> |
serviceTableRef
This is the table of known services.
|
Constructor and Description |
---|
AbstractLBSPolicy() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
conditionallyForwardReadRequest(HALoadBalancerServlet servlet,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Hook provides the
IHALoadBalancerPolicy with an opportunity to
forward a read-request to the local service rather than proxying the
request to a service selected by the load balancer (a local forward has
less overhead than proxying to either the local host or a remote service,
which makes it more efficient under some circumstances to handle the
read-request on the service where it was originally received). |
protected void |
conditionallyUpdateServiceTable()
Conditionally update the
serviceTableRef iff it does not exist or
is empty. |
void |
destroy()
Destroy the policy (stop any asynchronous processing, release any
resources).
|
protected IHAJournal |
getJournal()
Return the cached reference to the
HAJournal . |
String |
getLeaderURI(javax.servlet.http.HttpServletRequest request)
Return the Request-URI to which a non-idempotent request will be proxied.
|
protected ServiceScore |
getLocalServiceScore()
Return the
ServiceScore for the HAGlue service running on
this host within this webapp. |
protected ServiceScore |
getServiceScoreForHostname(String hostname)
Return the first service found for the indicated host.
|
void |
init(javax.servlet.ServletConfig servletConfig,
IIndexManager indexManager)
Initialize the policy.
|
void |
notify(QuorumEvent e)
Notify the client of a quorum event.
|
boolean |
service(boolean isLeaderRequest,
HALoadBalancerServlet servlet,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Invoked for each request.
|
String |
toString()
Note: implementation is non-blocking!
|
protected void |
toString(StringBuilder sb)
Extension hook for
toString() - implementation MUST NOT block. |
protected void |
updateServiceTable()
Update the per-service table.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getReaderURI
protected final AtomicReference<WeakReference<IHAJournal>> journalRef
protected final AtomicReference<UUID> serviceIDRef
UUID
of the HAJournalServer.protected final AtomicReference<ServiceScore[]> serviceTableRef
public String toString()
protected void toString(StringBuilder sb)
toString()
- implementation MUST NOT block.sb
- Buffer where you can write additional state.protected IHAJournal getJournal()
HAJournal
.null
iff the reference has been
cleared or has not yet been set.public void destroy()
IHAPolicyLifeCycle
destroy
in interface IHAPolicyLifeCycle
public void init(javax.servlet.ServletConfig servletConfig, IIndexManager indexManager) throws javax.servlet.ServletException
IHAPolicyLifeCycle
init
in interface IHAPolicyLifeCycle
javax.servlet.ServletException
public boolean service(boolean isLeaderRequest, HALoadBalancerServlet servlet, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
IHALoadBalancerPolicy
HALoadBalancerServlet
.service
in interface IHALoadBalancerPolicy
isLeaderRequest
- true
iff this request must be directed to the
leaeder and false
iff this request may be load
balanced over the joined services. UPDATEs MUST be handled by
the leader. Read requests can be handled by any service that
is joined with the met quorum.servlet
- The HALoadBalancerServlet
. This is exposed in order to
allow the IHALoadBalancerPolicy
to perform a local
forward of the request.request
- The request.response
- The response.true
iff the request was handled.javax.servlet.ServletException
IOException
protected boolean conditionallyForwardReadRequest(HALoadBalancerServlet servlet, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
IHALoadBalancerPolicy
with an opportunity to
forward a read-request to the local service rather than proxying the
request to a service selected by the load balancer (a local forward has
less overhead than proxying to either the local host or a remote service,
which makes it more efficient under some circumstances to handle the
read-request on the service where it was originally received).IOException
public final String getLeaderURI(javax.servlet.http.HttpServletRequest request)
This implementation rewrites the requestURL such that the request will be proxied to the quorum leader.
getLeaderURI
in interface IHALoadBalancerPolicy
request
- The request.null
if we could not
find a service to which we could proxy this request.protected ServiceScore getLocalServiceScore()
ServiceScore
for the HAGlue
service running on
this host within this webapp.protected ServiceScore getServiceScoreForHostname(String hostname)
hostname
- The hostname.public void notify(QuorumEvent e)
The listener MUST NOT take any event that could block. In particular, it
MUST NOT wait on another thread that will access the Quorum
as
that will cause a deadlock around the internal lock maintained by the
Quorum
.
The services table is updated if a services joins or leaves the quorum.
FIXME The QuorumListener
is unregistered by
AbstractQuorum.terminate()
. This happens any time the
HAJournalServer goes into the error state. When this occurs, we
stop getting QuorumEvent
s and the policy stops being responsive
(it can not proxy the request to a service that is still up because it
does not know what services are up, or maybe it just can not learn if
services go down).
We probably need to either NOT clear the quorum listener and/or add an
event type that is sent when Quorum.terminate()
is called and/or
use our own listener (independent of the HAJournalServer, which would
require us to use an HAClient).
This should be robust even when the HAQuorumService is not running. We do not want to be unable to proxy to another service just because this one is going through an error state. Would it make more sense to have a 2nd Quorum object for this purpose - one that is not started and stopped by the HAJournalServer?
notify
in interface QuorumListener
(HAJournal start() delay)
protected void conditionallyUpdateServiceTable()
serviceTableRef
iff it does not exist or
is empty.protected void updateServiceTable()
serviceTableRef
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.