forked from JavaWebinar/masterjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6d70aa1
Showing
7 changed files
with
364 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
out | ||
target | ||
*.iml | ||
log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Многомодульный maven. Многопоточность. XML. Веб сервисы. Удаленное взаимодействие | ||
|
||
 | ||
|
||
- **приложение импорта** из XML (JAXB, StAX, XPath, XSLT) | ||
- **многопоточного почтового веб-сервиса** (JavaMail, java.util.concurrent, JAX-WS, MTOM, хендлеры авторизации, логирования и статистики) | ||
- **веб приложения отправки почты с вложениями** | ||
- по SOAP (JAX-WS, MTOM) | ||
- по JAX-RS (Jersey) | ||
- по JMS ([ActiveMQ](http://activemq.apache.org/)) | ||
- через [AKKA](http://akka.io/) | ||
- используя асинхронные сервлеты 3.0 | ||
- сохранение данных в PostgreSQL используя [jDBI](http://jdbi.org/) | ||
- миграция базы [LiquiBase](http://www.liquibase.org/) | ||
- использование в проекте [Guava](https://github.com/google/guava/wiki), [Thymleaf](http://www.thymeleaf.org/), [Lombook](https://projectlombok.org/), [StreamEx](https://github.com/amaembo/streamex), | ||
[Typesafe Config](https://github.com/typesafehub/config), [Java Microbenchmark JMH](http://openjdk.java.net/projects/code-tools/jmh) | ||
|
||
## 17.10: [Занятие 1: Многопоточность](https://github.com/JavaOPs/masterjava) | ||
- Вступление. Многопоточность и параллельность | ||
- Структура памяти Java. Ленивая инициализация | ||
- Реализация многопоточности в Java | ||
- Реализация многопоточной отправки писем. Execution Framework | ||
|
||
## 24.10: Занятие 2 | ||
- Разбор ДЗ (многопоточная реализация умножения матриц) | ||
- [Java Microbenchmark JMH](http://openjdk.java.net/projects/code-tools/jmh/) (от Алексея Шипилева) | ||
- Формат XML. Создание схемы XSD. | ||
- Работа с XML в Java | ||
- JAXB, JAXP | ||
- StAX | ||
- XPath | ||
- XSLT | ||
|
||
## 31.10: Занятие 3 | ||
- Разбор ДЗ (работа с XML) | ||
- [Обзор Guava](https://drive.google.com/open?id=0B9Ye2auQ_NsFeFB5a29JQ2tRNHM) | ||
- Монады. flatMap | ||
- SOA и Микросервисы | ||
- Многомодульный Maven проект | ||
|
||
## 07.11: Занятие 4 | ||
- Разбор ДЗ (реализация структуры проекта, загрузка и разбор xml) | ||
- Thymleaf | ||
- Maven. Поиск и разрешение конфликтов зависимостей | ||
- Подключаем логирование с общими настройкам | ||
- Библиотеки и фреймворки для работы с JDBC. | ||
- Модуль persist | ||
|
||
## 14.11: Занятие 5 | ||
- Разбор ДЗ | ||
- Сохранение в базу в batch-моде с обработкой конфликтов | ||
- Вставка в несколько потоков | ||
- Конфигурирование приложения (<a href="https://github.com/typesafehub/config">Typesafe config</a>) | ||
- Lombook | ||
|
||
## 21.11: Занятие 6 | ||
- Разбор ДЗ (доработка модели и модуля export) | ||
- Миграция DB | ||
- Веб-сервисы (REST/SOAP) | ||
- Java реализации SOAP | ||
- Имплементируем Mail Service | ||
|
||
## 28.11: Занятие 7 | ||
- Разбор ДЗ | ||
- реализация MailSender | ||
- сохранение результатов отправки в DB | ||
- импорт Проектов и Групп | ||
- Стили WSDL. Кастомизация WSDL | ||
- Публикация кастомизированного WSDL. Автогенерация. | ||
- Деплой в Tomcat | ||
- Создание клиента почтового сервиса | ||
- Реализация массовой и групповой отправки почты. HW7 | ||
|
||
## 05.12: Занятие 8 | ||
- Разбор ДЗ | ||
- Делаем общий mailService.wsdl | ||
- Обновление WSDL | ||
- Отправка почты из модуля webapp | ||
- Доступ к переменным maven в приложении | ||
- SOAP Exception. Выделение общей части схемы | ||
- Коррекция схемы | ||
|
||
## 12.12: Занятие 9 | ||
- Добавление мавен плагинов (copy-rename-maven-plugin, maven-antrun-plugin, liquibase-maven-plugin) | ||
- Разбор ДЗ | ||
- Реализация вложений в веб-сервисе | ||
- Подключение MTOM | ||
- Реализация загрузки вложений в модуле webapp | ||
- Реализация вложений в почте | ||
- JAX-WS Message Context. Авторизация | ||
- JAX-WS Handlers (логирование SOAP) | ||
- Домашнее задание. Статистика | ||
|
||
## 19.12: Занятие 10 | ||
- Разбор ДЗ | ||
- Реализация SOAP handlers | ||
- Конфигурирование сервисов | ||
- JavaEE | ||
- JAX-RS. Интеграция с Jersey | ||
- JMS. Интеграция с [ActiveMQ](http://activemq.apache.org/) | ||
|
||
## 26.12: Занятие 11 | ||
- Авторизация в контейнере Tomcat | ||
- Отправка почты с вложениями | ||
- по JAX-RS | ||
- по JMS | ||
- Рефакторинг. Эксепшены в лямбдах Java 8 | ||
- Concurrent and distributed applications toolkit AKKA | ||
- Отсылка почты через AKKA Actors (Typed и Untyped Actors) | ||
- Асинхронные сервлеты 3.0 | ||
- Домашнее задание | ||
- Разбор решения с асинхронными сервлетами | ||
- [Выбор языка программирования](https://drive.google.com/open?id=0B9Ye2auQ_NsFZUVNakNxeUtGeFE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>ru.javaops</groupId> | ||
<artifactId>masterjava</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>Master Java</name> | ||
<url>https://github.com/JavaOPs/masterjava</url> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
|
||
<build> | ||
<finalName>masterjava</finalName> | ||
<defaultGoal>install</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
</dependencies> | ||
|
||
<profiles> | ||
</profiles> | ||
|
||
<dependencyManagement> | ||
</dependencyManagement> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ru.javaops.masterjava; | ||
|
||
/** | ||
* User: gkislin | ||
* Date: 05.08.2015 | ||
* | ||
* @link http://caloriesmng.herokuapp.com/ | ||
* @link https://github.com/JavaOPs/topjava | ||
*/ | ||
public class Main { | ||
public static void main(String[] args) { | ||
System.out.format("Hello MasterJava!"); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/ru/javaops/masterjava/matrix/MainMatrix.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ru.javaops.masterjava.matrix; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
/** | ||
* gkislin | ||
* 03.07.2016 | ||
*/ | ||
public class MainMatrix { | ||
private static final int MATRIX_SIZE = 1000; | ||
private static final int THREAD_NUMBER = 10; | ||
|
||
private final static ExecutorService executor = Executors.newFixedThreadPool(MainMatrix.THREAD_NUMBER); | ||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
final int[][] matrixA = MatrixUtil.create(MATRIX_SIZE); | ||
final int[][] matrixB = MatrixUtil.create(MATRIX_SIZE); | ||
|
||
double singleThreadSum = 0.; | ||
double concurrentThreadSum = 0.; | ||
int count = 1; | ||
while (count < 6) { | ||
System.out.println("Pass " + count); | ||
long start = System.currentTimeMillis(); | ||
final int[][] matrixC = MatrixUtil.singleThreadMultiply(matrixA, matrixB); | ||
double duration = (System.currentTimeMillis() - start) / 1000.; | ||
out("Single thread time, sec: %.3f", duration); | ||
singleThreadSum += duration; | ||
|
||
start = System.currentTimeMillis(); | ||
final int[][] concurrentMatrixC = MatrixUtil.concurrentMultiply(matrixA, matrixB, executor); | ||
duration = (System.currentTimeMillis() - start) / 1000.; | ||
out("Concurrent thread time, sec: %.3f", duration); | ||
concurrentThreadSum += duration; | ||
|
||
if (!MatrixUtil.compare(matrixC, concurrentMatrixC)) { | ||
System.err.println("Comparison failed"); | ||
break; | ||
} | ||
count++; | ||
} | ||
executor.shutdown(); | ||
out("\nAverage single thread time, sec: %.3f", singleThreadSum / 5.); | ||
out("Average concurrent thread time, sec: %.3f", concurrentThreadSum / 5.); | ||
} | ||
|
||
private static void out(String format, double ms) { | ||
System.out.println(String.format(format, ms)); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/ru/javaops/masterjava/matrix/MatrixUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ru.javaops.masterjava.matrix; | ||
|
||
import java.util.Random; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
/** | ||
* gkislin | ||
* 03.07.2016 | ||
*/ | ||
public class MatrixUtil { | ||
|
||
// TODO implement parallel multiplication matrixA*matrixB | ||
public static int[][] concurrentMultiply(int[][] matrixA, int[][] matrixB, ExecutorService executor) throws InterruptedException, ExecutionException { | ||
final int matrixSize = matrixA.length; | ||
final int[][] matrixC = new int[matrixSize][matrixSize]; | ||
|
||
return matrixC; | ||
} | ||
|
||
// TODO optimize by https://habrahabr.ru/post/114797/ | ||
public static int[][] singleThreadMultiply(int[][] matrixA, int[][] matrixB) { | ||
final int matrixSize = matrixA.length; | ||
final int[][] matrixC = new int[matrixSize][matrixSize]; | ||
|
||
for (int i = 0; i < matrixSize; i++) { | ||
for (int j = 0; j < matrixSize; j++) { | ||
int sum = 0; | ||
for (int k = 0; k < matrixSize; k++) { | ||
sum += matrixA[i][k] * matrixB[k][j]; | ||
} | ||
matrixC[i][j] = sum; | ||
} | ||
} | ||
return matrixC; | ||
} | ||
|
||
public static int[][] create(int size) { | ||
int[][] matrix = new int[size][size]; | ||
Random rn = new Random(); | ||
|
||
for (int i = 0; i < size; i++) { | ||
for (int j = 0; j < size; j++) { | ||
matrix[i][j] = rn.nextInt(10); | ||
} | ||
} | ||
return matrix; | ||
} | ||
|
||
public static boolean compare(int[][] matrixA, int[][] matrixB) { | ||
final int matrixSize = matrixA.length; | ||
for (int i = 0; i < matrixSize; i++) { | ||
for (int j = 0; j < matrixSize; j++) { | ||
if (matrixA[i][j] != matrixB[i][j]) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/ru/javaops/masterjava/service/MailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package ru.javaops.masterjava.service; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class MailService { | ||
private static final String OK = "OK"; | ||
|
||
private static final String INTERRUPTED_BY_FAULTS_NUMBER = "+++ Interrupted by faults number"; | ||
private static final String INTERRUPTED_BY_TIMEOUT = "+++ Interrupted by timeout"; | ||
private static final String INTERRUPTED_EXCEPTION = "+++ InterruptedException"; | ||
|
||
public GroupResult sendToList(final String template, final Set<String> emails) throws Exception { | ||
return new GroupResult(0, Collections.emptyList(), null); | ||
} | ||
|
||
|
||
// dummy realization | ||
public MailResult sendToUser(String template, String email) throws Exception { | ||
try { | ||
Thread.sleep(500); //delay | ||
} catch (InterruptedException e) { | ||
// log cancel; | ||
return null; | ||
} | ||
return Math.random() < 0.7 ? MailResult.ok(email) : MailResult.error(email, "Error"); | ||
} | ||
|
||
public static class MailResult { | ||
private final String email; | ||
private final String result; | ||
|
||
private static MailResult ok(String email) { | ||
return new MailResult(email, OK); | ||
} | ||
|
||
private static MailResult error(String email, String error) { | ||
return new MailResult(email, error); | ||
} | ||
|
||
public boolean isOk() { | ||
return OK.equals(result); | ||
} | ||
|
||
private MailResult(String email, String cause) { | ||
this.email = email; | ||
this.result = cause; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return '(' + email + ',' + result + ')'; | ||
} | ||
} | ||
|
||
public static class GroupResult { | ||
private final int success; // number of successfully sent email | ||
private final List<MailResult> failed; // failed emails with causes | ||
private final String failedCause; // global fail cause | ||
|
||
public GroupResult(int success, List<MailResult> failed, String failedCause) { | ||
this.success = success; | ||
this.failed = failed; | ||
this.failedCause = failedCause; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Success: " + success + '\n' + | ||
"Failed: " + failed.toString() + '\n' + | ||
(failedCause == null ? "" : "Failed cause" + failedCause); | ||
} | ||
} | ||
} |