Java Code Examples for com.google.common.base.Function

The following examples show how to use com.google.common.base.Function. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: bistoury   Source File: SQLiteStoreImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static String getDeleteSql(List<String> keys) {
    List<String> newKeys = Lists.transform(keys, new Function<String, String>() {
        @Override
        public String apply(String input) {
            return "'" + input + "'";
        }
    });
    StringBuilder sb = new StringBuilder("delete from bistoury where b_key in (");

    Joiner joiner = Joiner.on(",").skipNulls();

    HashSet<String> set = Sets.newHashSet(newKeys);
    if (set.size() == 0) {
        return null;
    }

    joiner.appendTo(sb, set);
    sb.append(")");
    return sb.toString();
}
 
Example 2
Source Project: arcusplatform   Source File: I18NServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ClientFuture<LoadLocalizedStringsResponse> loadLocalizedStrings(Set<String> strings, String s) {
 ClientRequest request = new ClientRequest();
 Map<String, Object> elements = new HashMap<>();
 elements.put("bundleNames", strings);
 elements.put("locale", s);
 request.setAttributes(elements);
 request.setTimeoutMs(10000);
 request.setAddress(getAddress());
 request.setCommand(I18NService.CMD_LOADLOCALIZEDSTRINGS);
 request.setConnectionURL(client.getConnectionURL());
 request.setRestfulRequest(true);

    return Futures.transform(client.request(request), new Function<ClientEvent, LoadLocalizedStringsResponse>() {
        @Override
        public LoadLocalizedStringsResponse apply(ClientEvent input) {
            return (new LoadLocalizedStringsResponse(input));
        }
    });
}
 
Example 3
Source Project: arcusplatform   Source File: ProductCatalogServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ClientFuture<GetProductCatalogResponse> getProductCatalog(String place) {
	GetProductCatalogRequest request = new GetProductCatalogRequest();
	request.setAddress(getAddress());
	request.setRestfulRequest(true);
	request.setPlace(place);

	ClientFuture<ClientEvent> result = client.request(request);

	return Futures.transform(result, new Function<ClientEvent, GetProductCatalogResponse>() {
		@Override
		public GetProductCatalogResponse apply(ClientEvent input) {
			GetProductCatalogResponse response = new GetProductCatalogResponse(input);
			return response;
		}
	});
}
 
Example 4
@Override
public Iterator<GTRecord> iterator() {
    Iterator<PartitionResultIterator> iterators = Iterators.transform(blocks,
            new Function<byte[], PartitionResultIterator>() {
                public PartitionResultIterator apply(byte[] input) {
                    return new PartitionResultIterator(input, info, columns);
                }
            });

    if (!needSorted) {
        logger.debug("Using Iterators.concat to pipeline partition results");
        return Iterators.concat(iterators);
    }

    return new SortMergedPartitionResultIterator(iterators, info, GTRecord.getComparator(groupByDims));
}
 
Example 5
Source Project: ghidra   Source File: GraphViewerUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a rectangle that contains all give vertices
 * 
 * @param viewer the viewer containing the UI
 * @param vertices the vertices 
 * @return a rectangle that contains all give vertices
 */
public static <V, E> Rectangle getBoundsForVerticesInLayoutSpace(
		VisualizationServer<V, E> viewer, Collection<V> vertices) {

	Layout<V, E> layout = viewer.getGraphLayout();
	RenderContext<V, E> renderContext = viewer.getRenderContext();
	Function<? super V, Shape> shapeTransformer = renderContext.getVertexShapeTransformer();

	Function<V, Rectangle> transformer = v -> {

		Shape shape = shapeTransformer.apply(v);
		Rectangle bounds = shape.getBounds();
		Point2D point = layout.apply(v);
		bounds.setLocation(new Point((int) point.getX(), (int) point.getY()));
		return bounds;
	};
	return getBoundsForVerticesInLayoutSpace(vertices, transformer);
}
 
