From: michal rehak Date: Fri, 3 Apr 2015 16:15:34 +0000 (+0000) Subject: Merge "Rpc manager not needed to instantiate DeviceManager" X-Git-Tag: release/lithium~528 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=d2fa11665095a3b8641b0b97fa54f99c50dfde85;hp=7e660aa27c578f75db565563a0ec9d1dcd508540;p=openflowplugin.git Merge "Rpc manager not needed to instantiate DeviceManager" --- diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/BarrierProcessor.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/BarrierProcessor.java new file mode 100644 index 0000000000..1323ccab3c --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/BarrierProcessor.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2015 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.openflowplugin.impl.device; + +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; + +/** + * openflowplugin-impl + * org.opendaylight.openflowplugin.impl.device + * + * + * + * @author Vaclav Demcak + * + * Created: Apr 3, 2015 + */ +public class BarrierProcessor { + + public static void processOutstandingRequests(final long xid, final DeviceContext deviceCtx) { + // TODO + } +} diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/BarrierTaskBuilder.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/BarrierTaskBuilder.java new file mode 100644 index 0000000000..afb9abb23e --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/BarrierTaskBuilder.java @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2015 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.openflowplugin.impl.device; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.JdkFutureAdapters; +import com.google.common.util.concurrent.ListenableFuture; +import io.netty.util.HashedWheelTimer; +import io.netty.util.Timeout; +import io.netty.util.TimerTask; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * openflowplugin-impl + * org.opendaylight.openflowplugin.impl.device + * + * Barrier message self restarting builder. + * + * @author Vaclav Demcak + * + * Created: Apr 3, 2015 + */ +public class BarrierTaskBuilder { + + private static final Logger LOG = LoggerFactory.getLogger(BarrierTaskBuilder.class); + + private final HashedWheelTimer hashedWheelTimer; + private final DeviceContext deviceCtx; + + public BarrierTaskBuilder (final DeviceContext deviceCtx, final HashedWheelTimer hashedWheelTimer) { + this.hashedWheelTimer = Preconditions.checkNotNull(hashedWheelTimer); + this.deviceCtx = Preconditions.checkNotNull(deviceCtx); + } + + public void buildAndFireBarrierTask() { + hashedWheelTimer.newTimeout(makeTimerTask(), 500, TimeUnit.MILLISECONDS); + } + + private TimerTask makeTimerTask() { + return new TimerTask() { + @Override + public void run(final Timeout timeout) throws Exception { + final Future> future = deviceCtx.getPrimaryConnectionContext() + .getConnectionAdapter().barrier(makeBarier()); + final ListenableFuture> lsFuture = JdkFutureAdapters.listenInPoolThread(future); + Futures.addCallback(lsFuture, makeCallBack()); + } + }; + } + + private FutureCallback> makeCallBack() { + return new FutureCallback>() { + @Override + public void onSuccess(final RpcResult result) { + BarrierProcessor.processOutstandingRequests(result.getResult().getXid(), deviceCtx); + buildAndFireBarrierTask(); + } + @Override + public void onFailure(final Throwable t) { + LOG.info("Barrier has failed {} ", t.getMessage()); + LOG.trace("Barrier has failed", t); + } + }; + } + + private BarrierInput makeBarier() { + final BarrierInputBuilder biBuilder = new BarrierInputBuilder(); + biBuilder.setVersion(deviceCtx.getDeviceState().getVersion()); + biBuilder.setXid(deviceCtx.getNextXid().getValue()); + return biBuilder.build(); + } +}