All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.ocpplugin.impl.services.SimpleRequestCallback Maven / Gradle / Ivy

/*
 * 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.ocpplugin.impl.services;

import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.FutureCallback;
import org.opendaylight.ocpplugin.api.ocp.device.RequestContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.ocp.common.types.rev150811.OcpHeader;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

final class SimpleRequestCallback extends AbstractRequestCallback {
    private static final Logger LOG = LoggerFactory.getLogger(SimpleRequestCallback.class);
    private final Class clazz;

    private SimpleRequestCallback(final RequestContext context, final Class requestType, final Class clazz) {
        super(context, requestType);
        this.clazz = Preconditions.checkNotNull(clazz);
    }

    static  FutureCallback create(final RequestContext context, final Class requestType, final Class clazz) {
        return new SimpleRequestCallback<>(context, requestType, clazz);
    }

    @Override
    public final void onSuccess(final OcpHeader result) {

        if (result == null) {
            setResult(RpcResultBuilder.success().build());
            return;
        }
        if (!clazz.isInstance(result)) {
            LOG.info("Expected response type {}, got {}, result is empty", clazz, result.getClass());
            setResult(RpcResultBuilder.success().build());
            return;

        }

        setResult(RpcResultBuilder.success(clazz.cast(result)).build());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy