本文整理匯總了Java中com.google.common.util.concurrent.MoreExecutors.directExecutor方法的典型用法代碼示例。如果您正苦於以下問題:Java MoreExecutors.directExecutor方法的具體用法?Java MoreExecutors.directExecutor怎麽用?Java MoreExecutors.directExecutor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.util.concurrent.MoreExecutors
的用法示例。
在下文中一共展示了MoreExecutors.directExecutor方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: activate
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
@Activate
public void activate(ComponentContext context) {
configService.registerProperties(getClass());
setupCodecs();
messageReceivingExecutor = receiveOnIOLoopThread
? MoreExecutors.directExecutor()
: Executors.newFixedThreadPool(
totalReceiverThreads,
groupedThreads("onos/net-perf-test", "receiver-%d"));
registerMessageHandlers();
startTest();
reporter.scheduleWithFixedDelay(this::reportPerformance,
reportIntervalSeconds,
reportIntervalSeconds,
TimeUnit.SECONDS);
logConfig("Started");
}
示例2: from
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
/**
* Wraps listenable future with a fluent future.
* @param <V> value type
* @param future future
* @return fluent instance
*/
public static <V> FluentFuture<V> from(ListenableFuture<V> future) {
if (future instanceof FluentFuture<?>) {
return (FluentFuture<V>) future;
}
return new WrapingFluentFuture<>(future, MoreExecutors.directExecutor());
}
示例3: EventBus
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
/**
* Creates a new EventBus with the given {@code identifier}.
*
* @param identifier a brief name for this bus, for logging purposes. Should be a valid Java
* identifier.
*/
public EventBus(String identifier) {
this(
identifier,
MoreExecutors.directExecutor(),
Dispatcher.perThreadDispatchQueue(),
LoggingHandler.INSTANCE);
}
示例4: wrapExecutor
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
/**
* returns an Executor that will either execute the command given the Executor delegate or
* call the callback.onFailure if it receives a (Es)RejectedExecutionException
*/
public static Executor wrapExecutor(Executor delegate, FutureCallback<?> callback) {
if (delegate == MoreExecutors.directExecutor()) {
// directExecutor won't reject anything...
return delegate;
}
return new RejectionAwareExecutor(delegate, callback);
}
示例5: testChainedTransactionFailureWithSingleShard
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception {
initDatastoresWithCars("testChainedTransactionFailureWithSingleShard");
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(
LogicalDatastoreType.CONFIGURATION, followerDistributedDataStore).build(),
MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
try {
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (final TransactionCommitFailedException e) {
// Expected
}
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
txChain.close();
broker.close();
}
示例6: testChainedTransactionFailureWithMultipleShards
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testChainedTransactionFailureWithMultipleShards");
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(
LogicalDatastoreType.CONFIGURATION, followerDistributedDataStore).build(),
MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
// Note that merge will validate the data and fail but put succeeds b/c deep validation is not
// done for put for performance reasons.
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
try {
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (final TransactionCommitFailedException e) {
// Expected
}
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
txChain.close();
broker.close();
}
示例7: executor
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
@Provides
@Production
static Executor executor() {
return MoreExecutors.directExecutor();
}
示例8: testCreateChainedTransactionsInQuickSuccession
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
@Test
public void testCreateChainedTransactionsInQuickSuccession() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
DOMTransactionChain txChain = broker.createTransactionChain(listener);
final List<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
final DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
futures.add(writeTx.submit());
int numCars = 100;
for (int i = 0; i < numCars; i++) {
final DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i),
CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));
futures.add(rwTx.submit());
}
for (final CheckedFuture<Void, TransactionCommitFailedException> f : futures) {
f.checkedGet();
}
final Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
.read(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("# cars", numCars, ((Collection<?>) optional.get().getValue()).size());
txChain.close();
broker.close();
}
}
};
}
示例9: testChainedTransactionFailureWithSingleShard
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testChainedTransactionFailureWithSingleShard", "cars-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataReadWriteTransaction writeTx = txChain.newReadWriteTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH,
PeopleModel.emptyContainer());
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
try {
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (final TransactionCommitFailedException e) {
// Expected
}
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx),
any(Throwable.class));
txChain.close();
broker.close();
}
}
};
}
示例10: testChainedTransactionFailureWithMultipleShards
import com.google.common.util.concurrent.MoreExecutors; //導入方法依賴的package包/類
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(
testParameter, "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
.put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataReadWriteTransaction writeTx = txChain.newReadWriteTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH,
PeopleModel.emptyContainer());
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
.withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
// Note that merge will validate the data and fail but put
// succeeds b/c deep validation is not
// done for put for performance reasons.
try {
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (final TransactionCommitFailedException e) {
// Expected
}
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx),
any(Throwable.class));
txChain.close();
broker.close();
}
}
};
}