public final class BasicTwillContext extends Object implements TwillContext
TwillContext that provides the basic runtime information of a TwillRunnable.| Constructor and Description |
|---|
BasicTwillContext(RunId runId,
RunId appRunId,
InetAddress host,
String[] args,
String[] appArgs,
TwillRunnableSpecification spec,
int instanceId,
DiscoveryService discoveryService,
DiscoveryServiceClient discoveryServiceClient,
ZKClient zkClient,
int instanceCount,
int allowedMemoryMB,
int virtualCores) |
| Modifier and Type | Method and Description |
|---|---|
Cancellable |
announce(String serviceName,
int port)
Registers an endpoint that could be discovered by external party.
|
Cancellable |
announce(String serviceName,
int port,
byte[] payload)
Registers an endpoint that could be discovered by external party with a payload.
|
Lock |
createLock(String name)
Creates a
Lock for performing locking mechanism within the same TwillApplication. |
ServiceDiscovered |
discover(String name)
Discover service with the given name that is announced within the same
TwillApplication. |
Cancellable |
electLeader(String name,
ElectionHandler participantHandler)
Register to participate in a leader election by instances within the same
TwillApplication. |
String[] |
getApplicationArguments()
Returns the runtime arguments that are passed to the
TwillApplication. |
RunId |
getApplicationRunId()
Returns the
RunId of this running application. |
String[] |
getArguments()
Returns the runtime arguments that are passed to the
TwillRunnable. |
InetAddress |
getHost()
Returns the hostname that the runnable is running on.
|
int |
getInstanceCount()
Returns the number of running instances assigned for this
TwillRunnable. |
int |
getInstanceId()
Returns an integer id from 0 to (instanceCount - 1).
|
int |
getMaxMemoryMB()
Returns the amount of memory in MB the runnable is allowed to use.
|
RunId |
getRunId()
Returns the
RunId of this running instance of TwillRunnable. |
TwillRunnableSpecification |
getSpecification()
Returns the
TwillRunnableSpecification that was created by TwillRunnable.configure(). |
int |
getVirtualCores()
Returns the number of virtual cores the runnable is allowed to use.
|
void |
setInstanceCount(int count) |
void |
stop()
Stops and frees any currently allocated resources.
|
public BasicTwillContext(RunId runId, RunId appRunId, InetAddress host, String[] args, String[] appArgs, TwillRunnableSpecification spec, int instanceId, DiscoveryService discoveryService, DiscoveryServiceClient discoveryServiceClient, ZKClient zkClient, int instanceCount, int allowedMemoryMB, int virtualCores)
public RunId getRunId()
TwillContextRunId of this running instance of TwillRunnable.getRunId in interface TwillContextpublic RunId getApplicationRunId()
TwillContextRunId of this running application.getApplicationRunId in interface TwillContextpublic int getInstanceCount()
TwillContextTwillRunnable.getInstanceCount in interface TwillContextpublic void setInstanceCount(int count)
public InetAddress getHost()
TwillContextgetHost in interface TwillContextpublic String[] getArguments()
TwillContextTwillRunnable.getArguments in interface TwillContextpublic String[] getApplicationArguments()
TwillContextTwillApplication.getApplicationArguments in interface TwillContextpublic TwillRunnableSpecification getSpecification()
TwillContextTwillRunnableSpecification that was created by TwillRunnable.configure().getSpecification in interface TwillContextpublic int getInstanceId()
TwillContextgetInstanceId in interface TwillContextpublic int getVirtualCores()
TwillContextgetVirtualCores in interface TwillContextpublic int getMaxMemoryMB()
TwillContextgetMaxMemoryMB in interface TwillContextpublic Cancellable announce(String serviceName, int port)
ServiceAnnouncerannounce in interface ServiceAnnouncerserviceName - Name of the endpointport - Port of the endpointpublic Cancellable announce(String serviceName, int port, byte[] payload)
ServiceAnnouncerannounce in interface ServiceAnnouncerserviceName - Name of the endpointport - Port of the endpointpayload - byte array payloadpublic ServiceDiscovered discover(String name)
TwillContextTwillApplication.discover in interface TwillContextdiscover in interface DiscoveryServiceClientname - Name of the serviceServiceDiscovered object representing the result.public Cancellable electLeader(String name, ElectionHandler participantHandler)
TwillContextTwillApplication.electLeader in interface TwillContextname - Unique name for the electionCancellable object representing this candidate's participation.public Lock createLock(String name)
TwillContextLock for performing locking mechanism within the same TwillApplication.
The lock created is a reentrant such that if the lock is owned by the current thread, it will return immediately.createLock in interface TwillContextname - Unique name for the lockLock objectpublic void stop()
Copyright © 2013-2020 The Apache Software Foundation. All rights reserved.