Skip to content

Commit

Permalink
Add stockticker demo (payara#55)
Browse files Browse the repository at this point in the history
* Add Stock Ticker Demo to Payara Examples
  • Loading branch information
smillidge authored May 20, 2017
1 parent da752c8 commit 5799856
Show file tree
Hide file tree
Showing 42 changed files with 31,667 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Payara-Micro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
<module>simplest-bootstrap</module>
<module>spring-boot-jpa-jsf-example</module>
<module>spring-boot-rest-example</module>
<module>JMS-Client-Example</module>
</modules>
<module>JMS-Client-Example</module>
<module>stock-ticker-demo</module>
</modules>

</project>
1 change: 1 addition & 0 deletions Payara-Micro/stock-ticker-demo/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

19 changes: 19 additions & 0 deletions Payara-Micro/stock-ticker-demo/StockTicker/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Stock Ticker Application

This application consists of a simple EJB Timer that fires an event onto the Clustered CDI Event Bus
every second. The event consists of a single Stock POJO with a random number for the Stock Price

deploy this application on Payara Micro using;

```shell
java -jar payara-micro.jar --autobindhttp --deploy StockTicker-1.0-SNAPSHOT.jar
```

Once deployed it prints out a message whenever it fires an event;

```shell
Stock{symbol=PAYARA, description=, price=2.6473029469799902}
Stock{symbol=PAYARA, description=, price=53.18660982282327}
Stock{symbol=PAYARA, description=, price=4.84404008973881}
Stock{symbol=PAYARA, description=, price=92.9819267848963}
```
20 changes: 20 additions & 0 deletions Payara-Micro/stock-ticker-demo/StockTicker/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv3ee6</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<netbeans.hint.jdkPlatform>JDK 1.7</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
83 changes: 83 additions & 0 deletions Payara-Micro/stock-ticker-demo/StockTicker/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>fish.payara.examples.payaramicro</groupId>
<artifactId>StockTicker</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>

<name>StockTicker</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>fish.payara.api</groupId>
<artifactId>payara-api</artifactId>
<version>4.1.1.171.1</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2017] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.examples.payaramicro.stockticker;

import java.io.Serializable;

/**
* POJO Stock Object used as the payload for the CDI Event
*
* @author Steve Millidge (Payara Foundation)
*/
public class Stock implements Serializable {

private static final long serialVersionUID = 1L;
private String symbol;
private String description;
private double price;

public Stock(String symbol, String description, double price) {
this.symbol = symbol;
this.description = description;
this.price = price;
}

public Stock() {

}

public String getSymbol() {
return symbol;
}

public void setSymbol(String symbol) {
this.symbol = symbol;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

@Override
public String toString() {
return "Stock{" + "symbol=" + symbol + ", description=" + description + ", price=" + price + '}';
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2017] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.examples.payaramicro.stockticker;

import fish.payara.micro.cdi.Outbound;
import javax.ejb.Singleton;
import javax.ejb.Schedule;
import javax.enterprise.event.Event;
import javax.inject.Inject;

/**
* Singleton EJB Timner that fires a CDI Event every second
* The CDI Event is fired onto the Clustered CDI Event Bus
* just using the @OutBound annotation
* @author Steve Millidge (Payara Foundation)
*/
@Singleton
public class StockTicker {

@Inject
@Outbound(loopBack = true)
Event<Stock> stockEvents;

@Schedule(hour = "*", minute="*", second = "*/1", persistent = false)
public void generatePrice() {

String symbol = "PAYARA";
Stock stock = new Stock(symbol,"",(Math.random()*100.0) + 10.0);
System.out.println(stock);
stockEvents.fire(stock);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

22 changes: 22 additions & 0 deletions Payara-Micro/stock-ticker-demo/StockWeb/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Stock Web

This is a web application that uses JavaEE websockets and the Payara CDI Clustered Event Bus to push data in real time to the browser and update an HTML 5 graph.

The application received Stock Events from the CDI Event Bus and sends them via WebSockets.
The Browser parses the JSON Stock object
The JSON data is used to update the data in a HighCharts chart.

To run the application on Payara Micro use;

```shell
java -jar payara-micro.jar --autobindhttp --deploy StockWeb-1.0-SNAPSHOT.war
```

Once deployed navigate to http://127.0.0.1:8081/StockWeb-1.0-SNAPSHOT

The actual URL will be displayed after the boot of Payara Micro for example;
```shell
Payara Micro URLs
http://MintyFresh:8081/StockWeb-1.0-SNAPSHOT

```
20 changes: 20 additions & 0 deletions Payara-Micro/stock-ticker-demo/StockWeb/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv3ee6</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<netbeans.hint.jdkPlatform>JDK 1.7</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
Loading

0 comments on commit 5799856

Please sign in to comment.