Example 6
Source Project: arcusplatform   Source File: RuleServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ClientFuture<GetRuleTemplatesByCategoryResponse> getRuleTemplatesByCategory(String placeId, String category) {
   ClientRequest request = buildRequest(
         RuleService.CMD_GETRULETEMPLATESBYCATEGORY,
         ImmutableMap.<String,Object>of(GetRuleTemplatesByCategoryRequest.ATTR_PLACEID, placeId,
                                        GetRuleTemplatesByCategoryRequest.ATTR_CATEGORY, category));
   ClientFuture<ClientEvent> result = client.request(request);
   return Futures.transform(result, new Function<ClientEvent, GetRuleTemplatesByCategoryResponse>() {
      @Override
      public GetRuleTemplatesByCategoryResponse apply(ClientEvent input) {
         GetRuleTemplatesByCategoryResponse response = new GetRuleTemplatesByCategoryResponse(input);
         IrisClientFactory.getModelCache().addOrUpdate(response.getRuleTemplates());
         return response;
      }
   });
}
 
Example 7
Source Project: arcusplatform   Source File: Main.java    License: Apache License 2.0 6 votes vote down vote up
private static Predicate<Entry> or(List<String> queries, Function<String, Predicate<Entry>> transform) {
   Preconditions.checkNotNull(transform);
   if(queries == null || queries.isEmpty()) {
      return Predicates.alwaysTrue();
   }
   List<Predicate<Entry>> predicates = new ArrayList<>(queries.size());
   for(String query: queries) {
      Predicate<Entry> p = transform.apply(query);
      if(p != null) {
         predicates.add(p);
      }
   }
   if(predicates.isEmpty()) {
      return Predicates.alwaysTrue();
   }
   else if(predicates.size() == 1) {
      return predicates.get(0);
   }
   else {
      return Predicates.or(predicates);
   }
}
 
Example 8
Source Project: arcusplatform   Source File: SessionServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ClientFuture<LockDeviceResponse> lockDevice(String deviceIdentifier, String reason) {
	LockDeviceRequest request = new LockDeviceRequest();
     request.setAddress(getAddress());
     request.setRestfulRequest(true);
     request.setDeviceIdentifier(deviceIdentifier);
     request.setReason(reason);

     ClientFuture<ClientEvent> result = client.request(request);
     return Futures.transform(result, new Function<ClientEvent, LockDeviceResponse>() {
        @Override
        public LockDeviceResponse apply(ClientEvent response) {
           return new LockDeviceResponse(response);
        }
     });
}
 
Example 9
Source Project: arcusplatform   Source File: RuleServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ClientFuture<ListRuleTemplatesResponse> listRuleTemplates(String placeId) {
   ClientRequest request = buildRequest(
         RuleService.CMD_LISTRULETEMPLATES,
         ImmutableMap.<String, Object>of(ListRuleTemplatesRequest.ATTR_PLACEID, placeId)
   );
   ClientFuture<ClientEvent> result = client.request(request);
   return Futures.transform(result, new Function<ClientEvent, ListRuleTemplatesResponse>() {
      @Override
      public ListRuleTemplatesResponse apply(ClientEvent input) {
         ListRuleTemplatesResponse response = new ListRuleTemplatesResponse(input);
         IrisClientFactory.getModelCache().retainAll(RuleTemplate.NAMESPACE, response.getRuleTemplates());
         return response;
      }

   });
}
 
Example 10
Source Project: sharding-jdbc-1.5.1   Source File: YamlIntegratedTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithDataSource() throws SQLException, URISyntaxException, IOException {
    File yamlFile = new File(YamlIntegratedTest.class.getResource(filePath).toURI());
    DataSource dataSource;
    if (hasDataSource) {
        dataSource = new YamlShardingDataSource(yamlFile);
    } else {
        dataSource = new YamlShardingDataSource(Maps.asMap(Sets.newHashSet("db0", "db1"), new Function<String, DataSource>() {
            @Override
            public DataSource apply(final String key) {
                return createDataSource(key);
            }
        }), yamlFile);
    }
    
    try (Connection conn = dataSource.getConnection();
         Statement stm = conn.createStatement()) {
        stm.executeQuery("SELECT * FROM t_order");
        stm.executeQuery("SELECT * FROM t_order_item");
        stm.executeQuery("SELECT * FROM config");
    }
}
 
Example 11
Source Project: arcusplatform   Source File: SessionServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ClientFuture<LogResponse> log(String category, String code, String message) {
   LogRequest request = new LogRequest();
   request.setAddress(getAddress());
   request.setRestfulRequest(false);

   request.setCategory(category);
   request.setCode(code);
   request.setMessage(message);

   ClientFuture<ClientEvent> result = client.request(request);
   return Futures.transform(result, new Function<ClientEvent, LogResponse>() {
      @Override
      public LogResponse apply(ClientEvent input) {
         return new LogResponse(input);
      }
   });
}
 
