List of usage examples for com.google.common.util.concurrent Futures immediateFuture
@CheckReturnValue public static <V> ListenableFuture<V> immediateFuture(@Nullable V value)
From source file:org.thingsboard.server.dao.timeseries.BaseTimeseriesService.java
@Override public ListenableFuture<List<TsKvEntry>> findLatest(TenantId tenantId, EntityId entityId, Collection<String> keys) { validate(entityId);/* www .j a v a 2 s. c o m*/ List<ListenableFuture<TsKvEntry>> futures = Lists.newArrayListWithExpectedSize(keys.size()); keys.forEach(key -> Validator.validateString(key, "Incorrect key " + key)); if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) { EntityView entityView = entityViewService.findEntityViewById(tenantId, (EntityViewId) entityId); List<String> filteredKeys = new ArrayList<>(keys); if (entityView.getKeys() != null && entityView.getKeys().getTimeseries() != null && !entityView.getKeys().getTimeseries().isEmpty()) { filteredKeys.retainAll(entityView.getKeys().getTimeseries()); } List<ReadTsKvQuery> queries = filteredKeys.stream().map(key -> { long endTs = entityView.getEndTimeMs() != 0 ? entityView.getEndTimeMs() : Long.MAX_VALUE; return new BaseReadTsKvQuery(key, entityView.getStartTimeMs(), endTs, 1, "DESC"); }).collect(Collectors.toList()); if (queries.size() > 0) { return timeseriesDao.findAllAsync(tenantId, entityView.getEntityId(), queries); } else { return Futures.immediateFuture(new ArrayList<>()); } } keys.forEach(key -> futures.add(timeseriesDao.findLatest(tenantId, entityId, key))); return Futures.allAsList(futures); }
From source file:org.opendaylight.didm.hp3800.OpenFlowDeviceDriver.java
@Override public Future<RpcResult<AdjustFlowOutput>> adjustFlow(AdjustFlowInput input) { Set<Flow> adjustedFlows = new HashSet<Flow>(); LOG.info("HP 3800 adjustFlow"); NodeRef nodeRef = input.getNode();//w w w . j a v a2s . c o m InstanceIdentifier<Node> nodePath = (InstanceIdentifier<Node>) nodeRef.getValue(); FlowModChassisV2 flowModDriver = new FlowModChassisV2(nodePath, dataBroker); org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.didm.drivers.openflow.rev150211.adjust.flow.input.Flow flow = input .getFlow(); org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow fb = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder( flow).build(); adjustedFlows = flowModDriver.adjustFlowMod(fb); //Test ARP flow using flow creator test code //FlowCreator flowCreator = new FlowCreator(); //Flow arpFlow = flowCreator.buildArpFlowMod(); //adjustedFlows = flowModDriver.adjustFlowMod(arpFlow); //Push flows to device SalFlowService salFlowService = rpcRegistry.getRpcService(SalFlowService.class); DriverUtil.install_flows(salFlowService, adjustedFlows, nodePath); //Send the output flow to the RPC listener List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.didm.drivers.openflow.rev150211.adjust.flow.output.Flow> adjustedOutputFlows = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.didm.drivers.openflow.rev150211.adjust.flow.output.Flow>(); for (Flow oFflow : adjustedFlows) { adjustedOutputFlows.add(new FlowBuilder(oFflow).build()); } AdjustFlowOutputBuilder outputBuilder = new AdjustFlowOutputBuilder(); outputBuilder.setFlow(adjustedOutputFlows); AdjustFlowOutput rpcResultType = outputBuilder.build(); return Futures .immediateFuture(RpcResultBuilder.<AdjustFlowOutput>status(true).withResult(rpcResultType).build()); }
From source file:org.apache.shindig.social.websockbackend.spi.WsNativeAlbumSPI.java
@Override public Future<Album> getAlbum(UserId userId, String appId, Set<String> fields, String albumId, SecurityToken token) throws ProtocolException { Album album = null;/*from ww w .j av a 2 s. c o m*/ // create query final WebsockQuery query = new WebsockQuery(EQueryType.PROCEDURE_CALL); query.setPayload(ShindigNativeQueries.GET_ALBUM_QUERY); // set parameters for method query.setParameter(ShindigNativeQueries.USER_ID, userId.getUserId(token)); query.setParameter(ShindigNativeQueries.APP_ID, appId); query.setParameter(ShindigNativeQueries.ALBUM_ID, albumId); if (fields != null) { final List<String> fieldList = new ArrayList<String>(fields); query.setParameter(ShindigNativeQueries.FIELD_LIST, fieldList); } final IQueryCallback result = this.fQueryHandler.sendQuery(query); SingleResult sResult = null; try { sResult = (SingleResult) result.get(); // TODO: proper not found exception if (sResult == null) { return null; } } catch (final Exception e) { e.printStackTrace(); this.fLogger.log(Level.SEVERE, "server error", e); throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "could not retrieve result", e); } @SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) sResult.getResults(); album = new AlbumDTO(map); return Futures.immediateFuture(album); }
From source file:org.apache.twill.internal.container.TwillContainerService.java
@Override public ListenableFuture<String> onReceived(final String messageId, final Message message) { LOG.debug("Message received: {} {}.", messageId, message); if (handleSecureStoreUpdate(message)) { return Futures.immediateFuture(messageId); }//from w w w. ja v a 2 s . com final SettableFuture<String> result = SettableFuture.create(); Command command = message.getCommand(); if (message.getType() == Message.Type.SYSTEM && "instances".equals(command.getCommand()) && command.getOptions().containsKey("count")) { context.setInstanceCount(Integer.parseInt(command.getOptions().get("count"))); } String commandStr = command.getCommand(); if (message.getType() == Message.Type.SYSTEM) { boolean handled = false; if (SystemMessages.SET_LOG_LEVEL.equals(commandStr)) { // The options is a map from logger name to log level. setLogLevels(command.getOptions()); handled = true; } else if (SystemMessages.RESET_LOG_LEVEL.equals(commandStr)) { // The options is a set of loggers to reset in the form of loggerName -> loggerName map. resetLogLevels(command.getOptions().keySet()); handled = true; } if (handled) { updateLiveNode(); return Futures.immediateFuture(messageId); } } commandExecutor.execute(new Runnable() { @Override public void run() { try { runnable.handleCommand(message.getCommand()); result.set(messageId); } catch (Exception e) { result.setException(e); } } }); return result; }
From source file:org.opendaylight.tsdr.collector.spi.CollectorSPIImpl.java
@Override public Future<RpcResult<Void>> insertTSDRLogRecord(InsertTSDRLogRecordInput input) { StoreTSDRLogRecordInputBuilder tsdrServiceInput = new StoreTSDRLogRecordInputBuilder(); List<TSDRLogRecord> records = new ArrayList<TSDRLogRecord>(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.tsdr.collector.spi.rev150915.inserttsdrlogrecord.input.TSDRLogRecord inputRec : input .getTSDRLogRecord()) {/*from w w w . ja va 2 s. c om*/ TSDRLogRecordBuilder rec = new TSDRLogRecordBuilder(); rec.setNodeID(inputRec.getNodeID()); rec.setRecordAttributes(inputRec.getRecordAttributes()); rec.setRecordFullText(inputRec.getRecordFullText()); rec.setRecordKeys(inputRec.getRecordKeys()); rec.setTimeStamp(inputRec.getTimeStamp()); rec.setIndex(inputRec.getIndex()); rec.setTSDRDataCategory(inputRec.getTSDRDataCategory()); records.add(rec.build()); } tsdrServiceInput.setTSDRLogRecord(records); logDataService.storeTSDRLogRecord(tsdrServiceInput.build()); return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); }
From source file:eu.point.bootstrapping.impl.BootstrappingServiceImpl.java
/** * The method which activates the bootstrapping application. * @param input The input to activate the bootstrapping application, boolean or false. * @return It returns a void future result. * @see ActivateApplicationInput/* w w w . ja v a 2 s . com*/ */ @Override public Future<RpcResult<Void>> activateApplication(ActivateApplicationInput input) { applicationActivated = input.isStatus(); LOG.info("Received input {}.", input); // if true then activate. if (applicationActivated) { LOG.info("Activating bootstrapping application."); IcnIdConfigurator.getInstance().addLinks(unconfiguredLinks); //IcnIdConfigurator.getInstance().addMultipleLinks(unconfiguredLinks); } // else de-activate. else { LOG.info("De-activating bootstrapping application."); } return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); }
From source file:org.apache.qpid.server.virtualhostnode.AbstractStandardVirtualHostNode.java
@Override protected ListenableFuture<Void> activate() { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Activating virtualhost node " + this); }/*from ww w . j a v a 2s. c om*/ getConfigurationStore().init(this); getConfigurationStore().upgradeStoreStructure(); getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.CREATED()); writeLocationEventLog(); getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_START()); VirtualHostStoreUpgraderAndRecoverer upgrader = new VirtualHostStoreUpgraderAndRecoverer(this); ConfiguredObjectRecord[] initialRecords = null; try { initialRecords = getInitialRecords(); } catch (IOException e) { throw new IllegalConfigurationException("Could not process initial configuration", e); } final boolean isNew = upgrader.upgradeAndRecover(getConfigurationStore(), initialRecords); if (initialRecords.length > 0) { setAttributes(Collections.<String, Object>singletonMap(VIRTUALHOST_INITIAL_CONFIGURATION, "{}")); } getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_COMPLETE()); QueueManagingVirtualHost<?> host = getVirtualHost(); if (host != null) { final QueueManagingVirtualHost<?> recoveredHost = host; final ListenableFuture<Void> openFuture; recoveredHost.setFirstOpening(isNew && initialRecords.length == 0); openFuture = Subject.doAs(getSubjectWithAddedSystemRights(), new PrivilegedAction<ListenableFuture<Void>>() { @Override public ListenableFuture<Void> run() { return recoveredHost.openAsync(); } }); return openFuture; } else { return Futures.immediateFuture(null); } }
From source file:producerstest.SimpleProducerModule.java
@Produces @IntoSet static ListenableFuture<String> setOfStrFutureElement() { return Futures.immediateFuture("set of str element"); }
From source file:org.thingsboard.server.dao.AbstractModelDao.java
protected ListenableFuture<T> findOneByStatementAsync(Statement statement) { if (statement != null) { statement.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()); ResultSetFuture resultSetFuture = getSession().executeAsync(statement); ListenableFuture<T> result = Futures.transform(resultSetFuture, new Function<ResultSet, T>() { @Nullable//from ww w . j a v a 2 s . c o m @Override public T apply(@Nullable ResultSet resultSet) { Result<T> result = getMapper().map(resultSet); if (result != null) { return result.one(); } else { return null; } } }); return result; } return Futures.immediateFuture(null); }
From source file:org.snlab.vxe.demo.opendaylight.impl.VxeOpenDaylightDemoProvider.java
@Override public Future<RpcResult<Void>> setupPath(SetupPathInput input) { Tasklet<VxeDemoTasklet> tasklet = factory.create(input.getSource(), input.getDestination()); tasklet.submit();/*from ww w .j a va2 s. c o m*/ return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); }