List of usage examples for com.google.common.collect ClassToInstanceMap putInstance
<T extends B> T putInstance(Class<T> type, @Nullable T value);
From source file:org.immutables.generator.StaticEnvironment.java
static <T extends Completable> T getInstance(Class<T> type, Supplier<T> supplier) { ClassToInstanceMap<Completable> components = state().components; @Nullable//w w w . jav a2 s.c o m T instance = components.getInstance(type); if (instance == null) { instance = supplier.get(); components.putInstance(type, instance); } return instance; }
From source file:org.opendaylight.controller.config.yang.md.sal.dom.impl.DomBrokerImplModule.java
@Override public java.lang.AutoCloseable createInstance() { // The services are provided via blueprint so retrieve then from the OSGi service registry for // backwards compatibility. final List<AutoCloseable> closeables = new ArrayList<>(); DOMNotificationService domNotificationService = newTracker(DOMNotificationService.class, closeables) .waitForService(WaitingServiceTracker.FIVE_MINUTES); DOMNotificationPublishService domNotificationPublishService = newTracker( DOMNotificationPublishService.class, closeables).waitForService(WaitingServiceTracker.FIVE_MINUTES); DOMRpcService domRpcService = newTracker(DOMRpcService.class, closeables) .waitForService(WaitingServiceTracker.FIVE_MINUTES); DOMRpcProviderService domRpcProvider = newTracker(DOMRpcProviderService.class, closeables) .waitForService(WaitingServiceTracker.FIVE_MINUTES); DOMMountPointService mountService = newTracker(DOMMountPointService.class, closeables) .waitForService(WaitingServiceTracker.FIVE_MINUTES); SchemaService globalSchemaService = newTracker(SchemaService.class, closeables) .waitForService(WaitingServiceTracker.FIVE_MINUTES); final DOMDataBroker dataBroker = getAsyncDataBrokerDependency(); final ClassToInstanceMap<BrokerService> services = MutableClassToInstanceMap.create(); services.putInstance(DOMNotificationService.class, domNotificationService); services.putInstance(DOMNotificationPublishService.class, domNotificationPublishService); final SchemaService schemaService = getSchemaServiceImpl(globalSchemaService); services.putInstance(SchemaService.class, schemaService); services.putInstance(DOMDataBroker.class, dataBroker); services.putInstance(DOMRpcService.class, domRpcService); services.putInstance(DOMRpcProviderService.class, domRpcProvider); services.putInstance(DOMMountPointService.class, mountService); BrokerImpl broker = new BrokerImpl(domRpcService, domRpcProvider, services); broker.setDeactivator(new AutoCloseable() { @Override// www. ja va2 s . c om public void close() { for (AutoCloseable ac : closeables) { try { ac.close(); } catch (Exception e) { LOG.warn("Exception while closing {}", ac, e); } } } }); return broker; }
From source file:org.tensorics.core.commons.options.ImmutableOptionRegistry.java
private void addToMap(ClassToInstanceMap<T> mutableMap, Collection<T> toAdd) { for (T option : toAdd) { @SuppressWarnings("unchecked") Class<T> markerInterface = (Class<T>) option.getMarkerInterface(); mutableMap.putInstance(markerInterface, option); }/*from w w w. j a v a 2 s . c o m*/ }
From source file:org.opendaylight.didm.mininet.DidmMininetProviderImpl.java
public ClassToInstanceMap<RpcService> getDrivers(String deviceType) { Preconditions.checkNotNull(deviceType); Preconditions.checkArgument(deviceType.equals(MININET_DEVICE_TYPE), "Only the '{}' device type is supported!", MININET_DEVICE_TYPE); ClassToInstanceMap<RpcService> drivers = MutableClassToInstanceMap.create(); drivers.putInstance(OpenflowFeatureService.class, new OpenFlowDeviceDriver()); return drivers; }
From source file:org.opendaylight.didm.hp3800.Hp3800ModuleImpl.java
public ClassToInstanceMap<RpcService> getDrivers(String deviceType) { Preconditions.checkNotNull(deviceType); Preconditions.checkArgument(deviceType.equals(HP_DEVICE_TYPE), "Only the '{}' device type is supported!", HP_DEVICE_TYPE);/*from w w w .j a va2 s .c o m*/ ClassToInstanceMap<RpcService> drivers = MutableClassToInstanceMap.create(); drivers.putInstance(OpenflowFeatureService.class, new OpenFlowDeviceDriver(dataBroker, rpcRegistry)); return drivers; }
From source file:org.opendaylight.didm.ovs.DidmOVSProviderImpl.java
public ClassToInstanceMap<RpcService> getDrivers(String deviceType) { Preconditions.checkNotNull(deviceType); Preconditions.checkArgument(deviceType.equals(OVS_DEVICE_TYPE), "Only the '{}' device type is supported!", OVS_DEVICE_TYPE);/*w w w.j a va 2s .c o m*/ ClassToInstanceMap<RpcService> drivers = MutableClassToInstanceMap.create(); drivers.putInstance(OpenflowFeatureService.class, new OpenFlowDeviceDriver()); // obtain the flow and group service. SalFlowService salFlowService = rpcRegistry.getRpcService(SalFlowService.class); SalGroupService salGroupService = rpcRegistry.getRpcService(SalGroupService.class); drivers.putInstance(AtriumFlowObjectiveService.class, new AtriumFlowObjectiveDriver(salFlowService, salGroupService)); return drivers; }