public abstract class AbstractTwillService
extends com.google.common.util.concurrent.AbstractExecutionThreadService
implements org.apache.twill.internal.state.MessageCallback
Service that uses ZooKeeper to transmit states and messages. It uses
the following directory structure in ZK:
/instances
|- [runId_1]
|- [runId_2]
|- ...
/[runId_1]
|- messages
|- [messageId_1]
|- [messageId_2]
|- ....
/[runId_2]
|- messages
It assumes that the zk root node is already namespaced
(either with applicationId for AM or runnableId for containers).
The ephemeral nodes under /instances are the liveNode for each running instance. It can carries data
about that service, which is set by the corresponding implementation.
Each running instance also has its own node named by the runId. Under that node, it has a messages node for
receiving messages from the controller. New message is created by creating a sequence node under the messages
node, with the node data carrying the message content. The message node will be removed once the message
is being processed by the service.| Modifier and Type | Field and Description |
|---|---|
protected RunId |
runId |
protected ZKClient |
zkClient |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractTwillService(ZKClient zkClient,
RunId runId) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doRun()
Override to execution service work.
|
protected void |
doStart()
Override to perform any work during service start.
|
protected void |
doStop()
Overrides to perform any work during service shutdown.
|
protected Object |
getLiveNodeData()
Returns an Object to be stored in the live node.
|
protected com.google.gson.Gson |
getLiveNodeGson()
Returns a
Gson instance for serializing object returned by the getLiveNodeData() method. |
com.google.common.util.concurrent.ListenableFuture<String> |
onReceived(String messageId,
org.apache.twill.internal.state.Message message)
Handles message by simply logging it.
|
protected void |
run() |
protected void |
shutDown() |
protected void |
startUp() |
protected OperationFuture<?> |
updateLiveNode()
Update the live node for the service.
|
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, serviceName, start, startAndWait, startAsync, state, stop, stopAndWait, stopAsync, toString, triggerShutdownprotected void doStart()
throws Exception
Exceptionprotected void doRun()
throws Exception
Exceptionprotected void doStop()
throws Exception
Exceptionprotected Object getLiveNodeData()
null
is returned, no data will be stored to the live node.protected com.google.gson.Gson getLiveNodeGson()
Gson instance for serializing object returned by the getLiveNodeData() method.public com.google.common.util.concurrent.ListenableFuture<String> onReceived(String messageId, org.apache.twill.internal.state.Message message)
onReceived in interface org.apache.twill.internal.state.MessageCallbackmessage - Message being received.ListenableFuture that would be completed when message processing is completed or failed.
The result of the future should be the input message Id if succeeded.MessageCallbackprotected final void startUp()
throws Exception
startUp in class com.google.common.util.concurrent.AbstractExecutionThreadServiceExceptionprotected final void run()
throws Exception
run in class com.google.common.util.concurrent.AbstractExecutionThreadServiceExceptionprotected final void shutDown()
throws Exception
shutDown in class com.google.common.util.concurrent.AbstractExecutionThreadServiceExceptionprotected final OperationFuture<?> updateLiveNode()
OperationFuture that will be completed when the update is done.Copyright © 2013-2020 The Apache Software Foundation. All rights reserved.