Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

Commit

Permalink
start copying spring angular-universal.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Aug 5, 2018
1 parent 7574203 commit fe5b14a
Show file tree
Hide file tree
Showing 9 changed files with 598 additions and 502 deletions.
792 changes: 367 additions & 425 deletions core-server/authorization-server/pom.xml

Large diffs are not rendered by default.

This file was deleted.

7 changes: 7 additions & 0 deletions shared/angular-universal-j2v8-renderer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# TBME TV | Angular Universal J2V8 Renderer

(Java-)Server-Side renderer for angular universal applications.

## Hat-Tip and Acknowledgement

This project is heavily based on [swaechter](https://github.com/swaechter)'s original [implementation](https://github.com/swaechter/angularj-universal).
85 changes: 85 additions & 0 deletions shared/angular-universal-j2v8-renderer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.tbmelabs.tv.shared</groupId>
<artifactId>angular-universal-j2v8-renderer</artifactId>

<parent>
<groupId>ch.tbmelabs.tv</groupId>
<artifactId>shared</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<properties>
<!-- Plugin configuration -->
<com.eclipsesource.j2v8.version>4.6.0</com.eclipsesource.j2v8.version>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>eclipsesource-j2v8-linux</id>

<activation>
<os>
<family>unix</family>
</os>
</activation>

<dependencies>
<!-- https://mvnrepository.com/artifact/com.eclipsesource.j2v8/j2v8_linux_x86_64 -->
<dependency>
<groupId>com.eclipsesource.j2v8</groupId>
<artifactId>j2v8_linux_x86_64</artifactId>
<version>${com.eclipsesource.j2v8.version}</version>
</dependency>
</dependencies>
</profile>

<profile>
<id>eclipsesource-j2v8-windows</id>

<activation>
<os>
<family>windows</family>
</os>
</activation>

<dependencies>
<!-- https://mvnrepository.com/artifact/com.eclipsesource.j2v8/j2v8_win32_x86_64 -->
<dependency>
<groupId>com.eclipsesource.j2v8</groupId>
<artifactId>j2v8_win32_x86_64</artifactId>
<version>${com.eclipsesource.j2v8.version}</version>
</dependency>
</dependencies>
</profile>

<profile>
<id>eclipsesource-j2v8-mac</id>

<activation>
<os>
<family>mac</family>
</os>
</activation>

<dependencies>
<!-- https://mvnrepository.com/artifact/com.eclipsesource.j2v8/j2v8_macosx_x86_64 -->
<dependency>
<groupId>com.eclipsesource.j2v8</groupId>
<artifactId>j2v8_macosx_x86_64</artifactId>
<version>${com.eclipsesource.j2v8.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ch.tbmelabs.tv.shared.angularuniversalj2v8renderer;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;

import ch.tbmelabs.tv.shared.angularuniversalj2v8renderer.configuration.RenderEngineConfiguration;
import ch.tbmelabs.tv.shared.angularuniversalj2v8renderer.engine.RenderEngine;

/**
* Original source:
* https://github.com/swaechter/angularj-universal/blob/master/angularj-universal-renderer/src/main/java/ch/swaechter/angularjuniversal/renderer/Renderer.java
*/
public class Renderer {
private final List<RenderEngine> renderEngines;
private final RenderEngineConfiguration renderEngineConfiguration;
private Date startdate;

public Renderer(RenderEngineConfiguration renderEngineConfiguration) {
this.renderEngines = new ArrayList<>();
this.renderEngineConfiguration = renderEngineConfiguration;
}

public synchronized void startRenderer() {
if (renderEngines.size() != 0) {
return;
}

startdate = new Date();

for (int i = 0; i < renderEngineConfiguration.getEngines(); i++) {
RenderEngine renderengine = renderenginefactory.createRenderEngine();
renderEngines.add(renderengine);

Thread thread = new Thread(() -> {
renderengine.startWorking(renderrequests, renderconfiguration);
});
thread.start();
}

if (renderEngineConfiguration.getLiveReload()) {
Thread thread = new Thread(() -> {
while (isRendererRunning()) {
File file = renderEngineConfiguration.getServerBundleFile();
if (startdate.before(new Date(file.lastModified()))) {
stopRenderer();
startRenderer();
}
}
});
thread.start();
}
}

public synchronized void stopRenderer() {
if (renderEngines.size() == 0) {
return;
}

for (int i = 0; i < renderEngineConfiguration.getEngines(); i++) {
renderrequests.add(Optional.empty());
}

while (renderrequests.size() != 0) {
// Wait for an empty request queue
}

renderEngines.clear();
}

public synchronized boolean isRendererRunning() {
return renderEngines.size() != 0;
}

public Future<String> addRenderRequest(String uri) {
RenderRequest renderrequest = new RenderRequest(uri);
renderrequests.add(Optional.of(renderrequest));
return renderrequest.getFuture();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ch.tbmelabs.tv.shared.angularuniversalj2v8renderer.configuration;

import java.io.File;
import java.nio.charset.Charset;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
* Original source:
* https://github.com/swaechter/angularj-universal/blob/master/angularj-universal-renderer/src/main/java/ch/swaechter/angularjuniversal/renderer/configuration/RenderConfiguration.java
*/
@Data
@AllArgsConstructor
public class RenderEngineConfiguration {
private final String templateContent;
private final File serverBundleFile;
private final int engines;
private final boolean livereload;
private final Charset charset;
private final List<String> routes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.tbmelabs.tv.shared.angularuniversalj2v8renderer.engine;

import java.net.URI;

/**
* Original source:
* https://github.com/swaechter/angularj-universal/blob/master/angularj-universal-renderer/src/main/java/ch/swaechter/angularjuniversal/renderer/engine/RenderEngine.java
*/
public interface RenderEngine {
String renderPage(URI uri);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ch.tbmelabs.tv.shared.angularuniversalj2v8renderer.engine.impl;

import java.net.URI;

import ch.tbmelabs.tv.shared.angularuniversalj2v8renderer.engine.RenderEngine;

/**
* Original source:
* https://github.com/swaechter/angularj-universal/blob/master/angularj-universal-renderer-v8/src/main/java/ch/swaechter/angularjuniversal/v8renderer/V8RenderEngine.java
*/
public class NodeRenderEngineImpl implements RenderEngine {

@Override
public String renderPage(URI uri) {
// TODO Auto-generated method stub
return null;
}

}
1 change: 1 addition & 0 deletions shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<modules>
<module>constants</module>
<module>actuator-security-utils</module>
<module>angular-universal-j2v8-renderer</module>
</modules>
</project>

0 comments on commit fe5b14a

Please sign in to comment.