org.apache.oozie.service
Class ZKLocksService

java.lang.Object
  extended by org.apache.oozie.service.MemoryLocksService
      extended by org.apache.oozie.service.ZKLocksService
All Implemented Interfaces:
Service, Instrumentable

public class ZKLocksService
extends MemoryLocksService
implements Service, Instrumentable

Service that provides distributed locks via ZooKeeper. Requires that a ZooKeeper ensemble is available. The locks will be located under a ZNode named "locks" under the namespace (see ZKUtils). For example, with default settings, if the resource we're locking is called "foo", then the ZNode backing the lock will be at /oozie/locks/foo.


Field Summary
static int DEFAULT_REAPING_THRESHOLD
           
static String LOCKS_NODE
           
static String REAPING_THREADS
           
static String REAPING_THRESHOLD
           
 
Fields inherited from class org.apache.oozie.service.MemoryLocksService
INSTRUMENTATION_GROUP
 
Fields inherited from interface org.apache.oozie.service.Service
CONF_PREFIX, DEFAULT_LOCK_TIMEOUT, lockTimeout, USE_XCOMMAND
 
Constructor Summary
ZKLocksService()
           
 
Method Summary
 void destroy()
          Destroy the zookeeper locks service.
 HashMap<String,org.apache.curator.framework.recipes.locks.InterProcessReadWriteLock> getLocks()
           
 LockToken getReadLock(String resource, long wait)
          Obtain a READ lock for a source.
 LockToken getWriteLock(String resource, long wait)
          Obtain a WRITE lock for a source.
 void init(Services services)
          Initialize the zookeeper locks service
 void instrument(Instrumentation instr)
          Instruments the zookeeper locks service.
 
Methods inherited from class org.apache.oozie.service.MemoryLocksService
getInterface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.oozie.service.Service
getInterface
 

Field Detail

LOCKS_NODE

public static final String LOCKS_NODE
See Also:
Constant Field Values

DEFAULT_REAPING_THRESHOLD

public static final int DEFAULT_REAPING_THRESHOLD
See Also:
Constant Field Values

REAPING_THRESHOLD

public static final String REAPING_THRESHOLD
See Also:
Constant Field Values

REAPING_THREADS

public static final String REAPING_THREADS
See Also:
Constant Field Values
Constructor Detail

ZKLocksService

public ZKLocksService()
Method Detail

init

public void init(Services services)
          throws ServiceException
Initialize the zookeeper locks service

Specified by:
init in interface Service
Overrides:
init in class MemoryLocksService
Parameters:
services - services instance.
Throws:
ServiceException - thrown if the service could not initialize.

destroy

public void destroy()
Destroy the zookeeper locks service.

Specified by:
destroy in interface Service
Overrides:
destroy in class MemoryLocksService

instrument

public void instrument(Instrumentation instr)
Instruments the zookeeper locks service.

Specified by:
instrument in interface Instrumentable
Overrides:
instrument in class MemoryLocksService
Parameters:
instr - instance to instrument the memory locks service to.

getReadLock

public LockToken getReadLock(String resource,
                             long wait)
                      throws InterruptedException
Obtain a READ lock for a source.

Overrides:
getReadLock in class MemoryLocksService
Parameters:
resource - resource name.
wait - time out in milliseconds to wait for the lock, -1 means no timeout and 0 no wait.
Returns:
the lock token for the resource, or null if the lock could not be obtained.
Throws:
InterruptedException - thrown if the thread was interrupted while waiting.

getWriteLock

public LockToken getWriteLock(String resource,
                              long wait)
                       throws InterruptedException
Obtain a WRITE lock for a source.

Overrides:
getWriteLock in class MemoryLocksService
Parameters:
resource - resource name.
wait - time out in milliseconds to wait for the lock, -1 means no timeout and 0 no wait.
Returns:
the lock token for the resource, or null if the lock could not be obtained.
Throws:
InterruptedException - thrown if the thread was interrupted while waiting.

getLocks

public HashMap<String,org.apache.curator.framework.recipes.locks.InterProcessReadWriteLock> getLocks()


Copyright © 2015 Apache Software Foundation. All Rights Reserved.