2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.yang.protocol.framework;
10 import io.netty.util.concurrent.EventExecutor;
12 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
13 import org.opendaylight.protocol.framework.ReconnectStrategy;
14 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
15 import org.opendaylight.protocol.framework.TimedReconnectStrategy;
17 import com.google.common.base.Preconditions;
23 public final class TimedReconnectStrategyFactoryModule extends org.opendaylight.controller.config.yang.protocol.framework.AbstractTimedReconnectStrategyFactoryModule
26 public TimedReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
27 super(identifier, dependencyResolver);
30 public TimedReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
31 TimedReconnectStrategyFactoryModule oldModule, java.lang.AutoCloseable oldInstance) {
33 super(identifier, dependencyResolver, oldModule, oldInstance);
37 protected void customValidation(){
38 JmxAttributeValidationException.checkNotNull(getSleepFactor(), "value is not set.", sleepFactorJmxAttribute);
39 JmxAttributeValidationException.checkCondition(getSleepFactor().doubleValue() >= 1, "value " + getSleepFactor()
40 + " is less than 1", sleepFactorJmxAttribute);
42 JmxAttributeValidationException.checkNotNull(getConnectTime(), "value is not set.", connectTimeJmxAttribute);
43 JmxAttributeValidationException.checkCondition(getConnectTime() >= 0, "value " + getConnectTime()
44 + " is less than 0", connectTimeJmxAttribute);
46 JmxAttributeValidationException.checkNotNull(getMinSleep(), "value is not set.", minSleepJmxAttribute);
47 JmxAttributeValidationException.checkCondition(getMaxSleep() == null || getMinSleep() <= getMaxSleep(),
48 "value " + getMinSleep() + " is greter than MaxSleep " + getMaxSleep(), minSleepJmxAttribute);
52 public java.lang.AutoCloseable createInstance() {
53 return new TimedReconnectStrategyFactoryCloseable(getTimedReconnectExecutorDependency(),
54 getConnectTime(), getMinSleep(), getSleepFactor().doubleValue(), getMaxSleep(), getMaxAttempts(),
58 private static final class TimedReconnectStrategyFactoryCloseable implements ReconnectStrategyFactory, AutoCloseable {
60 private final EventExecutor executor;
61 private final Long deadline, maxAttempts, maxSleep;
62 private final double sleepFactor;
63 private final int connectTime;
64 private final long minSleep;
66 public TimedReconnectStrategyFactoryCloseable(final EventExecutor executor, final int connectTime, final long minSleep, final double sleepFactor,
67 final Long maxSleep, final Long maxAttempts, final Long deadline) {
68 Preconditions.checkArgument(maxSleep == null || minSleep <= maxSleep);
69 Preconditions.checkArgument(sleepFactor >= 1);
70 Preconditions.checkArgument(connectTime >= 0);
71 this.executor = Preconditions.checkNotNull(executor);
72 this.deadline = deadline;
73 this.maxAttempts = maxAttempts;
74 this.minSleep = minSleep;
75 this.maxSleep = maxSleep;
76 this.sleepFactor = sleepFactor;
77 this.connectTime = connectTime;
81 public void close() throws Exception {
86 public ReconnectStrategy createReconnectStrategy() {
87 return new TimedReconnectStrategy(this.executor,
88 this.connectTime, this.minSleep, this.sleepFactor, this.maxSleep, this.maxAttempts,