}
- public boolean isCodecAvailable(final Class<?> cls) {
- // FIXME: enforce type?
- // Preconditions.checkArgument(DataContainer.class.isAssignableFrom(cls));
-
- if (containerCodecs.containsKey(cls)) {
- return true;
- }
- if (identifierCodecs.containsKey(cls)) {
- return true;
- }
- if (choiceCodecs.containsKey(cls)) {
- return true;
- }
- if (caseCodecs.containsKey(cls)) {
- return true;
- }
- if (augmentableCodecs.containsKey(cls)) {
- return true;
- }
- if (augmentationCodecs.containsKey(cls)) {
- return true;
- }
- return false;
- }
-
- public static final Type referencedType(final Class<?> augmentableType) {
+ private static final Type referencedType(final Class<?> augmentableType) {
return new ReferencedTypeImpl(augmentableType.getPackage().getName(), augmentableType.getSimpleName());
}
}
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
+import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMappingService, SchemaContextListener,
@Override
public void waitForSchema(final Class<?> cls) {
- if (!registry.isCodecAvailable(cls)) {
- final Type ref = Types.typeForClass(cls);
+ final ListenableFuture<Type> f = getSchemaDefinition(cls);
+ if (f != null) {
try {
- getSchemaWithRetry(ref);
+ f.get();
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Waiting for schema for class {} failed", cls, e);
throw new IllegalStateException(String.format("Failed to get schema for %s", cls), e);
}
+ LOG.info("Schema for {} became available, thread unblocked", cls);
}
}
return serviceRef;
}
- private void getSchemaWithRetry(final Type type) throws InterruptedException, ExecutionException {
- final SettableFuture<Type> f;
-
+ private ListenableFuture<Type> getSchemaDefinition(final Class<?> cls) {
+ final Type type = Types.typeForClass(cls);
synchronized (this) {
if (typeToDefinition.containsKey(type)) {
- return;
+ return null;
}
- LOG.info("Thread blocked waiting for schema for: {}", type.getFullyQualifiedName());
- f = SettableFuture.create();
+ LOG.info("Thread is going to wait for schema for: {}", type.getFullyQualifiedName());
+ final SettableFuture<Type> f = SettableFuture.create();
promisedTypes.put(type, f);
+ return f;
}
-
- f.get();
- LOG.info("Schema for {} became available, thread unblocked", type.getFullyQualifiedName());
}
@GuardedBy("this")
+/**
+ * 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.sal.binding.generator.impl;
-public interface SchemaLock {
-
- public void waitForSchema(Class<?> cls);
-
+interface SchemaLock {
+ void waitForSchema(Class<?> cls);
}