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;
22 public final class TimedReconnectStrategyFactoryModule extends org.opendaylight.controller.config.yang.protocol.framework.AbstractTimedReconnectStrategyFactoryModule
25 public TimedReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
26 super(identifier, dependencyResolver);
29 public TimedReconnectStrategyFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
30 TimedReconnectStrategyFactoryModule oldModule, java.lang.AutoCloseable oldInstance) {
32 super(identifier, dependencyResolver, oldModule, oldInstance);
36 protected void customValidation(){
37 JmxAttributeValidationException.checkNotNull(getSleepFactor(), "value is not set.", sleepFactorJmxAttribute);
38 JmxAttributeValidationException.checkCondition(getSleepFactor().doubleValue() >= 1, "value " + getSleepFactor()
39 + " is less than 1", sleepFactorJmxAttribute);
41 JmxAttributeValidationException.checkNotNull(getConnectTime(), "value is not set.", connectTimeJmxAttribute);
42 JmxAttributeValidationException.checkCondition(getConnectTime() >= 0, "value " + getConnectTime()
43 + " is less than 0", connectTimeJmxAttribute);
45 JmxAttributeValidationException.checkNotNull(getMinSleep(), "value is not set.", minSleepJmxAttribute);
46 JmxAttributeValidationException.checkCondition(getMaxSleep() == null || getMinSleep() <= getMaxSleep(),
47 "value " + getMinSleep() + " is greter than MaxSleep " + getMaxSleep(), minSleepJmxAttribute);
51 public java.lang.AutoCloseable createInstance() {
52 return new TimedReconnectStrategyFactoryCloseable(getTimedReconnectExecutorDependency(),
53 getConnectTime(), getMinSleep(), getSleepFactor().doubleValue(), getMaxSleep(), getMaxAttempts(),
57 private static final class TimedReconnectStrategyFactoryCloseable implements ReconnectStrategyFactory, AutoCloseable {
59 private final EventExecutor executor;
60 private final Long deadline, maxAttempts, maxSleep;
61 private final double sleepFactor;
62 private final int connectTime;
63 private final long minSleep;
65 public TimedReconnectStrategyFactoryCloseable(final EventExecutor executor, final int connectTime, final long minSleep, final double sleepFactor,
66 final Long maxSleep, final Long maxAttempts, final Long deadline) {
67 Preconditions.checkArgument(maxSleep == null || minSleep <= maxSleep);
68 Preconditions.checkArgument(sleepFactor >= 1);
69 Preconditions.checkArgument(connectTime >= 0);
70 this.executor = Preconditions.checkNotNull(executor);
71 this.deadline = deadline;
72 this.maxAttempts = maxAttempts;
73 this.minSleep = minSleep;
74 this.maxSleep = maxSleep;
75 this.sleepFactor = sleepFactor;
76 this.connectTime = connectTime;
80 public void close() throws Exception {
85 public ReconnectStrategy createReconnectStrategy() {
86 return new TimedReconnectStrategy(this.executor,
87 this.connectTime, this.minSleep, this.sleepFactor, this.maxSleep, this.maxAttempts,