refactoring
parent
369e30640c
commit
b5f2827413
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright 2016 Nikita Koksharov
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.redisson;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.redisson.api.RFuture;
|
||||
import org.redisson.command.CommandAsyncExecutor;
|
||||
|
||||
import io.netty.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <R> result type
|
||||
*/
|
||||
public abstract class MapWriterExecutorPromise<R> extends MapWriterPromise<R> {
|
||||
|
||||
public MapWriterExecutorPromise(RFuture<R> f, CommandAsyncExecutor commandExecutor) {
|
||||
super(f, commandExecutor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final Future<R> future, ExecutorService executorService) {
|
||||
if (condition(future)) {
|
||||
executorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
executeWriter();
|
||||
} catch (Exception e) {
|
||||
tryFailure(e);
|
||||
return;
|
||||
}
|
||||
trySuccess(future.getNow());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
trySuccess(future.getNow());
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean condition(Future<R> future) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void executeWriter();
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright 2016 Nikita Koksharov
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.redisson;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import org.redisson.api.RFuture;
|
||||
import org.redisson.command.CommandAsyncExecutor;
|
||||
import org.redisson.misc.RedissonPromise;
|
||||
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.FutureListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
* @param <R> result type
|
||||
*/
|
||||
public abstract class MapWriterPromise<R> extends RedissonPromise<R> {
|
||||
|
||||
public MapWriterPromise(RFuture<R> f, final CommandAsyncExecutor commandExecutor) {
|
||||
super();
|
||||
f.addListener(new FutureListener<R>() {
|
||||
@Override
|
||||
public void operationComplete(Future<R> future) throws Exception {
|
||||
if (!future.isSuccess()) {
|
||||
tryFailure(future.cause());
|
||||
return;
|
||||
}
|
||||
|
||||
execute(future, commandExecutor.getConnectionManager().getExecutor());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public abstract void execute(Future<R> future, ExecutorService executorService);
|
||||
|
||||
}
|
Loading…
Reference in New Issue