Example 12
Source Project: qconfig   Source File: NotifyServiceImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void notifyPushIp(final ConfigMeta meta, final long version, List<Host> destinations) {
    List<String> serverUrls = getServerUrls();
    if (serverUrls.isEmpty()) {
        logger.warn("notify push server, {}, version: {}, but no server, {}", meta, version, destinations);
        return;
    }

    String uri = this.notifyIpPushUrl;
    logger.info("notify push server, {}, version: {}, uri: {}, servers: {}, {}", meta, version, uri, serverUrls, destinations);
    StringBuilder sb = new StringBuilder();
    for (Host item : destinations) {
        sb.append(item.getIp()).append(Constants.LINE);
    }
    final String destinationsStr = sb.toString();

    doNotify(serverUrls, uri, "admin/notifyIpPush", new Function<String, Request>() {
        @Override
        public Request apply(String url) {
            AsyncHttpClient.BoundRequestBuilder builder = getBoundRequestBuilder(url, meta, version, destinationsStr);
            return builder.build();
        }
    });
}
 
Example 13
Source Project: arcusplatform   Source File: SchedulerServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ClientFuture<ScheduleCommandsResponse> scheduleCommands(
      String target, String group, List<Map<String, Object>> commands) {
   ScheduleCommandsRequest request = new ScheduleCommandsRequest();
   request.setAddress(getAddress());
   request.setTarget(target);
   request.setGroup(group);
   request.setCommands(commands);
   
   ClientFuture<ClientEvent> result = client.request(request);
   return Futures.transform(result, new Function<ClientEvent, ScheduleCommandsResponse>() {
      @Override
      public ScheduleCommandsResponse apply(ClientEvent response) {
         return new ScheduleCommandsResponse(response);
      }
   });
}
 
Example 14
Source Project: arcusplatform   Source File: EventResolverFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Function<? super SubsystemEventAndContext, ?> getResolverForParameter(Method method, Type parameter, Annotation[] annotations) {
   if(parameter instanceof Class) {
      Class<?> type = (Class<?>) parameter;
      if(type.isAssignableFrom(eventType)) {
         return GetEvent;
      }
      if(type.isAssignableFrom(Address.class)) {
         return GetAddress;
      }
      if(type.equals(Model.class)) {
         return GetModel;
      }
   }
   else if(parameter instanceof ParameterizedType) {
      return getResolverForParameter(method, ((ParameterizedType) parameter).getRawType(), annotations);
   }
   return super.getResolverForParameter(method, parameter, annotations);
}
 
Example 15
private static AemContext createContext(String contentPath) {
    return new AemContext(
        (AemContextCallback) context -> {
            // Load page structure
            context.load().json(contentPath, "/content");

            UrlProviderImpl urlProvider = new UrlProviderImpl();
            urlProvider.activate(new MockUrlProviderConfiguration());
            context.registerService(UrlProvider.class, urlProvider);

            context.registerInjectActivateService(new SearchFilterServiceImpl());
            context.registerInjectActivateService(new SearchResultsServiceImpl());
            context.registerAdapter(Resource.class, ComponentsConfiguration.class,
                (Function<Resource, ComponentsConfiguration>) input -> MOCK_CONFIGURATION_OBJECT);
        },
        ResourceResolverType.JCR_MOCK);
}
 
Example 16
Source Project: arcusplatform   Source File: RegexDfaByte.java    License: Apache License 2.0 6 votes vote down vote up
public <T> RegexDfaByte<T> transform(Function<V,T> transformer) {
   IdentityHashMap<State<V>,State<T>> stateMap = new IdentityHashMap<>();

   State<T> newInitialState = null;
   for (State<V> state : states) {
      State<T> transformed = state.transform(transformer);
      if (transformed.isInitialState()) {
         newInitialState = transformed;
      }

      stateMap.put(state, transformed);
   }

   for (Map.Entry<State<V>,State<T>> entry : stateMap.entrySet()) {
      State<V> oldState = entry.getKey();
      State<T> newState = entry.getValue();
      newState.setTransitions(oldState.getTransitions().transform(stateMap,transformer));
   }

   if (newInitialState == null) {
      throw new IllegalStateException("no initial state");
   }

   Set<State<T>> newStates = ImmutableSet.copyOf(stateMap.values());
   return new RegexDfaByte<T>(newInitialState, newStates);
}
 
