import java.util.Collection;
import java.util.Collections;
-
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public abstract class AbstractConsumer implements Consumer, BundleActivator,ServiceTrackerCustomizer<Broker, Broker> {
-
-
-
private BundleContext context;
private ServiceTracker<Broker, Broker> tracker;
private Broker broker;
@Override
- public final void start(BundleContext context) throws Exception {
+ public final void start(final BundleContext context) throws Exception {
this.context = context;
this.startImpl(context);
tracker = new ServiceTracker<>(context, Broker.class, this);
@Override
- public final void stop(BundleContext context) throws Exception {
+ public final void stop(final BundleContext context) throws Exception {
stopImpl(context);
broker = null;
tracker.close();
}
- protected void startImpl(BundleContext context) {
+ protected void startImpl(final BundleContext context) {
// NOOP
}
- protected void stopImpl(BundleContext context) {
+ protected void stopImpl(final BundleContext context) {
// NOOP
}
@Override
- public Broker addingService(ServiceReference<Broker> reference) {
+ public Broker addingService(final ServiceReference<Broker> reference) {
if(broker == null) {
broker = context.getService(reference);
broker.registerConsumer(this, context);
}
@Override
- public void modifiedService(ServiceReference<Broker> reference, Broker service) {
+ public void modifiedService(final ServiceReference<Broker> reference, final Broker service) {
// NOOP
}
@Override
- public void removedService(ServiceReference<Broker> reference, Broker service) {
+ public void removedService(final ServiceReference<Broker> reference, final Broker service) {
stopImpl(context);
}
}
import java.util.Collection;
import java.util.Collections;
-
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
private Broker broker;
private BundleContext context;
private ServiceTracker<Broker, Broker> tracker;
+
@Override
public Collection<ProviderFunctionality> getProviderFunctionality() {
return Collections.emptySet();
}
@Override
- public final void start(BundleContext context) throws Exception {
+ public final void start(final BundleContext context) throws Exception {
this.context = context;
this.startImpl(context);
tracker = new ServiceTracker<>(context, Broker.class, this);
tracker.open();
}
- protected void startImpl(BundleContext context) {
+ protected void startImpl(final BundleContext context) {
// NOOP
}
- protected void stopImpl(BundleContext context) {
+ protected void stopImpl(final BundleContext context) {
// NOOP
}
@Override
- public final void stop(BundleContext context) throws Exception {
+ public final void stop(final BundleContext context) throws Exception {
broker = null;
tracker.close();
tracker = null;
}
@Override
- public Broker addingService(ServiceReference<Broker> reference) {
+ public Broker addingService(final ServiceReference<Broker> reference) {
if(broker == null) {
broker = context.getService(reference);
broker.registerProvider(this, context);
}
@Override
- public void modifiedService(ServiceReference<Broker> reference, Broker service) {
+ public void modifiedService(final ServiceReference<Broker> reference, final Broker service) {
// NOOP
}
@Override
- public void removedService(ServiceReference<Broker> reference, Broker service) {
+ public void removedService(final ServiceReference<Broker> reference, final Broker service) {
stopImpl(context);
}
canCommit,
preCommit,
doCommit,
- };
+ }
private static final Logger LOG = LoggerFactory.getLogger(CommitCoordinationTask.class);
private final Collection<DOMStoreThreePhaseCommitCohort> cohorts;
LOG.debug("Transaction {}: doCommit completed", tx.getIdentifier());
return null;
- } catch (TransactionCommitFailedException e) {
+ } catch (final TransactionCommitFailedException e) {
LOG.warn("Tx: {} Error during phase {}, starting Abort", tx.getIdentifier(), phase, e);
abortBlocking(e);
throw e;
*
*/
private void canCommitBlocking() throws TransactionCommitFailedException {
- for (ListenableFuture<?> canCommit : canCommitAll()) {
+ for (final ListenableFuture<?> canCommit : canCommitAll()) {
try {
final Boolean result = (Boolean)canCommit.get();
if (result == null || !result) {
private ListenableFuture<?>[] canCommitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
int i = 0;
- for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
+ for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
ops[i++] = cohort.canCommit();
}
return ops;
private void preCommitBlocking() throws TransactionCommitFailedException {
final ListenableFuture<?>[] preCommitFutures = preCommitAll();
try {
- for(ListenableFuture<?> future : preCommitFutures) {
+ for(final ListenableFuture<?> future : preCommitFutures) {
future.get();
}
} catch (InterruptedException | ExecutionException e) {
private ListenableFuture<?>[] preCommitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
int i = 0;
- for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
+ for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
ops[i++] = cohort.preCommit();
}
return ops;
private void commitBlocking() throws TransactionCommitFailedException {
final ListenableFuture<?>[] commitFutures = commitAll();
try {
- for(ListenableFuture<?> future : commitFutures) {
+ for(final ListenableFuture<?> future : commitFutures) {
future.get();
}
} catch (InterruptedException | ExecutionException e) {
private ListenableFuture<?>[] commitAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
int i = 0;
- for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
+ for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
ops[i++] = cohort.commit();
}
return ops;
* @return Future which will complete once all cohorts completed
* abort.
*/
+ @SuppressWarnings({"unchecked", "rawtypes"})
private ListenableFuture<Void> abortAsyncAll() {
final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
int i = 0;
- for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
+ for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
ops[i++] = cohort.abort();
}
* order to fail composite future if any of them failed.
* See Futures.allAsList for this description.
*/
- @SuppressWarnings({ "unchecked", "rawtypes" })
- ListenableFuture<Void> compositeResult = (ListenableFuture) Futures.allAsList(ops);
- return compositeResult;
+ return (ListenableFuture) Futures.allAsList(ops);
}
}
*
* @param delegate Backend broker, may not be null.
*/
- public PingPongDataBroker(final @Nonnull DOMDataBroker delegate) {
+ public PingPongDataBroker(@Nonnull final DOMDataBroker delegate) {
this.delegate = Preconditions.checkNotNull(delegate);
}
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
/**
- * A {@link Future} used to report the status of an future {@link java.util.concurrent.Future}.
+ * A {@link java.util.concurrent.Future} used to report the status of an future
+ * {@link java.util.concurrent.Future}.
*/
final class PingPongFuture extends AbstractCheckedFuture<Void, TransactionCommitFailedException> {
protected PingPongFuture(final ListenableFuture<Void> delegate) {
if (e.getCause() instanceof TransactionCommitFailedException){
return (TransactionCommitFailedException) e.getCause();
} else {
- return new TransactionCommitFailedException(e.getMessage(), e.getCause(), null);
+ return new TransactionCommitFailedException(e.getMessage(), e.getCause());
}
}
}
* @param tx Transaction which needs processing.
*/
@GuardedBy("this")
- private void processTransaction(final @Nonnull PingPongTransaction tx) {
+ private void processTransaction(@Nonnull final PingPongTransaction tx) {
if (failed) {
LOG.debug("Cancelling transaction {}", tx);
tx.getTransaction().cancel();
tx.onFailure(t);
}
- private void readyTransaction(final @Nonnull PingPongTransaction tx) {
+ private void readyTransaction(@Nonnull final PingPongTransaction tx) {
// First mark the transaction as not locked.
final boolean lockedMatch = LOCKED_UPDATER.compareAndSet(this, tx, null);
Preconditions.checkState(lockedMatch, "Attempted to submit transaction %s while we have %s", tx, lockedTx);
for (final DOMDataTreeIdentifier s : producer.getSubtrees()) {
final DOMDataTreeProducer r = idToProducer.remove(s);
if (!producer.equals(r)) {
- LOG.error("Removed producer %s on subtree %s while removing %s", r, s, producer);
+ LOG.error("Removed producer {} on subtree {} while removing {}", r, s, producer);
}
}
}
private DOMDataTreeProducer createProducer(final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap) {
// Record the producer's attachment points
final DOMDataTreeProducer ret = ShardedDOMDataTreeProducer.create(this, shardMap);
- for (final DOMDataTreeIdentifier s : shardMap.keySet()) {
+ for (DOMDataTreeIdentifier s : shardMap.keySet()) {
idToProducer.put(s, ret);
}
final Builder<DOMDataTreeShard, DOMStoreTransactionChain> cb = ImmutableBiMap.builder();
final Queue<Exception> es = new LinkedList<>();
- for (DOMDataTreeShard s : shards) {
+ for (final DOMDataTreeShard s : shards) {
if (s instanceof DOMStore) {
try {
final DOMStoreTransactionChain c = ((DOMStore)s).createTransactionChain();
LOG.trace("Using DOMStore chain {} to access shard {}", c, s);
cb.put(s, c);
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Failed to instantiate chain for shard {}", s, e);
es.add(e);
}
// An error was encountered, close chains and report the error
if (shardToChain.size() != shards.size()) {
- for (DOMStoreTransactionChain c : shardToChain.values()) {
+ for (final DOMStoreTransactionChain c : shardToChain.values()) {
try {
c.close();
- } catch (Exception e) {
- LOG.warn("Exception raised while closing chain %s", c, e);
+ } catch (final Exception e) {
+ LOG.warn("Exception raised while closing chain {}", c, e);
}
}
// Allocate backing transactions
final Map<DOMDataTreeShard, DOMStoreWriteTransaction> shardToTx = new HashMap<>();
- for (Entry<DOMDataTreeShard, DOMStoreTransactionChain> e : shardToChain.entrySet()) {
+ for (final Entry<DOMDataTreeShard, DOMStoreTransactionChain> e : shardToChain.entrySet()) {
shardToTx.put(e.getKey(), e.getValue().newWriteOnlyTransaction());
}
// Create the ID->transaction map
final ImmutableMap.Builder<DOMDataTreeIdentifier, DOMStoreWriteTransaction> b = ImmutableMap.builder();
- for (Entry<DOMDataTreeIdentifier, DOMDataTreeShard> e : idToShard.entrySet()) {
+ for (final Entry<DOMDataTreeIdentifier, DOMDataTreeShard> e : idToShard.entrySet()) {
b.put(e.getKey(), shardToTx.get(e.getValue()));
}
@GuardedBy("this")
private boolean haveSubtree(final DOMDataTreeIdentifier subtree) {
- for (DOMDataTreeIdentifier i : idToShard.keySet()) {
+ for (final DOMDataTreeIdentifier i : idToShard.keySet()) {
if (i.contains(subtree)) {
return true;
}
@GuardedBy("this")
private DOMDataTreeProducer lookupChild(final DOMDataTreeIdentifier s) {
- for (Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : children.entrySet()) {
+ for (final Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : children.entrySet()) {
if (e.getKey().contains(s)) {
return e.getValue();
}
Preconditions.checkState(!closed, "Producer is already closed");
Preconditions.checkState(openTx == null, "Transaction %s is still open", openTx);
- for (DOMDataTreeIdentifier s : subtrees) {
+ for (final DOMDataTreeIdentifier s : subtrees) {
// Check if the subtree was visible at any time
if (!haveSubtree(s)) {
throw new IllegalArgumentException(String.format("Subtree %s was never available in producer %s", s, this));
Preconditions.checkArgument(child == null, "Subtree %s is delegated to child producer %s", s, child);
// Check if part of the requested subtree is not delegated to a child.
- for (DOMDataTreeIdentifier c : children.keySet()) {
+ for (final DOMDataTreeIdentifier c : children.keySet()) {
if (s.contains(c)) {
throw new IllegalArgumentException(String.format("Subtree %s cannot be delegated as it is superset of already-delegated %s", s, c));
}
final DOMDataTreeProducer ret = dataTree.createProducer(this, subtrees);
final ImmutableMap.Builder<DOMDataTreeIdentifier, DOMDataTreeProducer> cb = ImmutableMap.builder();
cb.putAll(children);
- for (DOMDataTreeIdentifier s : subtrees) {
+ for (final DOMDataTreeIdentifier s : subtrees) {
cb.put(s, ret);
}
super( opName, TransactionCommitFailedException.class );
}
- public static final TransactionCommitFailedExceptionMapper create(final String opName) {
+ public static TransactionCommitFailedExceptionMapper create(final String opName) {
return new TransactionCommitFailedExceptionMapper(opName);
}
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.CheckedFuture;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
public class BrokerImpl implements Broker, DOMRpcProviderService, DOMRpcService, AutoCloseable {
private final static Logger log = LoggerFactory.getLogger(BrokerImpl.class);
// Validation
private void checkPredicates(final Provider prov) {
Preconditions.checkNotNull(prov, "Provider should not be null.");
- for (ProviderContextImpl session : providerSessions) {
+ for (final ProviderContextImpl session : providerSessions) {
if (prov.equals(session.getProvider())) {
throw new IllegalStateException("Provider already registered");
}
private void checkPredicates(final Consumer cons) {
Preconditions.checkNotNull(cons, "Consumer should not be null.");
- for (ConsumerContextImpl session : sessions) {
+ for (final ConsumerContextImpl session : sessions) {
if (cons.equals(session.getConsumer())) {
throw new IllegalStateException("Consumer already registered");
}
// Private Factory methods
private ConsumerContextImpl newSessionFor(final Consumer provider) {
- ConsumerContextImpl ret = new ConsumerContextImpl(provider, this);
+ final ConsumerContextImpl ret = new ConsumerContextImpl(provider, this);
return ret;
}
private ProviderContextImpl newSessionFor(final Provider provider) {
- ProviderContextImpl ret = new ProviderContextImpl(provider, this);
+ final ProviderContextImpl ret = new ProviderContextImpl(provider, this);
return ret;
}
@Override
- public ConsumerSession registerConsumer(Consumer consumer) {
+ public ConsumerSession registerConsumer(final Consumer consumer) {
checkPredicates(consumer);
log.trace("Registering consumer {}", consumer);
final ConsumerContextImpl session = newSessionFor(consumer);
@Override
- public ProviderSession registerProvider(Provider provider) {
+ public ProviderSession registerProvider(final Provider provider) {
checkPredicates(provider);
final ProviderContextImpl session = newSessionFor(provider);
provider.onSessionInitiated(session);
public class SchemaContextProviders {
+ private SchemaContextProviders() {
+ throw new UnsupportedOperationException("Utility class.");
+ }
+
public static final SchemaContextProvider fromSchemaService(final SchemaService schemaService) {
if (schemaService instanceof SchemaContextProvider) {
return (SchemaContextProvider) schemaService;
return new SchemaServiceAdapter(schemaService);
}
- private final static class SchemaServiceAdapter implements SchemaContextProvider, Delegator<SchemaService> {
+ private static final class SchemaServiceAdapter implements SchemaContextProvider, Delegator<SchemaService> {
private final SchemaService service;
return ((T) _createProxyImpl);
}
- private static Object _createProxyImpl(final ServiceReference<?> ref,
+ private static Object createProxyImpl(final ServiceReference<?> ref,
final DOMMountPointService service) {
return new DOMMountPointServiceProxy(
((ServiceReference<DOMMountPointService>) ref), service);
}
- private static Object _createProxyImpl(final ServiceReference<?> ref,
+ private static Object createProxyImpl(final ServiceReference<?> ref,
final SchemaService service) {
return new SchemaServiceProxy(((ServiceReference<SchemaService>) ref),
service);
}
- private static DOMDataBrokerProxy _createProxyImpl(
+ private static DOMDataBrokerProxy createProxyImpl(
final ServiceReference<?> ref, final DOMDataBroker service) {
return new DOMDataBrokerProxy(((ServiceReference<DOMDataBroker>) ref),
service);
}
- private static Object _createProxyImpl(final ServiceReference<?> reference,
+ private static Object createProxyImplFallback(final ServiceReference<?> reference,
final BrokerService service) {
return service;
final BrokerService service) {
if (service instanceof DOMDataBroker) {
- return _createProxyImpl(ref, (DOMDataBroker) service);
+ return createProxyImpl(ref, (DOMDataBroker) service);
} else if (service instanceof SchemaService) {
- return _createProxyImpl(ref, (SchemaService) service);
+ return createProxyImpl(ref, (SchemaService) service);
} else if (service instanceof DOMMountPointService) {
- return _createProxyImpl(ref, (DOMMountPointService) service);
+ return createProxyImpl(ref, (DOMMountPointService) service);
} else if (service != null) {
- return _createProxyImpl(ref, service);
+ return createProxyImplFallback(ref, service);
} else {
throw new IllegalArgumentException("Unhandled parameter types: "
+ Arrays.<Object> asList(ref, service).toString());