/** * @param templatePath path to a template on classpath */ public Templator(String templatePath){ template = readResource(templatePath); }
/** * Reads contents of resource fully into a string. Sets UTF-8 encoding internally. * * @param resourceName resource name. * @return entire contents of resource as string. */ public static String readResource(String resourceName) { return readResource(resourceName, "UTF-8"); }
/** * This method is used in one-off operations, where it is OK to load a template every time. * * Example: * <code> * String result = Templator.mergeFromPath(readResource("/message_template.txt", valuesMap)); * </code> * * @param templatePath template to merge * @param values values to merge into a template * @return result of merging */ public static String mergeFromPath(String templatePath, Map<String, ?> values) { return mergeFromTemplate(readResource(templatePath), values); }
/** * Reads contents of resource fully into a string. Sets UTF-8 encoding internally. * * @param resourceName resource name. * @return entire contents of resource as string. */ public static String readResource(String resourceName) { return readResource(resourceName, "UTF-8"); }
/** * @param templatePath path to a template on classpath */ public Templator(String templatePath){ template = readResource(templatePath); }
/** * Reads contents of resource fully into a string. Sets UTF-8 encoding internally. * * @param resourceName resource name. * @return entire contents of resource as string. */ public static String readResource(String resourceName) { return readResource(resourceName, "UTF-8"); }
/** * This method is used in one-off operations, where it is OK to load a template every time. * * Example: * <code> * String result = Templator.mergeFromPath(readResource("/message_template.txt", valuesMap)); * </code> * * @param templatePath template to merge * @param values values to merge into a template * @return result of merging */ public static String mergeFromPath(String templatePath, Map<String, ?> values) { return mergeFromTemplate(readResource(templatePath), values); }
String filePath = Files.createTempDirectory("async").toFile().getCanonicalPath(); Async async = new Async(filePath, true, new QueueConfig(QUEUE_NAME)); String loremIpsum = Util.readResource("/lorem-ipsum.txt"); async.start();
private static void testSendMethod() throws IOException { String QUEUE_NAME = "queue1"; String filePath = Files.createTempDirectory("async").toFile().getCanonicalPath(); Async async = new Async(filePath, false, new QueueConfig(QUEUE_NAME, new CommandListener(), LISTENER_THREAD_COUNT)); String loremIpsum = Util.readResource("/lorem-ipsum.txt"); async.start(); HelloPerformanceCommand.START = System.currentTimeMillis(); Runnable r = () -> { for(int i = 0; i < MESSAGES_PER_THREAD; i++){ async.send(QUEUE_NAME, new HelloPerformanceCommand(loremIpsum + i)); System.out.println("sent...."); } }; for(int i = 0; i < SENDING_THREAD_COUNT; i++){ Thread t = new Thread(r); t.start(); try { Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } } } }