public class Broker extends Object implements Runnable
Modifier and Type | Class and Description |
---|---|
static class |
Broker.WrappedResponse
We wrap responses in a class that has a machine ID, and then put them in a TreeSet so that
the machine with the lowest ID on a given graph always gets single-point work.
|
Modifier and Type | Field and Description |
---|---|
CircularList<Job> |
jobs |
int |
MAX_TASKS_PER_WORKER
the most tasks to deliver to a worker at a time
|
static long |
WORKER_STARTUP_TIME
How long to give workers to start up (in ms) before assuming that they have started (and starting more
on a given graph if they haven't.
|
Constructor and Description |
---|
Broker(Properties brokerConfig,
String addr,
int port) |
Modifier and Type | Method and Description |
---|---|
boolean |
anyJobsActive() |
void |
createWorkersForGraph(String graphId)
Create workers for a given job, if need be
|
boolean |
deleteJob(String jobId)
delete a job
|
org.glassfish.grizzly.http.server.Response |
deletePriorityTask(int taskId)
Marks the specified priority request as completed, and returns the suspended Response object for the connection
that submitted the priority request (the UI), which probably still waiting to receive a result back over the
same connection.
|
boolean |
deliver(Job job,
org.glassfish.grizzly.http.server.Response response)
Attempt to hand some tasks from the given job to a waiting consumer connection.
|
void |
deliverHighPriorityTasks(String graphId)
attempt to deliver high priority tasks via side channels, or move them into normal channels if need be
|
void |
deliverTasks()
This method checks whether there are any high-priority tasks or normal job tasks and attempts to match them with
waiting workers.
|
void |
enqueuePriorityTask(AnalystClusterRequest task,
org.glassfish.grizzly.http.server.Response response)
Enqueue a task for execution ASAP, planning to return the response over the same HTTP connection.
|
void |
enqueueTasks(List<AnalystClusterRequest> tasks)
Enqueue some tasks for queued execution possibly much later.
|
Job |
findJob(AnalystClusterRequest task)
find the job for a task, creating it if it does not exist
|
Job |
findJob(String jobId)
find the job for a jobId, or null if it does not exist
|
Job |
getJobForTask(int taskId)
This uses a linear search through jobs, which should not be problematic unless there are thousands of
simultaneous jobs.
|
boolean |
markTaskCompleted(int taskId)
Take a normal (non-priority) task out of a job queue, marking it as completed so it will not be re-delivered.
|
void |
registerSinglePointChannel(String graphAffinity,
Broker.WrappedResponse response)
Register an HTTP connection that can be used to send single point requests directly to
workers, bypassing normal task distribution channels.
|
void |
registerSuspendedResponse(String graphId,
org.glassfish.grizzly.http.server.Response response)
Consumer long-poll operations are enqueued here.
|
boolean |
removeSinglePointChannel(String graphAffinity,
Broker.WrappedResponse response)
Remove a single point channel because the connection was closed.
|
boolean |
removeSuspendedResponse(String graphId,
org.glassfish.grizzly.http.server.Response response)
When we notice that a long poll connection has closed, we remove it here.
|
void |
run() |
boolean |
workersAvailableForGraph(String graphId) |
public final CircularList<Job> jobs
public final int MAX_TASKS_PER_WORKER
public static final long WORKER_STARTUP_TIME
public Broker(Properties brokerConfig, String addr, int port)
public void enqueuePriorityTask(AnalystClusterRequest task, org.glassfish.grizzly.http.server.Response response)
public void deliverHighPriorityTasks(String graphId)
public void enqueueTasks(List<AnalystClusterRequest> tasks)
public boolean workersAvailableForGraph(String graphId)
public void createWorkersForGraph(String graphId)
public void registerSuspendedResponse(String graphId, org.glassfish.grizzly.http.server.Response response)
public boolean removeSuspendedResponse(String graphId, org.glassfish.grizzly.http.server.Response response)
public void registerSinglePointChannel(String graphAffinity, Broker.WrappedResponse response)
public boolean removeSinglePointChannel(String graphAffinity, Broker.WrappedResponse response)
public void deliverTasks() throws InterruptedException
InterruptedException
public Job getJobForTask(int taskId)
public boolean deliver(Job job, org.glassfish.grizzly.http.server.Response response)
public boolean markTaskCompleted(int taskId)
public org.glassfish.grizzly.http.server.Response deletePriorityTask(int taskId)
public Job findJob(AnalystClusterRequest task)
public boolean deleteJob(String jobId)
public boolean anyJobsActive()
Copyright © 2018. All rights reserved.