List of usage examples for java.util EnumSet allOf
public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType)
From source file:com.aionlightning.commons.utils.concurrent.RunnableStatsManager.java
public static void dumpClassStats(final SortBy sortBy) { final List<MethodStat> methodStats = new ArrayList<MethodStat>(); synchronized (RunnableStatsManager.class) { for (ClassStat classStat : classStats.values()) for (MethodStat methodStat : classStat.methodStats) if (methodStat.count > 0) methodStats.add(methodStat); }/*from w w w . j av a 2 s . co m*/ if (sortBy != null) Collections.sort(methodStats, sortBy.comparator); final List<String> lines = new ArrayList<String>(); lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"); lines.add("<entries>"); lines.add("\t<!-- This XML contains statistics about execution times. -->"); lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->"); final String[][] values = new String[SortBy.VALUES.length][methodStats.size()]; final int[] maxLength = new int[SortBy.VALUES.length]; for (int i = 0; i < SortBy.VALUES.length; i++) { final SortBy sort = SortBy.VALUES[i]; for (int k = 0; k < methodStats.size(); k++) { @SuppressWarnings("rawtypes") final Comparable c = sort.getComparableValueOf(methodStats.get(k)); final String value; if (c instanceof Number) value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue()); else value = String.valueOf(c); values[i][k] = value; maxLength[i] = Math.max(maxLength[i], value.length()); } } for (int k = 0; k < methodStats.size(); k++) { StringBuilder sb = new StringBuilder(); sb.append("\t<entry "); EnumSet<SortBy> set = EnumSet.allOf(SortBy.class); if (sortBy != null) { switch (sortBy) { case NAME: case METHOD: appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k], maxLength[SortBy.NAME.ordinal()]); set.remove(SortBy.NAME); appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k], maxLength[SortBy.METHOD.ordinal()]); set.remove(SortBy.METHOD); break; default: appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]); set.remove(sortBy); break; } } for (SortBy sort : SortBy.VALUES) if (set.contains(sort)) appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]); sb.append("/>"); lines.add(sb.toString()); } lines.add("</entries>"); PrintStream ps = null; try { ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log"); for (String line : lines) ps.println(line); } catch (Exception e) { log.warn("", e); } finally { IOUtils.closeQuietly(ps); } }
From source file:de.javakaffee.kryoserializers.KryoTest.java
@Test public void testCopyEnumSet() throws Exception { final EnumSet<?> set = EnumSet.allOf(Gender.class); final EnumSet<?> copy = _kryo.copy(set); assertDeepEquals(copy, set);//from www. j ava 2 s . co m }
From source file:com.hortonworks.streamline.webservice.StreamlineApplication.java
private void enableCORS(Environment environment, List<String> urlPatterns) { // Enable CORS headers final FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class); // Configure CORS parameters cors.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*"); cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Authorization,Content-Type,Accept,Origin"); cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "OPTIONS,GET,PUT,POST,DELETE,HEAD"); // Add URL mapping String[] urls = urlPatterns.toArray(new String[urlPatterns.size()]); cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, urls); }
From source file:com.rjuarez.webapp.tools.MethodSub.java
public static MethodSub fromString(final String value) { if (StringUtils.isNotBlank(value)) { for (final MethodSub method : EnumSet.allOf(MethodSub.class)) { if (value.equalsIgnoreCase(method.value)) { return method; }/*from ww w. j a va2s .c o m*/ } } // We've not found the type! throw new IllegalArgumentException("Method '" + value + "' not recognised"); }
From source file:com.linkedin.pinot.transport.perf.ScatterGatherPerfTester.java
private static Options buildCommandLineOptions() { Options options = new Options(); options.addOption(EXECUTION_MODE, true, "Execution Mode. One of " + EnumSet.allOf(ExecutionMode.class)); options.addOption(NUM_CLIENTS, true, "Number of Client instances. (Clients will not share connection-pool). Used only when execution mode is RUN_CLIENT or RUN_BOTH"); options.addOption(NUM_SERVERS, true, "Number of server instances. Used only when execution mode is RUN_SERVER or RUN_BOTH"); options.addOption(REQUEST_SIZE, true, "Request Size. Used only when execution mode is RUN_SERVER or RUN_BOTH"); options.addOption(RESPONSE_SIZE, true, "Response Size. Used only when execution mode is RUN_SERVER or RUN_BOTH"); options.addOption(NUM_REQUESTS, true, "Number of requests to be sent per Client instances. Used only when execution mode is RUN_CLIENT or RUN_BOTH"); options.addOption(SERVER_START_PORT, true, "Start port for server. If execution_mode == RUN_SERVER or RUN_BOTH, then, N (controlled by num_servers) servers will be started with port numbers monotonically incremented from this value. If execution_mode == RUN_CLIENT, then N servers are assumed to be running remotely and this client connects to them"); options.addOption(SYNC_REQUEST_DISPATCH, false, "Do we want to send requests synchronously (one by one requests and response per client). Set it to false to mimic production workflows"); options.addOption(SERVER_HOSTS, true, "Comma seperated list of remote hosts where the servers are assumed to be running with same ports (assigned from start_port_num)"); options.addOption(CONN_POOL_SIZE_PER_PEER, true, "Number of max active connections to be allowed"); options.addOption(NUM_RESPONSE_READERS, true, "Number of reponse reader threads per Client instances. Used only when execution mode is RUN_CLIENT or RUN_BOTH"); options.addOption(RESPONSE_LATENCY, true, "Induced Latency in server per request. Used only when execution mode is RUN_SERVER or RUN_BOTH"); return options; }
From source file:io.reappt.adapters.kafka.OutboundKafkaAdapter.java
public void start() { Properties kprops = new Properties(); kprops.put("acks", "1"); kprops.put("bootstrap.servers", kafkaBootstrapUrl); kprops.put("security.protocol", "SASL_SSL"); kprops.put("group.id", KafkaAdapter.DIFFUSION_KAFKA_CONSUMER_GROUP); producer = new KafkaProducer<>(kprops, new StringSerializer(), new StringSerializer()); final Topics topicsFeature = session.feature(Topics.class); topicsFeature.addFallbackTopicStream(topicStream); ClientControl clientControl = session.feature(ClientControl.class); AuthenticationControl authControl = session.feature(AuthenticationControl.class); authControl.setAuthenticationHandler("before-system-handler", EnumSet.allOf(SessionDetails.DetailType.class), authenticationHandler); // Listen to client events and publish to kafka clientControl.setSessionPropertiesListener(propertiesListener, Session.ALL_FIXED_PROPERTIES, Session.ALL_USER_PROPERTIES); // Get everything except the Diffusion publisher and the synthetic kafka topic topicsFeature.subscribe("?(?!(Diffusion|" + KafkaAdapter.DIFFUSION_KAFKA_ROOT_TOPIC + ")).*//", callback); }
From source file:org.wso2.carbon.bpel.core.ode.integration.store.Utils.java
public static List<Long> delete(String filter) { log.info("Instance filter for instance deletion:" + filter); final InstanceFilter instanceFilter = new InstanceFilter(filter); final List<Long> ret = new LinkedList<Long>(); try {/*from w w w. ja va 2 s. c o m*/ dbexec(new BpelDatabase.Callable<Object>() { public Object run(BpelDAOConnection conn) { Collection<ProcessInstanceDAO> instances = conn.instanceQuery(instanceFilter); for (ProcessInstanceDAO instance : instances) { instance.delete(EnumSet.allOf(ProcessConf.CLEANUP_CATEGORY.class), true); ret.add(instance.getInstanceId()); } return null; } }); } catch (Exception e) { String errMsg = "Exception during instance deletion. Filter: " + filter; log.error(errMsg, e); throw new ManagementException(errMsg, e); } return ret; }
From source file:org.apache.hadoop.hdfs.security.token.block.TestBlockToken.java
@Test public void testBlockTokenRpc() throws Exception { BlockTokenSecretManager sm = new BlockTokenSecretManager(true, blockKeyUpdateInterval, blockTokenLifetime); Token<BlockTokenIdentifier> token = sm.generateToken(block3, EnumSet.allOf(BlockTokenSecretManager.AccessMode.class)); ClientDatanodeProtocol mockDN = mock(ClientDatanodeProtocol.class); when(mockDN.getProtocolVersion(anyString(), anyLong())).thenReturn(ClientDatanodeProtocol.versionID); BlockTokenIdentifier id = sm.createIdentifier(); id.readFields(new DataInputStream(new ByteArrayInputStream(token.getIdentifier()))); doAnswer(new getLengthAnswer(sm, id)).when(mockDN).recoverBlock(any(Block.class), anyBoolean(), any(DatanodeInfo[].class)); final Server server = RPC.getServer(mockDN, ADDRESS, 0, 5, true, conf, sm); server.start();/*from w w w .ja v a 2 s .c o m*/ final InetSocketAddress addr = NetUtils.getConnectAddress(server); final UserGroupInformation ticket = UserGroupInformation.createRemoteUser(block3.toString()); ticket.addToken(token); ClientDatanodeProtocol proxy = null; try { proxy = (ClientDatanodeProtocol) RPC.getProxy(ClientDatanodeProtocol.class, ClientDatanodeProtocol.versionID, addr, ticket, conf, NetUtils.getDefaultSocketFactory(conf)); LocatedBlock lb = proxy.recoverBlock(block3, true, null); assertEquals(block3.getBlockId(), lb.getBlock().getBlockId()); } finally { server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } } }
From source file:org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryManagerOnTimelineStore.java
private ApplicationAttemptReport getApplicationAttempt(ApplicationAttemptId appAttemptId, boolean checkACLs) throws YarnException, IOException { if (checkACLs) { ApplicationReportExt app = getApplication(appAttemptId.getApplicationId(), ApplicationReportField.USER_AND_ACLS); checkAccess(app);//w ww . j a v a 2 s. c om } TimelineEntity entity = timelineDataManager.getEntity(AppAttemptMetricsConstants.ENTITY_TYPE, appAttemptId.toString(), EnumSet.allOf(Field.class), UserGroupInformation.getLoginUser()); if (entity == null) { throw new ApplicationAttemptNotFoundException( "The entity for application attempt " + appAttemptId + " doesn't exist in the timeline store"); } else { return convertToApplicationAttemptReport(entity); } }
From source file:com.nike.cerberus.cli.CerberusRunner.java
private void printCustomUsage() { StringBuilder sb = new StringBuilder("Usage: cerberus [options] [command] [command options]\n"); String indent = ""; //indenting//from w w w . ja va 2 s .co m int descriptionIndent = 6; int indentCount = indent.length() + descriptionIndent; int longestName = 0; List<ParameterDescription> sorted = Lists.newArrayList(); for (ParameterDescription pd : commander.getParameters()) { if (!pd.getParameter().hidden()) { sorted.add(pd); // + to have an extra space between the name and the description int length = pd.getNames().length() + 2; if (length > longestName) { longestName = length; } } } sb.append(indent).append(" Options:\n"); sorted.stream().sorted((p0, p1) -> p0.getLongestName().compareTo(p1.getLongestName())).forEach(pd -> { WrappedParameter parameter = pd.getParameter(); sb.append(indent).append(" " + (parameter.required() ? "* " : " ") + Chalk.on(pd.getNames()).green().bold().toString() + "\n"); wrapDescription(sb, indentCount, s(indentCount) + pd.getDescription()); Object def = pd.getDefault(); if (def != null) { String displayedDef = StringUtils.isBlank(def.toString()) ? "<empty string>" : def.toString(); sb.append("\n" + s(indentCount)) .append("Default: " + Chalk.on(displayedDef).yellow().bold().toString()); } Class<?> type = pd.getParameterized().getType(); if (type.isEnum()) { String values = EnumSet.allOf((Class<? extends Enum>) type).toString(); sb.append("\n" + s(indentCount)) .append("Possible Values: " + Chalk.on(values).yellow().bold().toString()); } sb.append("\n"); }); System.out.println(sb.toString()); System.out.print(" "); printCommands(); }