Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Fix Eclipse warnings in config-manager
[controller.git]
/
opendaylight
/
config
/
config-manager
/
src
/
main
/
java
/
org
/
opendaylight
/
controller
/
config
/
manager
/
impl
/
osgi
/
BlankTransactionServiceTracker.java
diff --git
a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java
b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java
index 375ef5948712f3bcc5dc803802645b1d6fa56103..a15820556c4a9a76ac45f80ccf89a317df646d53 100644
(file)
--- a/
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java
+++ b/
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java
@@
-8,6
+8,9
@@
package org.opendaylight.controller.config.manager.impl.osgi;
import com.google.common.annotations.VisibleForTesting;
package org.opendaylight.controller.config.manager.impl.osgi;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import javax.management.ObjectName;
import org.opendaylight.controller.config.api.ConflictingVersionException;
import org.opendaylight.controller.config.api.ValidationException;
import javax.management.ObjectName;
import org.opendaylight.controller.config.api.ConflictingVersionException;
import org.opendaylight.controller.config.api.ValidationException;
@@
-25,47
+28,52
@@
import org.slf4j.LoggerFactory;
* functionality.
*/
public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer<ModuleFactory, Object> {
* functionality.
*/
public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer<ModuleFactory, Object> {
- private static final Logger
logger
= LoggerFactory.getLogger(BlankTransactionServiceTracker.class);
+ private static final Logger
LOG
= LoggerFactory.getLogger(BlankTransactionServiceTracker.class);
public static final int DEFAULT_MAX_ATTEMPTS = 10;
private final BlankTransaction blankTransaction;
public static final int DEFAULT_MAX_ATTEMPTS = 10;
private final BlankTransaction blankTransaction;
- private int maxAttempts;
+ private final ExecutorService txExecutor;
+ private final int maxAttempts;
public BlankTransactionServiceTracker(final ConfigRegistryImpl configRegistry) {
public BlankTransactionServiceTracker(final ConfigRegistryImpl configRegistry) {
- this(new BlankTransaction() {
- @Override
- public CommitStatus hit() throws ValidationException, ConflictingVersionException {
- ObjectName tx = configRegistry.beginConfig(true);
- return configRegistry.commitConfig(tx);
- }
- });
+ this(() -> {
+ ObjectName tx = configRegistry.beginConfig(true);
+ return configRegistry.commitConfig(tx);
+ });
}
public BlankTransactionServiceTracker(final BlankTransaction blankTransaction) {
}
public BlankTransactionServiceTracker(final BlankTransaction blankTransaction) {
- this(blankTransaction, DEFAULT_MAX_ATTEMPTS);
+ this(blankTransaction, DEFAULT_MAX_ATTEMPTS, Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
+ .setNameFormat("config-blank-txn-%d").build()));
}
@VisibleForTesting
}
@VisibleForTesting
- BlankTransactionServiceTracker(final BlankTransaction blankTx, final int maxAttempts) {
+ BlankTransactionServiceTracker(final BlankTransaction blankTx, final int maxAttempts,
+ final ExecutorService txExecutor) {
this.blankTransaction = blankTx;
this.maxAttempts = maxAttempts;
this.blankTransaction = blankTx;
this.maxAttempts = maxAttempts;
+ this.txExecutor = txExecutor;
}
@Override
public Object addingService(ServiceReference<ModuleFactory> moduleFactoryServiceReference) {
}
@Override
public Object addingService(ServiceReference<ModuleFactory> moduleFactoryServiceReference) {
- blankTransaction();
+ blankTransaction
Async
();
return null;
}
return null;
}
- synchronized void blankTransaction() {
+ private void blankTransactionAsync() {
+ txExecutor.execute(this::blankTransactionSync);
+ }
+
+ void blankTransactionSync() {
// race condition check: config-persister might push new configuration while server is starting up.
ConflictingVersionException lastException = null;
for (int i = 0; i < maxAttempts; i++) {
try {
// create transaction
CommitStatus commitStatus = blankTransaction.hit();
// race condition check: config-persister might push new configuration while server is starting up.
ConflictingVersionException lastException = null;
for (int i = 0; i < maxAttempts; i++) {
try {
// create transaction
CommitStatus commitStatus = blankTransaction.hit();
-
logger
.debug("Committed blank transaction with status {}", commitStatus);
+
LOG
.debug("Committed blank transaction with status {}", commitStatus);
return;
} catch (ConflictingVersionException e) {
lastException = e;
return;
} catch (ConflictingVersionException e) {
lastException = e;
@@
-73,29
+81,30
@@
public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer<
Thread.sleep(1000);
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
Thread.sleep(1000);
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
- throw new IllegalStateException(interruptedException);
+ LOG.debug("blankTransactionSync was interrupted");
+ return;
}
} catch (ValidationException e) {
}
} catch (ValidationException e) {
- logger.error("Validation exception while running blank transaction indicates programming error", e);
- throw new RuntimeException("Validation exception while running blank transaction indicates programming error", e);
+ LOG.error("Validation exception while running blank transaction indicates programming error", e);
}
}
}
}
- throw new RuntimeException("Maximal number of attempts reached and still cannot get optimistic lock from " +
- "config manager",lastException);
+
+ LOG.error("Maximal number of attempts reached and still cannot get optimistic lock from config manager",
+ lastException);
}
@Override
public void modifiedService(ServiceReference <ModuleFactory> moduleFactoryServiceReference, Object o) {
}
@Override
public void modifiedService(ServiceReference <ModuleFactory> moduleFactoryServiceReference, Object o) {
- blankTransaction();
+ blankTransaction
Async
();
}
@Override
public void removedService(ServiceReference<ModuleFactory> moduleFactoryServiceReference, Object o) {
}
@Override
public void removedService(ServiceReference<ModuleFactory> moduleFactoryServiceReference, Object o) {
- blankTransaction();
+ blankTransaction
Async
();
}
@VisibleForTesting
}
@VisibleForTesting
-
static
interface BlankTransaction {
+ interface BlankTransaction {
CommitStatus hit() throws ValidationException, ConflictingVersionException;
}
}
CommitStatus hit() throws ValidationException, ConflictingVersionException;
}
}