Example 17
Source Project: arcusplatform   Source File: RuleTemplateRequestor.java    License: Apache License 2.0 6 votes vote down vote up
public ListenableFuture<List<Map<String, Object>>> listTemplatesForPlace(UUID placeId) {
	MessageBody listTemplates =
		ListRuleTemplatesRequest
			.builder()
			.withPlaceId(placeId.toString())
			.build();
	PlatformMessage request =
		PlatformMessage
			.request(RuleService.ADDRESS)
			.from(PairingDeviceService.ADDRESS)
			.withCorrelationId(IrisUUID.randomUUID().toString())
			.withPlaceId(placeId)
			.withPopulation(populationCacheMgr.getPopulationByPlaceId(placeId))
			.withPayload(listTemplates)
			.create();
	return 
		Futures.transform(
			requestor.request(request), 
			(Function<PlatformMessage, List<Map<String, Object>>>) (message) -> ListRuleTemplatesResponse.getRuleTemplates(message.getValue(), ImmutableList.of()),
			MoreExecutors.directExecutor()
		);
}
 
Example 18
Source Project: arcusplatform   Source File: SessionServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ClientFuture<SetActivePlaceResponse> setActivePlace(String placeId) {
   SetActivePlaceRequest request = new SetActivePlaceRequest();
   request.setAddress(getAddress());
   request.setRestfulRequest(false);

   request.setPlaceId(placeId);

   ClientFuture<ClientEvent> result = client.request(request);
   return Futures.transform(result, new Function<ClientEvent, SetActivePlaceResponse>() {
      @Override
      public SetActivePlaceResponse apply(ClientEvent input) {
         return new SetActivePlaceResponse(input);
      }
   });
}
 
Example 19
Source Project: arcusplatform   Source File: HubAlarmSubsystem.java    License: Apache License 2.0 6 votes vote down vote up
@Request(SubsystemCapability.SuspendRequest.NAME)
public void suspend(final SubsystemContext<AlarmSubsystemModel> context, PlatformMessage request) {
   if(!AlarmUtil.isActive(context)) {
      return;
   }

   assertValidSuspendState(context);

   AlarmUtil.sendHubRequest(context, request, HubAlarmCapability.SuspendRequest.instance(),
      new Function<PlatformMessage, MessageBody>() {
         @Override
         public MessageBody apply(PlatformMessage input) {
            context.model().setState(SubsystemCapability.STATE_SUSPENDED);
            context.model().setAvailable(false);
            return SubsystemCapability.SuspendResponse.instance();
         }
      }
   );
}
 
Example 20
private static AemContext createContext(String contentPath) {
    return new AemContext(
        (AemContextCallback) context -> {
            // Load page structure
            context.load().json(contentPath, "/content");
            context.registerService(ImplementationPicker.class, new ResourceTypeImplementationPicker());

            UrlProviderImpl urlProvider = new UrlProviderImpl();
            urlProvider.activate(new MockUrlProviderConfiguration());
            context.registerService(UrlProvider.class, urlProvider);

            context.registerInjectActivateService(new SearchFilterServiceImpl());
            context.registerInjectActivateService(new SearchResultsServiceImpl());
            context.registerAdapter(Resource.class, ComponentsConfiguration.class,
                (Function<Resource, ComponentsConfiguration>) input -> MOCK_CONFIGURATION_OBJECT);
        },
        ResourceResolverType.JCR_MOCK);
}
 
Example 21
Source Project: arcusplatform   Source File: AnnotatedSubsystem.java    License: Apache License 2.0 6 votes vote down vote up
protected final void handleRequest(MessageReceivedEvent event, SubsystemContext<M> context) {
   PlatformMessage request = event.getMessage();
   String type = request.getMessageType();
   Function<SubsystemEventAndContext, MessageBody> handler = requestHandlers.get(type);
   if(handler == null) {
      context.sendResponse(request, Errors.invalidRequest(type));
   }
   else {
      MessageBody response;
      try {
         response = handler.apply(new SubsystemEventAndContext(context, event));
      }
      catch(Exception e) {
         context.logger().warn("Error handling request {}", request, e);
         response = Errors.fromException(e);
      }
      if(response != null) {
         context.sendResponse(request, response);
      }
   }
}
 
