List of usage examples for java.util Properties put
@Override public synchronized Object put(Object key, Object value)
From source file:MainClass.java
public static void main(String[] args) { if (args.length != 4) { System.out.println("usage: java msgmultisend <to> <from> <smtp> true|false"); return;/*from w w w .j a v a2 s . com*/ } String to = args[0]; String from = args[1]; String host = args[2]; boolean debug = Boolean.valueOf(args[3]).booleanValue(); // create some properties and get the default Session Properties props = new Properties(); props.put("mail.smtp.host", host); Session session = Session.getInstance(props, null); session.setDebug(debug); try { // create a message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject("JavaMail APIs Multipart Test"); msg.setSentDate(new Date()); // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(msgText1); // create and fill the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // Use setText(text, charset), to show it off ! mbp2.setText(msgText2, "us-ascii"); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); // send the message Transport.send(msg); } catch (MessagingException mex) { mex.printStackTrace(); Exception ex = null; if ((ex = mex.getNextException()) != null) { ex.printStackTrace(); } } }
From source file:kafka.examples.producer.BasicProducerExample.java
public static void main(String[] args) { ArgumentParser parser = argParser(); try {//from w ww . ja va 2 s .c o m Namespace res = parser.parseArgs(args); /* parse args */ String brokerList = res.getString("bootstrap.servers"); String topic = res.getString("topic"); Boolean syncSend = res.getBoolean("syncsend"); long noOfMessages = res.getLong("messages"); long delay = res.getLong("delay"); String messageType = res.getString("messagetype"); Properties producerConfig = new Properties(); producerConfig.put("bootstrap.servers", brokerList); producerConfig.put("client.id", "basic-producer"); producerConfig.put("acks", "all"); producerConfig.put("retries", "3"); producerConfig.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); producerConfig.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); SimpleProducer<byte[], byte[]> producer = new SimpleProducer<>(producerConfig, syncSend); for (int i = 0; i < noOfMessages; i++) { producer.send(topic, getKey(i), getEvent(messageType, i)); try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } producer.close(); } catch (ArgumentParserException e) { if (args.length == 0) { parser.printHelp(); System.exit(0); } else { parser.handleError(e); System.exit(1); } } }
From source file:kafka.examples.producer.CustomPartitionerExample.java
public static void main(String[] args) { ArgumentParser parser = argParser(); try {//from w w w . j a va2 s . com Namespace res = parser.parseArgs(args); /* parse args */ String brokerList = res.getString("bootstrap.servers"); String topic = res.getString("topic"); Boolean syncSend = res.getBoolean("syncsend"); long noOfMessages = res.getLong("messages"); long delay = res.getLong("delay"); String messageType = res.getString("messagetype"); Properties producerConfig = new Properties(); producerConfig.put("bootstrap.servers", brokerList); producerConfig.put("client.id", "basic-producer"); producerConfig.put("acks", "all"); producerConfig.put("retries", "3"); producerConfig.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); producerConfig.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); producerConfig.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, "kafka.examples.producer.CustomPartitioner"); SimpleProducer<byte[], byte[]> producer = new SimpleProducer<>(producerConfig, syncSend); for (int i = 0; i < noOfMessages; i++) { producer.send(topic, getKey(i), getEvent(messageType, i)); try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } producer.close(); } catch (ArgumentParserException e) { if (args.length == 0) { parser.printHelp(); System.exit(0); } else { parser.handleError(e); System.exit(1); } } }
From source file:com.datis.kafka.stream.PageViewUntypedDemo.java
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-pageview-untyped"); props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181"); props.put(StreamsConfig.TIMESTAMP_EXTRACTOR_CLASS_CONFIG, JsonTimestampExtractor.class); // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); KStreamBuilder builder = new KStreamBuilder(); final Serializer<JsonNode> jsonSerializer = new JsonSerializer(); final Deserializer<JsonNode> jsonDeserializer = new JsonDeserializer(); final Serde<JsonNode> jsonSerde = Serdes.serdeFrom(jsonSerializer, jsonDeserializer); KStream<String, JsonNode> views = builder.stream(Serdes.String(), jsonSerde, "streams-pageview-input"); KTable<String, JsonNode> users = builder.table(Serdes.String(), jsonSerde, "streams-userprofile-input"); KTable<String, String> userRegions = users.mapValues(new ValueMapper<JsonNode, String>() { @Override/*w w w. j a va 2s . co m*/ public String apply(JsonNode record) { return record.get("region").textValue(); } }); KStream<JsonNode, JsonNode> regionCount = views .leftJoin(userRegions, new ValueJoiner<JsonNode, String, JsonNode>() { @Override public JsonNode apply(JsonNode view, String region) { ObjectNode jNode = JsonNodeFactory.instance.objectNode(); return jNode.put("user", view.get("user").textValue()) .put("page", view.get("page").textValue()) .put("region", region == null ? "UNKNOWN" : region); } }).map(new KeyValueMapper<String, JsonNode, KeyValue<String, JsonNode>>() { @Override public KeyValue<String, JsonNode> apply(String user, JsonNode viewRegion) { return new KeyValue<>(viewRegion.get("region").textValue(), viewRegion); } }) .countByKey(TimeWindows.of("GeoPageViewsWindow", 7 * 24 * 60 * 60 * 1000L).advanceBy(1000), Serdes.String()) // TODO: we can merge ths toStream().map(...) with a single toStream(...) .toStream().map(new KeyValueMapper<Windowed<String>, Long, KeyValue<JsonNode, JsonNode>>() { @Override public KeyValue<JsonNode, JsonNode> apply(Windowed<String> key, Long value) { ObjectNode keyNode = JsonNodeFactory.instance.objectNode(); keyNode.put("window-start", key.window().start()).put("region", key.key()); ObjectNode valueNode = JsonNodeFactory.instance.objectNode(); valueNode.put("count", value); return new KeyValue<>((JsonNode) keyNode, (JsonNode) valueNode); } }); // write to the result topic regionCount.to(jsonSerde, jsonSerde, "streams-pageviewstats-untyped-output"); KafkaStreams streams = new KafkaStreams(builder, props); streams.start(); // usually the stream application would be running forever, // in this example we just let it run for some time and stop since the input data is finite. Thread.sleep(5000L); streams.close(); }
From source file:sendfile.java
public static void main(String[] args) { if (args.length != 5) { System.out.println("usage: java sendfile <to> <from> <smtp> <file> true|false"); System.exit(1);//from ww w.j a v a 2 s .com } String to = args[0]; String from = args[1]; String host = args[2]; String filename = args[3]; boolean debug = Boolean.valueOf(args[4]).booleanValue(); String msgText1 = "Sending a file.\n"; String subject = "Sending a file"; // create some properties and get the default Session Properties props = System.getProperties(); props.put("mail.smtp.host", host); Session session = Session.getInstance(props, null); session.setDebug(debug); try { // create a message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(msgText1); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource(filename); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the Multipart and add its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); // set the Date: header msg.setSentDate(new Date()); // send the message Transport.send(msg); } catch (MessagingException mex) { mex.printStackTrace(); Exception ex = null; if ((ex = mex.getNextException()) != null) { ex.printStackTrace(); } } }
From source file:kafka.examples.producer.BasicPartitionExample.java
public static void main(String[] args) { ArgumentParser parser = argParser(); try {//from ww w. ja v a2 s . com Namespace res = parser.parseArgs(args); /* parse args */ String brokerList = res.getString("bootstrap.servers"); String topic = res.getString("topic"); Boolean syncSend = res.getBoolean("syncsend"); long noOfMessages = res.getLong("messages"); long delay = res.getLong("delay"); String messageType = res.getString("messagetype"); Properties producerConfig = new Properties(); producerConfig.put("bootstrap.servers", brokerList); producerConfig.put("client.id", "basic-producer"); producerConfig.put("acks", "all"); producerConfig.put("retries", "3"); producerConfig.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); producerConfig.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); SimpleProducer<byte[], byte[]> producer = new SimpleProducer<>(producerConfig, syncSend); for (int i = 0; i < noOfMessages; i++) { if (i % 2 == 0) producer.send(topic, 0, getKey(i), getEvent(messageType, i)); // send even numbered messages else producer.send(topic, 1, getKey(i), getEvent(messageType, i)); // send odd numbered messages try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } producer.close(); } catch (ArgumentParserException e) { if (args.length == 0) { parser.printHelp(); System.exit(0); } else { parser.handleError(e); System.exit(1); } } }
From source file:msgsendsample.java
public static void main(String[] args) { if (args.length != 4) { usage();/*from w w w . j av a2 s .c o m*/ System.exit(1); } System.out.println(); String to = args[0]; String from = args[1]; String host = args[2]; boolean debug = Boolean.valueOf(args[3]).booleanValue(); // create some properties and get the default Session Properties props = new Properties(); props.put("mail.smtp.host", host); if (debug) props.put("mail.debug", args[3]); Session session = Session.getInstance(props, null); session.setDebug(debug); try { // create a message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject("JavaMail APIs Test"); msg.setSentDate(new Date()); // If the desired charset is known, you can use // setText(text, charset) msg.setText(msgText); Transport.send(msg); } catch (MessagingException mex) { System.out.println("\n--Exception handling in msgsendsample.java"); mex.printStackTrace(); System.out.println(); Exception ex = mex; do { if (ex instanceof SendFailedException) { SendFailedException sfex = (SendFailedException) ex; Address[] invalid = sfex.getInvalidAddresses(); if (invalid != null) { System.out.println(" ** Invalid Addresses"); for (int i = 0; i < invalid.length; i++) System.out.println(" " + invalid[i]); } Address[] validUnsent = sfex.getValidUnsentAddresses(); if (validUnsent != null) { System.out.println(" ** ValidUnsent Addresses"); for (int i = 0; i < validUnsent.length; i++) System.out.println(" " + validUnsent[i]); } Address[] validSent = sfex.getValidSentAddresses(); if (validSent != null) { System.out.println(" ** ValidSent Addresses"); for (int i = 0; i < validSent.length; i++) System.out.println(" " + validSent[i]); } } System.out.println(); if (ex instanceof MessagingException) ex = ((MessagingException) ex).getNextException(); else ex = null; } while (ex != null); } }
From source file:com.jeeffy.test.streams.pageview.PageViewUntypedDemo.java
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-pageview-untyped"); props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181"); props.put(StreamsConfig.TIMESTAMP_EXTRACTOR_CLASS_CONFIG, JsonTimestampExtractor.class); // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); KStreamBuilder builder = new KStreamBuilder(); final Serializer<JsonNode> jsonSerializer = new JsonSerializer(); final Deserializer<JsonNode> jsonDeserializer = new JsonDeserializer(); final Serde<JsonNode> jsonSerde = Serdes.serdeFrom(jsonSerializer, jsonDeserializer); KStream<String, JsonNode> views = builder.stream(Serdes.String(), jsonSerde, "streams-pageview-input"); KTable<String, JsonNode> users = builder.table(Serdes.String(), jsonSerde, "streams-userprofile-input", "streams-userprofile-store-name"); KTable<String, String> userRegions = users.mapValues(new ValueMapper<JsonNode, String>() { @Override/*from w w w . jav a2 s. c o m*/ public String apply(JsonNode record) { return record.get("region").textValue(); } }); KStream<JsonNode, JsonNode> regionCount = views .leftJoin(userRegions, new ValueJoiner<JsonNode, String, JsonNode>() { @Override public JsonNode apply(JsonNode view, String region) { ObjectNode jNode = JsonNodeFactory.instance.objectNode(); return jNode.put("user", view.get("user").textValue()) .put("page", view.get("page").textValue()) .put("region", region == null ? "UNKNOWN" : region); } }).map(new KeyValueMapper<String, JsonNode, KeyValue<String, JsonNode>>() { @Override public KeyValue<String, JsonNode> apply(String user, JsonNode viewRegion) { return new KeyValue<>(viewRegion.get("region").textValue(), viewRegion); } }).groupByKey(Serdes.String(), jsonSerde) .count(TimeWindows.of(7 * 24 * 60 * 60 * 1000L).advanceBy(1000), "RollingSevenDaysOfPageViewsByRegion") // TODO: we can merge ths toStream().map(...) with a single toStream(...) .toStream().map(new KeyValueMapper<Windowed<String>, Long, KeyValue<JsonNode, JsonNode>>() { @Override public KeyValue<JsonNode, JsonNode> apply(Windowed<String> key, Long value) { ObjectNode keyNode = JsonNodeFactory.instance.objectNode(); keyNode.put("window-start", key.window().start()).put("region", key.key()); ObjectNode valueNode = JsonNodeFactory.instance.objectNode(); valueNode.put("count", value); return new KeyValue<>((JsonNode) keyNode, (JsonNode) valueNode); } }); // write to the result topic regionCount.to(jsonSerde, jsonSerde, "streams-pageviewstats-untyped-output"); KafkaStreams streams = new KafkaStreams(builder, props); streams.start(); // usually the stream application would be running forever, // in this example we just let it run for some time and stop since the input data is finite. Thread.sleep(5000L); streams.close(); }
From source file:PropertiesUtil.java
public static void main(String args[]) { try {//from ww w. j ava 2 s.c o m System.out.println(load(new Properties(), "C:/data/ccm_wa/dordev/Countrywide~csdrzs/Countrywide/src/com/javelin/util/test.properties")); System.out.println(load(new Properties(), new File( "C:/data/ccm_wa/dordev/Countrywide~csdrzs/Countrywide/src/com/javelin/util/test.properties"))); System.out.println(load(new Properties(), new URL( "file:///C:/data/ccm_wa/dordev/Countrywide~csdrzs/Countrywide/src/com/javelin/util/test.properties"))); System.out.println(load(new Properties(), PropertiesUtil.class, "test.properties")); Properties properties = new Properties(); properties.put("1", "2"); properties.put("2", "2"); properties.put("3", "3"); store(properties, "C:/data/ccm_wa/dordev/Countrywide~csdrzs/Countrywide/src/com/javelin/util/test1.properties"); store(properties, new File( "C:/data/ccm_wa/dordev/Countrywide~csdrzs/Countrywide/src/com/javelin/util/test2.properties")); store(properties, PropertiesUtil.class, "test4.properties"); System.out.println(getByValue(properties, "2")); } catch (Exception e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) { if (args.length != 4) { usage();//from w ww .j a v a2s . co m System.exit(1); } System.out.println(); String to = args[0]; String from = args[1]; String host = args[2]; boolean debug = Boolean.valueOf(args[3]).booleanValue(); // create some properties and get the default Session Properties props = new Properties(); props.put("mail.smtp.host", host); if (debug) props.put("mail.debug", args[3]); Session session = Session.getInstance(props, null); session.setDebug(debug); try { // create a message Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(args[0]) }; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject("JavaMail APIs Test"); msg.setSentDate(new Date()); // If the desired charset is known, you can use // setText(text, charset) msg.setText(msgText); Transport.send(msg); } catch (MessagingException mex) { System.out.println("\n--Exception handling in msgsendsample.java"); mex.printStackTrace(); System.out.println(); Exception ex = mex; do { if (ex instanceof SendFailedException) { SendFailedException sfex = (SendFailedException) ex; Address[] invalid = sfex.getInvalidAddresses(); if (invalid != null) { System.out.println(" ** Invalid Addresses"); if (invalid != null) { for (int i = 0; i < invalid.length; i++) System.out.println(" " + invalid[i]); } } Address[] validUnsent = sfex.getValidUnsentAddresses(); if (validUnsent != null) { System.out.println(" ** ValidUnsent Addresses"); if (validUnsent != null) { for (int i = 0; i < validUnsent.length; i++) System.out.println(" " + validUnsent[i]); } } Address[] validSent = sfex.getValidSentAddresses(); if (validSent != null) { System.out.println(" ** ValidSent Addresses"); if (validSent != null) { for (int i = 0; i < validSent.length; i++) System.out.println(" " + validSent[i]); } } } System.out.println(); if (ex instanceof MessagingException) ex = ((MessagingException) ex).getNextException(); else ex = null; } while (ex != null); } }