本文整理汇总了Java中org.apache.curator.framework.recipes.locks.Reaper类的典型用法代码示例。如果您正苦于以下问题:Java Reaper类的具体用法?Java Reaper怎么用?Java Reaper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Reaper类属于org.apache.curator.framework.recipes.locks包,在下文中一共展示了Reaper类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: ChildReaper
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
/**
* @param client the client
* @param path path to reap children from
* @param executor executor to use for background tasks
* @param reapingThresholdMs threshold in milliseconds that determines that a path can be deleted
* @param mode reaping mode
* @param leaderPath if not null, uses a leader selection so that only 1 reaper is active in the cluster
*/
public ChildReaper(CuratorFramework client, String path, Reaper.Mode mode, ScheduledExecutorService executor, int reapingThresholdMs, String leaderPath)
{
this.client = client;
this.mode = mode;
this.executor = new CloseableScheduledExecutorService(executor);
this.reapingThresholdMs = reapingThresholdMs;
this.reaper = new Reaper(client, executor, reapingThresholdMs, leaderPath);
addPath(path);
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:18,代码来源:ChildReaper.java
示例2: testSomeNodes
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void testSomeNodes() throws Exception
{
Timing timing = new Timing();
ChildReaper reaper = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try
{
client.start();
Random r = new Random();
int nonEmptyNodes = 0;
for ( int i = 0; i < 10; ++i )
{
client.create().creatingParentsIfNeeded().forPath("/test/" + Integer.toString(i));
if ( r.nextBoolean() )
{
client.create().forPath("/test/" + Integer.toString(i) + "/foo");
++nonEmptyNodes;
}
}
reaper = new ChildReaper(client, "/test", Reaper.Mode.REAP_UNTIL_DELETE, 1);
reaper.start();
timing.forWaiting().sleepABit();
Stat stat = client.checkExists().forPath("/test");
Assert.assertEquals(stat.getNumChildren(), nonEmptyNodes);
}
finally
{
CloseableUtils.closeQuietly(reaper);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:38,代码来源:TestChildReaper.java
示例3: testSimple
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void testSimple() throws Exception
{
Timing timing = new Timing();
ChildReaper reaper = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try
{
client.start();
for ( int i = 0; i < 10; ++i )
{
client.create().creatingParentsIfNeeded().forPath("/test/" + Integer.toString(i));
}
reaper = new ChildReaper(client, "/test", Reaper.Mode.REAP_UNTIL_DELETE, 1);
reaper.start();
timing.forWaiting().sleepABit();
Stat stat = client.checkExists().forPath("/test");
Assert.assertEquals(stat.getNumChildren(), 0);
}
finally
{
CloseableUtils.closeQuietly(reaper);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:30,代码来源:TestChildReaper.java
示例4: testMultiPath
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void testMultiPath() throws Exception
{
Timing timing = new Timing();
ChildReaper reaper = null;
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
try
{
client.start();
for ( int i = 0; i < 10; ++i )
{
client.create().creatingParentsIfNeeded().forPath("/test1/" + Integer.toString(i));
client.create().creatingParentsIfNeeded().forPath("/test2/" + Integer.toString(i));
client.create().creatingParentsIfNeeded().forPath("/test3/" + Integer.toString(i));
}
reaper = new ChildReaper(client, "/test2", Reaper.Mode.REAP_UNTIL_DELETE, 1);
reaper.start();
reaper.addPath("/test1");
timing.forWaiting().sleepABit();
Stat stat = client.checkExists().forPath("/test1");
Assert.assertEquals(stat.getNumChildren(), 0);
stat = client.checkExists().forPath("/test2");
Assert.assertEquals(stat.getNumChildren(), 0);
stat = client.checkExists().forPath("/test3");
Assert.assertEquals(stat.getNumChildren(), 10);
}
finally
{
CloseableUtils.closeQuietly(reaper);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:37,代码来源:TestChildReaper.java
示例5: testNamespace
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void testNamespace() throws Exception
{
Timing timing = new Timing();
ChildReaper reaper = null;
CuratorFramework client = CuratorFrameworkFactory.builder()
.connectString(server.getConnectString())
.sessionTimeoutMs(timing.session())
.connectionTimeoutMs(timing.connection())
.retryPolicy(new RetryOneTime(1))
.namespace("foo")
.build();
try
{
client.start();
for ( int i = 0; i < 10; ++i )
{
client.create().creatingParentsIfNeeded().forPath("/test/" + Integer.toString(i));
}
reaper = new ChildReaper(client, "/test", Reaper.Mode.REAP_UNTIL_DELETE, 1);
reaper.start();
timing.forWaiting().sleepABit();
Stat stat = client.checkExists().forPath("/test");
Assert.assertEquals(stat.getNumChildren(), 0);
stat = client.usingNamespace(null).checkExists().forPath("/foo/test");
Assert.assertNotNull(stat);
Assert.assertEquals(stat.getNumChildren(), 0);
}
finally
{
CloseableUtils.closeQuietly(reaper);
CloseableUtils.closeQuietly(client);
}
}
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:40,代码来源:TestChildReaper.java
示例6: init
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@PostConstruct
public void init()
{
taskRunnerExecutor = new ExecutorCompletionService<TaskResult>(createTaskExecutor());
priorityTaskRunnerExecutor = new ExecutorCompletionService<TaskResult>(createPriorityTaskExecutor());
Version version = ApplicationVersion.get();
String prefix;
if( version.isDevelopment() )
{
prefix = "tasksdev/";
}
else
{
prefix = "tasks-" + version.getMmr() + '/';
}
ZK_TASKPATH = prefix + ZK_TASKPATH;
ZK_GLOBALTASKPATH = prefix + ZK_GLOBALTASKPATH;
ZK_TASKOWNERPATH = prefix + ZK_TASKOWNERPATH;
globalCache = zookeeperService.createPathCache(ZK_GLOBALTASKPATH, true);
taskCache = zookeeperService.createPathCache(ZK_TASKPATH, false, this, StartMode.POST_INITIALIZED_EVENT);
curator = zookeeperService.getCurator();
ourNodeId = zookeeperService.getNodeId();
final Reaper reaper = new Reaper(curator, 10000);
try
{
reaper.start();
}
catch( Exception e1 )
{
Throwables.propagate(e1);
}
new TaskWatchThread("Task Finisher listener", taskRunnerExecutor, reaper).start();
new TaskWatchThread("Priority Task Finisher listener", priorityTaskRunnerExecutor, reaper).start();
}
开发者ID:equella,项目名称:Equella,代码行数:37,代码来源:ClusteredTaskServiceImpl.java
示例7: close
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
public void close(Reaper reaper)
{
if( lockPath != null )
{
try
{
curator.delete().forPath(lockPath);
}
catch( Exception e )
{
reaper.addPath(lockPath);
}
}
}
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:ClusteredTaskServiceImpl.java
示例8: createInjector_WithFrameworkAndExecutorProvidedAndBound_BindsReaper
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void createInjector_WithFrameworkAndExecutorProvidedAndBound_BindsReaper() {
Injector inj = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(ScheduledExecutorService.class).toInstance(executorService);
bind(CuratorFramework.class).annotatedWith(Curator.class).toInstance(framework);
}
}, ReaperModuleBuilder.create().exectuor(Key.get(ScheduledExecutorService.class)).build());
inj.getInstance(Key.get(Reaper.class, Curator.class));
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:15,代码来源:ReaperModuleBuilderTest.java
示例9: createInjector_WithFrameworkAndNoExecutorProvided_BindsReaper
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void createInjector_WithFrameworkAndNoExecutorProvided_BindsReaper() {
Injector inj = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(CuratorFramework.class).annotatedWith(Curator.class).toInstance(framework);
}
}, ReaperModuleBuilder.create().leaderPath("/reaperleader").build());
inj.getInstance(Key.get(Reaper.class, Curator.class));
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:14,代码来源:ReaperModuleBuilderTest.java
示例10: TaskWatchThread
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
public TaskWatchThread(String name, CompletionService<TaskResult> executor, Reaper reaper)
{
this.name = name;
this.executor = executor;
this.reaper = reaper;
}
开发者ID:equella,项目名称:Equella,代码行数:7,代码来源:ClusteredTaskServiceImpl.java
示例11: build
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Override
public Module build() {
checkState(lockPath != null, "Lock path must be provided.");
checkState(mode != null, "Reaper mode must be provided.");
return new AbstractModule() {
@Override
protected void configure() {
if (getService() != null) {
requireBinding(getService());
}
final Key<ChildReaperManager> managerKey = holder.generateKey(ChildReaperManager.class);
install(new PrivateModule() {
@Override
protected void configure() {
if (getService() != null) {
bind(ScheduledExecutorService.class).annotatedWith(Private.class).to(getService());
} else {
bind(ScheduledExecutorService.class).annotatedWith(Private.class).toInstance(
Reaper.newExecutorService());
}
Key<ChildReaper> reaperKey = holder.generateKey(ChildReaper.class);
bind(reaperKey).to(Key.get(ChildReaper.class, Private.class)).in(Singleton.class);
expose(reaperKey);
bind(managerKey).to(ChildReaperManager.class).in(Singleton.class);
expose(managerKey);
}
@Provides
@Private
public ChildReaper childReaper(@Curator final CuratorFramework framework,
@Private final ScheduledExecutorService executorService) {
if (getLeaderPath() != null) {
return new ChildReaper(framework, lockPath, mode, executorService,
getReapingThresholdMillis(), getLeaderPath());
} else {
return new ChildReaper(framework, lockPath, mode, executorService,
getReapingThresholdMillis());
}
}
});
Multibinder<CuratorService> serviceMultibinder = Multibinder.newSetBinder(binder(),
CuratorService.class);
serviceMultibinder.addBinding().to(managerKey);
}
};
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:58,代码来源:ChildReaperModuleBuilder.java
示例12: ReaperManager
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Inject
ReaperManager(@Private final Reaper reaper) {
this.reaper = reaper;
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:5,代码来源:ReaperManager.java
示例13: build
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Override
public Module build() {
return new AbstractModule() {
@Override
protected void configure() {
if (getService() != null) {
requireBinding(getService());
}
final Key<ReaperManager> managerKey = holder.generateKey(ReaperManager.class);
install(new PrivateModule() {
@Override
protected void configure() {
if (getService() != null) {
bind(ScheduledExecutorService.class).annotatedWith(Private.class).to(getService());
} else {
bind(ScheduledExecutorService.class).annotatedWith(Private.class).toInstance(
Reaper.newExecutorService());
}
Key<Reaper> reaperKey = holder.generateKey(Reaper.class);
bind(reaperKey).to(Key.get(Reaper.class, Private.class)).in(Singleton.class);
expose(reaperKey);
bind(managerKey).to(ReaperManager.class).in(Singleton.class);
expose(managerKey);
}
@Provides
@Private
public Reaper reaper(@Curator final CuratorFramework framework,
@Private final ScheduledExecutorService executorService) {
if (getLeaderPath() != null) {
return new Reaper(framework, executorService, getReapingThresholdMillis(), getLeaderPath());
} else {
return new Reaper(framework, executorService, getReapingThresholdMillis());
}
}
});
Multibinder<CuratorService> serviceMultibinder = Multibinder.newSetBinder(binder(),
CuratorService.class);
serviceMultibinder.addBinding().to(managerKey);
}
};
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:53,代码来源:ReaperModuleBuilder.java
示例14: reaperMode_Valid_ReturnsSelf
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void reaperMode_Valid_ReturnsSelf() {
assertEquals(builder, builder.reaperMode(Reaper.Mode.REAP_INDEFINITELY));
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:5,代码来源:ChildReaperModuleBuilderTest.java
示例15: build_NoLockPath_ThrowsISE
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void build_NoLockPath_ThrowsISE() {
thrown.expect(IllegalStateException.class);
builder.reaperMode(Reaper.Mode.REAP_INDEFINITELY).build();
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:7,代码来源:ChildReaperModuleBuilderTest.java
示例16: build_LockAndPathProvided_ReturnsNotNull
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Test
public void build_LockAndPathProvided_ReturnsNotNull() {
assertNotNull(builder.reaperMode(Reaper.Mode.REAP_INDEFINITELY).lockPath("/path").build());
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:6,代码来源:ChildReaperModuleBuilderTest.java
示例17: setUp
import org.apache.curator.framework.recipes.locks.Reaper; //导入依赖的package包/类
@Before
public void setUp() {
builder = ChildReaperModuleBuilder.create().lockPath("/path").reaperMode(Reaper.Mode.REAP_INDEFINITELY);
}
开发者ID:dclements,项目名称:cultivar_old,代码行数:5,代码来源:ChildReaperModuleBuilderTest.java
注:本文中的org.apache.curator.framework.recipes.locks.Reaper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论