From: Robert Varga Date: Sat, 10 May 2014 11:25:21 +0000 (+0200) Subject: BUG-642: get rid of sneakyThrow X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~113^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=04001c9a746f523f2a56b1d6caece31277218249;ds=sidebyside BUG-642: get rid of sneakyThrow This patch rids us of unneeded usage of Exceptions.sneakyThrow. It generally hides problems and is only useful for generated (or sloppy) code. Change-Id: Ibb73f4546b1785c4bcb3e6c033249f58efd1d2d6 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java index fad37ae4f3..d434444d0a 100644 --- a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java +++ b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java @@ -1,15 +1,16 @@ /** * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.sal.compatibility; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import org.eclipse.xtext.xbase.lib.Exceptions; +import java.util.Date; +import java.util.HashSet; +import java.util.List; + import org.opendaylight.controller.sal.common.util.Arguments; import org.opendaylight.controller.sal.core.AdvertisedBandwidth; import org.opendaylight.controller.sal.core.Bandwidth; @@ -58,36 +59,30 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; -import java.util.Date; -import java.util.HashSet; -import java.util.List; +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; -@SuppressWarnings("all") -public class NodeMapping { +public final class NodeMapping { public final static String MD_SAL_TYPE = "MD_SAL"; - + private final static Class NODE_CLASS = Node.class; - + private final static Class NODECONNECTOR_CLASS = NodeConnector.class; - + private NodeMapping() { throw new UnsupportedOperationException("Utility class. Instantiation is not allowed."); } - + public static org.opendaylight.controller.sal.core.Node toADNode(final InstanceIdentifier node) throws ConstructionException { NodeId nodeId = NodeMapping.toNodeId(node); return NodeMapping.toADNode(nodeId); } - - public static org.opendaylight.controller.sal.core.Node toADNode(final NodeId id) { - try { + + public static org.opendaylight.controller.sal.core.Node toADNode(final NodeId id) throws ConstructionException { String aDNodeId = NodeMapping.toADNodeId(id); return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, aDNodeId); - } catch (Throwable e) { - throw Exceptions.sneakyThrow(e); - } } - + public static NodeId toNodeId(final InstanceIdentifier node) { Preconditions.>checkNotNull(node); List path = node.getPath(); @@ -96,16 +91,16 @@ public class NodeMapping { Preconditions.checkArgument(size >= 2); final PathArgument arg = path.get(1); final IdentifiableItem item = Arguments.checkInstanceOf(arg, IdentifiableItem.class); - Identifier key = item.getKey(); + Identifier key = item.getKey(); final NodeKey nodeKey = Arguments.checkInstanceOf(key, NodeKey.class); return nodeKey.getId(); } - + public static String toADNodeId(final NodeId nodeId) { Preconditions.checkNotNull(nodeId); return nodeId.getValue(); } - + public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorRef source) throws ConstructionException { Preconditions.checkNotNull(source); final InstanceIdentifier path = Preconditions.>checkNotNull(source.getValue()); @@ -115,18 +110,14 @@ public class NodeMapping { final NodeConnectorKey connectorKey = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class); return NodeMapping.toADNodeConnector(connectorKey.getId(), NodeMapping.toNodeId(path)); } - - public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorId ncid, final NodeId nid) { - try { - String nodeConnectorType = NodeMapping.toNodeConnectorType(ncid, nid); - Object aDNodeConnectorId = NodeMapping.toADNodeConnectorId(ncid, nid); - org.opendaylight.controller.sal.core.Node aDNode = NodeMapping.toADNode(nid); - return new org.opendaylight.controller.sal.core.NodeConnector(nodeConnectorType, aDNodeConnectorId, aDNode); - } catch (Throwable e) { - throw Exceptions.sneakyThrow(e); - } + + public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorId ncid, final NodeId nid) throws ConstructionException { + String nodeConnectorType = NodeMapping.toNodeConnectorType(ncid, nid); + Object aDNodeConnectorId = NodeMapping.toADNodeConnectorId(ncid, nid); + org.opendaylight.controller.sal.core.Node aDNode = NodeMapping.toADNode(nid); + return new org.opendaylight.controller.sal.core.NodeConnector(nodeConnectorType, aDNodeConnectorId, aDNode); } - + public static String toNodeConnectorType(final NodeConnectorId ncId, final NodeId nodeId) { if (ncId.equals(toLocalNodeConnectorId(nodeId))) { return NodeConnectorIDType.SWSTACK; @@ -146,19 +137,19 @@ public class NodeMapping { } return nodeConnectorId.getValue(); } - + public static NodeConnectorId toControllerNodeConnectorId(final NodeId node) { return new NodeConnectorId(node.getValue() + ":" + 4294967293L); } - + public static NodeConnectorId toLocalNodeConnectorId(final NodeId node) { return new NodeConnectorId(node.getValue() + ":" + 4294967294L); } - + public static NodeConnectorId toNormalNodeConnectorId(final NodeId node) { return new NodeConnectorId(node.getValue() + ":" + 4294967290L); } - + public static NodeRef toNodeRef(final org.opendaylight.controller.sal.core.Node node) { Preconditions.checkArgument(MD_SAL_TYPE.equals(node.getType())); final String nodeId = Arguments.checkInstanceOf(node.getID(), String.class); @@ -166,7 +157,7 @@ public class NodeMapping { final InstanceIdentifier nodePath = InstanceIdentifier.builder(Nodes.class).child(NODE_CLASS, nodeKey).toInstance(); return new NodeRef(nodePath); } - + public static NodeConnectorRef toNodeConnectorRef(final org.opendaylight.controller.sal.core.NodeConnector nodeConnector) { final NodeRef node = NodeMapping.toNodeRef(nodeConnector.getNode()); @@ -190,11 +181,11 @@ public class NodeMapping { final InstanceIdentifier path = InstanceIdentifier.builder(nodePath).child(NODECONNECTOR_CLASS, connectorKey).toInstance(); return new NodeConnectorRef(path); } - + public static org.opendaylight.controller.sal.core.Node toADNode(final NodeRef node) throws ConstructionException { return NodeMapping.toADNode(node.getValue()); } - + public static HashSet toADNodeConnectorProperties(final NodeConnectorUpdated nc) { final FlowCapableNodeConnectorUpdated fcncu = nc.getAugmentation(FlowCapableNodeConnectorUpdated.class); if (!Objects.equal(fcncu, null)) { @@ -202,7 +193,7 @@ public class NodeMapping { } return new HashSet(); } - + public static HashSet toADNodeConnectorProperties(final NodeConnector nc) { final FlowCapableNodeConnector fcnc = nc.getAugmentation(FlowCapableNodeConnector.class); if (!Objects.equal(fcnc, null)) { @@ -210,7 +201,7 @@ public class NodeMapping { } return new HashSet(); } - + public static HashSet toADNodeConnectorProperties(final FlowNodeConnector fcncu) { final HashSet props = new HashSet<>(); @@ -239,11 +230,11 @@ public class NodeMapping { } return props; } - + public static Name toAdName(final String name) { return new Name(name); } - + public static Config toAdConfig(final PortConfig pc) { Config config = null; if (pc.isPORTDOWN()) { @@ -253,7 +244,7 @@ public class NodeMapping { } return config; } - + public static org.opendaylight.controller.sal.core.State toAdState(final State s) { org.opendaylight.controller.sal.core.State state = null; @@ -264,7 +255,7 @@ public class NodeMapping { } return state; } - + public static Bandwidth toAdBandwidth(final PortFeatures pf) { Bandwidth bw = null; if (pf.isTenMbHd() || pf.isTenMbFd()) { @@ -286,7 +277,7 @@ public class NodeMapping { } return bw; } - + public static AdvertisedBandwidth toAdAdvertizedBandwidth(final PortFeatures pf) { AdvertisedBandwidth abw = null; final Bandwidth bw = toAdBandwidth(pf); @@ -295,7 +286,7 @@ public class NodeMapping { } return abw; } - + public static SupportedBandwidth toAdSupportedBandwidth(final PortFeatures pf) { SupportedBandwidth sbw = null; final Bandwidth bw = toAdBandwidth(pf); @@ -304,7 +295,7 @@ public class NodeMapping { } return sbw; } - + public static PeerBandwidth toAdPeerBandwidth(final PortFeatures pf) { PeerBandwidth pbw = null; final Bandwidth bw = toAdBandwidth(pf); @@ -313,7 +304,7 @@ public class NodeMapping { } return pbw; } - + public static HashSet toADNodeProperties(final NodeUpdated nu) { final FlowCapableNodeUpdated fcnu = nu.getAugmentation(FlowCapableNodeUpdated.class); if (fcnu != null) { @@ -321,7 +312,7 @@ public class NodeMapping { } return new HashSet(); } - + public static HashSet toADNodeProperties(final FlowNode fcnu, final NodeId id) { final HashSet props = new HashSet<>(); @@ -348,13 +339,13 @@ public class NodeMapping { } return props; } - + public static TimeStamp toADTimestamp() { final Date date = new Date(); final TimeStamp timestamp = new TimeStamp(date.getTime(), "connectedSince"); return timestamp; } - + public static MacAddress toADMacAddress(final NodeId id) { final String nodeId = id.getValue().replaceAll("openflow:", ""); long lNodeId = Long.parseLong(nodeId); @@ -362,11 +353,11 @@ public class NodeMapping { byte[] bytesFromDpid = ToSalConversionsUtils.bytesFromDpid(lNodeId); return new MacAddress(bytesFromDpid); } - + public static Tables toADTables(final Short tables) { return new Tables(tables.byteValue()); } - + public static Capabilities toADCapabiliities(final List> capabilities) { int b = 0; @@ -389,7 +380,7 @@ public class NodeMapping { } return new Capabilities(b); } - + public static Buffers toADBuffers(final Long buffers) { return new Buffers(buffers.intValue()); } diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java index cc9c6ebaa6..a935a33a5e 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java @@ -17,7 +17,6 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; -import org.eclipse.xtext.xbase.lib.Exceptions; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -79,17 +78,21 @@ public class AbstractForwardedTransaction apply(@Nullable final Optional> normalizedNode) { - try { - final DataObject dataObject = normalizedNode.isPresent() ? codec.toBinding(path, - normalizedNode.get()) : null; + if (normalizedNode.isPresent()) { + final DataObject dataObject; + try { + dataObject = codec.toBinding(path, normalizedNode.get()); + } catch (DeserializationException e) { + LOG.warn("Failed to create dataobject from node {}", normalizedNode.get(), e); + throw new IllegalStateException("Failed to create dataobject", e); + } + if (dataObject != null) { updateCache(store, path, dataObject); + return Optional.of(dataObject); } - return Optional.fromNullable(dataObject); - } catch (DeserializationException e) { - Exceptions.sneakyThrow(e); } - return null; + return Optional.absent(); } }); } @@ -108,10 +111,10 @@ public class AbstractForwardedTransaction> normalized = codec .toNormalizedNode(path, data); - org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalizedPath = normalized.getKey(); - ensureParentsByMerge(writeTransaction, store, normalized.getKey(), path); - LOG.debug("Tx: {} : Putting data {}",getDelegate().getIdentifier(),normalized.getKey()); - writeTransaction.put(store, normalized.getKey(), normalized.getValue()); + final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalizedPath = normalized.getKey(); + ensureParentsByMerge(writeTransaction, store, normalizedPath, path); + LOG.debug("Tx: {} : Putting data {}", getDelegate().getIdentifier(), normalizedPath); + writeTransaction.put(store, normalizedPath, normalized.getValue()); } protected void doMergeWithEnsureParents(final DOMDataReadWriteTransaction writeTransaction, @@ -120,10 +123,10 @@ public class AbstractForwardedTransaction> normalized = codec .toNormalizedNode(path, data); - org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalizedPath = normalized.getKey(); - ensureParentsByMerge(writeTransaction, store, normalized.getKey(), path); - LOG.debug("Tx: {} : Merge data {}",getDelegate().getIdentifier(),normalized.getKey()); - writeTransaction.merge(store, normalized.getKey(), normalized.getValue()); + final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalizedPath = normalized.getKey(); + ensureParentsByMerge(writeTransaction, store, normalizedPath, path); + LOG.debug("Tx: {} : Merge data {}",getDelegate().getIdentifier(),normalizedPath); + writeTransaction.merge(store, normalizedPath, normalized.getValue()); } private void ensureParentsByMerge(final DOMDataReadWriteTransaction writeTransaction, diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java index ea8b6c0972..ae90a7739e 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java @@ -7,151 +7,89 @@ */ package org.opendaylight.controller.sal.binding.codegen; -import com.google.common.base.Objects; import java.lang.reflect.Field; import java.util.Map; -import org.eclipse.xtext.xbase.lib.Exceptions; -import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification; + import org.opendaylight.yangtools.yang.binding.BaseIdentity; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; -@SuppressWarnings("all") -public class RuntimeCodeHelper { - /** - * Helper method to return delegate from ManagedDirectedProxy with use of reflection. - * - * Note: This method uses reflection, but access to delegate field should be - * avoided and called only if neccessary. - */ - public static T getDelegate(final RpcService proxy) { - try { - Class _class = proxy.getClass(); - final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD); - boolean _equals = Objects.equal(field, null); - if (_equals) { - UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to get delegate from proxy"); - throw _unsupportedOperationException; - } - try { - Object _get = field.get(proxy); - return ((T) _get); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } catch (Throwable _e_1) { - throw Exceptions.sneakyThrow(_e_1); +public final class RuntimeCodeHelper { + private RuntimeCodeHelper() { + throw new UnsupportedOperationException("Utility class should never be instantiated"); + } + + private static Field getField(final Class cls, final String name) { + try { + return cls.getField(name); + } catch (NoSuchFieldException e) { + throw new IllegalArgumentException( + String.format("Class %s is missing field %s", cls, name), e); + } catch (SecurityException e) { + throw new IllegalStateException(String.format("Failed to examine class %s", cls), e); + } } - } - /** - * Helper method to set delegate to ManagedDirectedProxy with use of reflection. - * - * Note: This method uses reflection, but setting delegate field should not occur too much - * to introduce any significant performance hits. - */ - public static void setDelegate(final RpcService proxy, final RpcService delegate) { - try { - Class _class = proxy.getClass(); - final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD); - boolean _equals = Objects.equal(field, null); - if (_equals) { - UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to set delegate to proxy"); - throw _unsupportedOperationException; - } - boolean _or = false; - boolean _equals_1 = Objects.equal(delegate, null); - if (_equals_1) { - _or = true; - } else { - Class _type = field.getType(); - Class _class_1 = delegate.getClass(); - boolean _isAssignableFrom = _type.isAssignableFrom(_class_1); - _or = (_equals_1 || _isAssignableFrom); - } - if (_or) { - field.set(proxy, delegate); - } else { - IllegalArgumentException _illegalArgumentException = new IllegalArgumentException("delegate class is not assignable to proxy"); - throw _illegalArgumentException; - } - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); + private static Field getDelegateField(final Class cls) { + return getField(cls, RuntimeCodeSpecification.DELEGATE_FIELD); } - } - /** - * Helper method to set delegate to ManagedDirectedProxy with use of reflection. - * - * Note: This method uses reflection, but setting delegate field should not occur too much - * to introduce any significant performance hits. - */ - public static void setDelegate(final Object proxy, final Object delegate) { - try { - Class _class = proxy.getClass(); - final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD); - boolean _equals = Objects.equal(field, null); - if (_equals) { - UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to set delegate to proxy"); - throw _unsupportedOperationException; - } - boolean _or = false; - boolean _equals_1 = Objects.equal(delegate, null); - if (_equals_1) { - _or = true; - } else { - Class _type = field.getType(); - Class _class_1 = delegate.getClass(); - boolean _isAssignableFrom = _type.isAssignableFrom(_class_1); - _or = (_equals_1 || _isAssignableFrom); - } - if (_or) { - field.set(proxy, delegate); - } else { - IllegalArgumentException _illegalArgumentException = new IllegalArgumentException("delegate class is not assignable to proxy"); - throw _illegalArgumentException; - } - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); + private static Object getFieldValue(final Field field, final Object obj) { + try { + return field.get(obj); + } catch (IllegalAccessException e) { + throw new IllegalStateException(String.format("Failed to get field %s of object %s", field, obj), e); + } + } + + private static void setFieldValue(final Field field, final Object obj, final Object value) { + try { + field.set(obj, value); + } catch (IllegalAccessException e) { + throw new IllegalStateException(String.format("Failed to set field %s to %s", field, value), e); + } + } + + /** + * Helper method to return delegate from ManagedDirectedProxy with use of reflection. + * + * Note: This method uses reflection, but access to delegate field should be + * avoided and called only if necessary. + */ + @SuppressWarnings("unchecked") + public static T getDelegate(final RpcService proxy) { + return (T)getFieldValue(getDelegateField(proxy.getClass()), proxy); + } + + /** + * Helper method to set delegate to ManagedDirectedProxy with use of reflection. + * + * Note: This method uses reflection, but setting delegate field should not occur too much + * to introduce any significant performance hits. + */ + public static void setDelegate(final Object proxy, final Object delegate) { + final Field field = getDelegateField(proxy.getClass()); + + if (delegate != null) { + final Class ft = field.getType(); + if (!ft.isAssignableFrom(delegate.getClass())) { + throw new IllegalArgumentException( + String.format("Field %s type %s is not compatible with delegate type %s", + field, ft, delegate.getClass())); + } + } + + setFieldValue(field, proxy, delegate); } - } - public static Map,? extends RpcService> getRoutingTable(final RpcService target, final Class tableClass) { - try { - Class _class = target.getClass(); - String _routingTableField = RuntimeCodeSpecification.getRoutingTableField(tableClass); - final Field field = _class.getField(_routingTableField); - boolean _equals = Objects.equal(field, null); - if (_equals) { - UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException( - "Unable to get routing table. Table field does not exists"); - throw _unsupportedOperationException; - } - try { - Object _get = field.get(target); - return ((Map,? extends RpcService>) _get); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); - } - } catch (Throwable _e_1) { - throw Exceptions.sneakyThrow(_e_1); + @SuppressWarnings("unchecked") + public static Map,? extends RpcService> getRoutingTable(final RpcService target, final Class tableClass) { + final Field field = getField(target.getClass(), RuntimeCodeSpecification.getRoutingTableField(tableClass)); + return (Map,? extends RpcService>) getFieldValue(field, target); } - } - public static void setRoutingTable(final RpcService target, final Class tableClass, final Map,? extends RpcService> routingTable) { - try { - Class _class = target.getClass(); - String _routingTableField = RuntimeCodeSpecification.getRoutingTableField(tableClass); - final Field field = _class.getField(_routingTableField); - boolean _equals = Objects.equal(field, null); - if (_equals) { - UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException( - "Unable to set routing table. Table field does not exists"); - throw _unsupportedOperationException; - } - field.set(target, routingTable); - } catch (Throwable _e) { - throw Exceptions.sneakyThrow(_e); + public static void setRoutingTable(final RpcService target, final Class tableClass, final Map,? extends RpcService> routingTable) { + final Field field = getField(target.getClass(), RuntimeCodeSpecification.getRoutingTableField(tableClass)); + setFieldValue(field, target, routingTable); } - } -} \ No newline at end of file +} diff --git a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/service/AbstractDataBroker.java b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/service/AbstractDataBroker.java index 82ce44c5e9..d8bde3d41a 100644 --- a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/service/AbstractDataBroker.java +++ b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/service/AbstractDataBroker.java @@ -14,14 +14,12 @@ import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import org.eclipse.xtext.xbase.lib.Exceptions; import org.opendaylight.controller.md.sal.common.api.RegistrationListener; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent; @@ -46,6 +44,7 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; +import com.google.common.base.Supplier; import com.google.common.collect.FluentIterable; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; @@ -120,9 +119,9 @@ public abstract class AbstractDataBroker

, D extends Object, DC } protected ImmutableList> affectedCommitHandlers(final Set

paths) { - final Callable>> _function = new Callable>>() { + final Supplier>> _function = new Supplier>>() { @Override - public ImmutableList> call() throws Exception { + public ImmutableList> get() { Map>> _asMap = commitHandlers.asMap(); Set>>> _entrySet = _asMap.entrySet(); FluentIterable>>> _from = FluentIterable @@ -163,9 +162,9 @@ public abstract class AbstractDataBroker

, D extends Object, DC } protected ImmutableList> probablyAffectedCommitHandlers(final HashSet

paths) { - final Callable>> _function = new Callable>>() { + final Supplier>> _function = new Supplier>>() { @Override - public ImmutableList> call() throws Exception { + public ImmutableList> get() { Map>> _asMap = commitHandlers.asMap(); Set>>> _entrySet = _asMap.entrySet(); FluentIterable>>> _from = FluentIterable @@ -221,12 +220,10 @@ public abstract class AbstractDataBroker

, D extends Object, DC return _dataReadRouter.readOperationalData(path); } - private static T withLock(final Lock lock, final Callable method) { + private static T withLock(final Lock lock, final Supplier method) { lock.lock(); try { - return method.call(); - } catch (Exception e) { - throw Exceptions.sneakyThrow(e); + return method.get(); } finally { lock.unlock(); }