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

org.opendaylight.jsonrpc.binding.ProxyContext Maven / Gradle / Ivy

There is a newer version: 1.17.0
Show newest version
/*
 * Copyright (c) 2018 Lumina Networks, Inc. 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.jsonrpc.binding;

import java.util.function.Consumer;
import org.opendaylight.jsonrpc.bus.messagelib.BaseSession;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.yang.binding.RpcService;

/**
 * Context of proxy. Allows proper cleanup of created instance.
 *
 * @author Richard Kosegi
 * @since Sep 21, 2018
 */
public class ProxyContext implements AutoCloseable {
    private final ObjectRegistration rpcRegistration;
    private final BaseSession session;
    private final T proxy;
    private final Consumer cleanCallback;
    private final Class type;

    ProxyContext(final Class type, final ObjectRegistration rpcRegistration, final BaseSession session,
            final T proxy, final Consumer cleanCallback) {
        this.rpcRegistration = rpcRegistration;
        this.session = session;
        this.proxy = proxy;
        this.cleanCallback = cleanCallback;
        this.type = type;
    }

    public T getProxy() {
        return proxy;
    }

    @Override
    public void close() {
        cleanCallback.accept(proxy);
    }

    public Class getType() {
        return type;
    }

    void closeInternal() {
        session.close();
        rpcRegistration.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy