/* * Copyright (c) 2014 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.yangtools.yang.parser.repo; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry; class SettableSchemaProvider implements SchemaSourceProvider { private final SettableFuture future = SettableFuture.create(); private final T schemaSourceRepresentation; private final PotentialSchemaSource potentialSchemaSource; SettableSchemaProvider(final T schemaSourceRepresentation, final SourceIdentifier sourceIdentifier, final Class representation, final int cost) { this.schemaSourceRepresentation = schemaSourceRepresentation; this.potentialSchemaSource = PotentialSchemaSource.create(sourceIdentifier, representation, cost); } public static SettableSchemaProvider createRemote( final T schemaSourceRepresentation, final Class representation) { return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.getIdentifier(), representation, PotentialSchemaSource.Costs.REMOTE_IO.getValue()); } public static SettableSchemaProvider createImmediate( final T schemaSourceRepresentation, final Class representation) { return new SettableSchemaProvider<>(schemaSourceRepresentation, schemaSourceRepresentation.getIdentifier(), representation, PotentialSchemaSource.Costs.IMMEDIATE.getValue()); } @Override public ListenableFuture getSource(final SourceIdentifier sourceIdentifier) { return future; } public T getSchemaSourceRepresentation() { return schemaSourceRepresentation; } public SourceIdentifier getId() { return schemaSourceRepresentation.getIdentifier(); } public void setResult() { future.set(schemaSourceRepresentation); } public void setException(final Throwable ex) { future.setException(ex); } public void register(final SchemaSourceRegistry repo) { repo.registerSchemaSource(this, potentialSchemaSource); } }