Example 22
Source Project: arcusplatform   Source File: PlatformDispatcherFactory.java    License: Apache License 2.0 5 votes vote down vote up
private <R> Consumer<PlatformMessage> wrapConsumer(Object ths, Method m, Predicate<Address> p, ArgumentResolverFactory<PlatformMessage, ?> resolver) {
   ArgumentResolverFactory<PlatformMessage, ?> factory =
         this.resolver == null ?
               resolver :
               Resolvers.chain(resolver, (ArgumentResolverFactory) this.resolver);
   Function<PlatformMessage, ?> h = 
         Methods
            .buildInvokerFactory(factory)
            .build()
            .wrapWithThis(m, ths);
   return (message) -> { if(p.apply(message.getSource())) { h.apply(message); } };
}
 
Example 23
Source Project: arcusplatform   Source File: PlaceServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ClientFuture<ListTimezonesResponse> listTimezones() {
   ListTimezonesRequest request = new ListTimezonesRequest();
   request.setAddress(getAddress());
   request.setRestfulRequest(true);

   ClientFuture<ClientEvent> result = client.request(request);
   return Futures.transform(result, new Function<ClientEvent, ListTimezonesResponse>() {
      @Override
      public ListTimezonesResponse apply(ClientEvent input) {
         ListTimezonesResponse response = new ListTimezonesResponse(input);
         return response;
      }
   });
}
 
Example 24
Source Project: qconfig   Source File: ListeningClientsServiceImpl.java    License: MIT License 5 votes vote down vote up
private <T> ListenableFuture<Set<T>> parseData(final List<String> serverUrls, final List<ListenableFuture<Response>> futures, final Function<String, Set<T>> parseFunction) {
    final SettableFuture<Set<T>> result = SettableFuture.create();
    ListenableFuture<List<Response>> responseFuture = Futures.successfulAsList(futures);
    Futures.addCallback(responseFuture, new FutureCallback<List<Response>>() {
        @Override
        public void onSuccess(List<Response> responses) {
            Set<T> allClients = Sets.newHashSet();
            for (int i = 0; i < responses.size(); ++i) {
                Response response = responses.get(i);
                if (response != null && response.getStatusCode() == HttpStatus.SC_OK) {
                    String responseStr = null;
                    try {
                        responseStr = response.getResponseBody("utf8");
                    } catch (IOException e) {
                        logger.warn("get listening client response from server error", e);
                    }
                    allClients.addAll(parseFunction.apply(responseStr));
                } else {
                    logger.warn("get listening clients error with {}", serverUrls.get(i));
                }
            }
            result.set(allClients);
        }

        @Override
        public void onFailure(Throwable t) {
            result.setException(t);
        }
    }, executor);

    return result;
}
 
Example 25
@Test
public void testRetrieveMetadata() {
    context.registerAdapter(Resource.class, GraphqlClient.class, (Function<Resource, GraphqlClient>) input -> input.getValueMap().get(
        "cq:graphqlClient") != null ? graphqlClient : null);

    final List<FilterAttributeMetadata> filterAttributeMetadata = searchFilterServiceUnderTest
        .retrieveCurrentlyAvailableCommerceFilters(page);

    assertThat(filterAttributeMetadata).hasSize(29);

    // Range type
    FilterAttributeMetadata price = filterAttributeMetadata.stream().filter(f -> f.getAttributeCode().equals("price")).findFirst()
        .get();
    assertThat(price.getFilterInputType()).isEqualTo("FilterRangeTypeInput");
    assertThat(price.getAttributeType()).isEqualTo("Float");
    assertThat(price.getAttributeInputType()).isEqualTo("price");

    // Equal type for string
    FilterAttributeMetadata material = filterAttributeMetadata.stream().filter(f -> f.getAttributeCode().equals("material")).findFirst()
        .get();
    assertThat(material.getFilterInputType()).isEqualTo("FilterEqualTypeInput");
    assertThat(material.getAttributeType()).isEqualTo("String");
    assertThat(material.getAttributeInputType()).isEqualTo("multiselect");

    // Equal type for int/boolean
    FilterAttributeMetadata newAttr = filterAttributeMetadata.stream().filter(f -> f.getAttributeCode().equals("new")).findFirst()
        .get();
    assertThat(newAttr.getFilterInputType()).isEqualTo("FilterEqualTypeInput");
    assertThat(newAttr.getAttributeType()).isEqualTo("Int");
    assertThat(newAttr.getAttributeInputType()).isEqualTo("boolean");
}
 
Example 26
Source Project: bistoury   Source File: VarVersionsGraph.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static void addToReversePostOrderListIterative(VarVersionNode root, List<? super VarVersionNode> lst, Set<? super VarVersionNode> setVisited) {
    Map<VarVersionNode, List<VarVersionEdge>> mapNodeSuccs = new HashMap<>();
    LinkedList<VarVersionNode> stackNode = new LinkedList<>();
    LinkedList<Integer> stackIndex = new LinkedList<>();

    stackNode.add(root);
    stackIndex.add(0);

    while (!stackNode.isEmpty()) {
        VarVersionNode node = stackNode.getLast();
        int index = stackIndex.removeLast();

        setVisited.add(node);

        //List<VarVersionEdge> lstSuccs = mapNodeSuccs.computeIfAbsent(node, n -> new ArrayList<>(n.succs));
        List<VarVersionEdge> lstSuccs = Map827.computeIfAbsent(mapNodeSuccs, node, new Function<VarVersionNode, List<VarVersionEdge>>() {
            @Override
            public List<VarVersionEdge> apply(VarVersionNode input) {
                return new ArrayList<>(input.succs);
            }
        });
        for (; index < lstSuccs.size(); index++) {
            VarVersionNode succ = lstSuccs.get(index).dest;

            if (!setVisited.contains(succ)) {
                stackIndex.add(index + 1);
                stackNode.add(succ);
                stackIndex.add(0);
                break;
            }
        }

        if (index == lstSuccs.size()) {
            lst.add(0, node);
            stackNode.removeLast();
        }
    }
}
 
Example 27
private String[] enumerateDictInfoList(List<DictionaryInfo> dictionaryInfoList, String dataType) throws IOException {
    List<Dictionary<String>> dictList = Lists.transform(dictionaryInfoList, new Function<DictionaryInfo, Dictionary<String>>() {
        @Nullable
        @Override
        public Dictionary<String> apply(@Nullable DictionaryInfo input) {
            return input.dictionaryObject;
        }
    });
    enumerator = new MultipleDictionaryValueEnumerator(DataType.getType(dataType), dictList);
    List<String> values = new ArrayList<>();
    while (enumerator.moveNext()) {
        values.add(enumerator.current());
    }
    return values.toArray(new String[0]);
}
 
Example 28
Source Project: qconfig   Source File: LogServiceImpl.java    License: MIT License 5 votes vote down vote up
private void initQueue() {
    selectBasedVersionQueue = new LinkedBlockingQueue<>(logQueueCapacity);
    configLogSaveQueue = new LinkedBlockingQueue<>(logQueueCapacity);
    configUsedLogSaveQueue = new LinkedBlockingQueue<>(logQueueCapacity);

    logEntryQueueArray = new LinkedBlockingQueue[]{selectBasedVersionQueue, configLogSaveQueue, configUsedLogSaveQueue};
    logEntryFunctionArray = new Function[]{
            new SelectBasedVersionFunction(configDao),
            new ConfigLogSaveFunction(configLogDao),
            new ConfigUsedLogSaveFunction(configUsedLogDao)
    };
}
 
Example 29
Source Project: arcusplatform   Source File: ActionList.java    License: Apache License 2.0 5 votes vote down vote up
public Builder addAction(Action action, @Nullable Function<ActionContext, ActionContext> wrapper) {
   Preconditions.checkNotNull(action, "action may not be null");
   if(wrapper == null) {
      wrapper = Functions.<ActionContext>identity();
   }
   actions.add(new Entry(action, wrapper));
   return this;
}
 
Example 30
Source Project: qconfig   Source File: TaskStatusVo.java    License: MIT License 5 votes vote down vote up
public Builder setBatchesAllocation(Map<Integer, List<Host>> batches) {
    Map<Integer, List<Host>> result = Maps.newHashMapWithExpectedSize(batches.size());
    for (Map.Entry<Integer, List<Host>> batch : batches.entrySet()) {
        result.put(batch.getKey(), Lists.transform(batch.getValue(), new Function<Host, Host>() {
            @Override
            public Host apply(Host host) {
                return new Host(host.getIp());
            }
        }));
    }

    this.batchesAllocation = result;
    return this;
}