This repository has been archived by the owner on Oct 10, 2021. It is now read-only.
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 3dd4eb8
Showing
11 changed files
with
294 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 @@ | ||
target | ||
.classpath | ||
.project | ||
.settings | ||
.springBeans |
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,42 @@ | ||
<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>com.soluvas.samples</groupId> | ||
<artifactId>eventfx.si</artifactId> | ||
<packaging>jar</packaging> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>eventfx.si</name> | ||
<url>http://maven.apache.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.7</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.integration</groupId> | ||
<artifactId>spring-integration-core</artifactId> | ||
<version>2.0.0.M2</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<repositories> | ||
<repository> | ||
<id>spring-milestone</id> | ||
<name>Spring Portfolio Milestone Repository</name> | ||
<url>http://s3.amazonaws.com/maven.springframework.org/milestone</url> | ||
</repository> | ||
</repositories> | ||
</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,9 @@ | ||
package com.soluvas.samples.eventfx.si; | ||
|
||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
public class App { | ||
public static void main(String[] args) { | ||
new ClassPathXmlApplicationContext("META-INF/spring/*.xml"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/soluvas/samples/eventfx/si/AsyncListener.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,8 @@ | ||
package com.soluvas.samples.eventfx.si; | ||
|
||
import java.util.EventListener; | ||
|
||
public interface AsyncListener<E> extends EventListener { | ||
|
||
void notify(E event); | ||
} |
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,38 @@ | ||
package com.soluvas.samples.eventfx.si; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class Display implements SyncListener<SensorEvent, String>, AsyncListener<SensorEvent> { | ||
|
||
private static Log log = LogFactory.getLog(Display.class); | ||
private String name; | ||
|
||
@PostConstruct | ||
public void initialize() { | ||
log.info("Display " + getName() + " created."); | ||
} | ||
|
||
@Override | ||
public String update(SensorEvent event) { | ||
log.info("[" + name + "] is updated: '" + event.getText() + "'"); | ||
return getName() + " received " + event.getText(); | ||
} | ||
|
||
@Override | ||
public void notify(SensorEvent event) { | ||
log.info("[" + name + "] is notified: '" + event.getText() + "'"); | ||
|
||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
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,45 @@ | ||
package com.soluvas.samples.eventfx.si; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class Sensor { | ||
|
||
private static Log log = LogFactory.getLog(Sensor.class); | ||
|
||
private SyncListener<SensorEvent, String> sensorSyncListener; | ||
private AsyncListener<SensorEvent> sensorAsyncListener; | ||
|
||
private void fireSensor(SensorEvent event) { | ||
if (sensorSyncListener != null) { | ||
String result = sensorSyncListener.update(event); | ||
log.info("Response: " + result); | ||
} | ||
if (sensorAsyncListener != null) { | ||
sensorAsyncListener.notify(event); | ||
} | ||
} | ||
|
||
public void updateText(String text) { | ||
log.info("updateText: " + text); | ||
fireSensor(new SensorEvent(text)); | ||
} | ||
|
||
public SyncListener<SensorEvent, String> getSensorSyncListener() { | ||
return sensorSyncListener; | ||
} | ||
|
||
public void setSensorSyncListener(SyncListener<SensorEvent, String> sensorSyncListener) { | ||
this.sensorSyncListener = sensorSyncListener; | ||
} | ||
|
||
public AsyncListener<SensorEvent> getSensorAsyncListener() { | ||
return sensorAsyncListener; | ||
} | ||
|
||
public void setSensorAsyncListener( | ||
AsyncListener<SensorEvent> sensorAsyncListener) { | ||
this.sensorAsyncListener = sensorAsyncListener; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/soluvas/samples/eventfx/si/SensorEvent.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,20 @@ | ||
package com.soluvas.samples.eventfx.si; | ||
|
||
public class SensorEvent { | ||
|
||
private String text; | ||
|
||
public SensorEvent(String text) { | ||
super(); | ||
this.text = text; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/soluvas/samples/eventfx/si/SensorSimulator.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,43 @@ | ||
package com.soluvas.samples.eventfx.si; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SensorSimulator { | ||
|
||
private static Log log = LogFactory.getLog(SensorSimulator.class); | ||
|
||
@Autowired | ||
private Sensor sensor; | ||
private ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); | ||
|
||
@PostConstruct | ||
public void initialize() { | ||
scheduledExecutor.scheduleAtFixedRate(new Runnable() { | ||
|
||
public void run() { | ||
sensor.updateText("Something happens at " + SimpleDateFormat.getTimeInstance().format(new Date())); | ||
} | ||
}, 2000, 2000, TimeUnit.MILLISECONDS); | ||
log.info("Sensor simulator initialized."); | ||
} | ||
|
||
@PreDestroy | ||
public void destroy() throws InterruptedException { | ||
log.info("Destroying Sensor simulator..."); | ||
scheduledExecutor.shutdown(); | ||
scheduledExecutor.awaitTermination(2000, TimeUnit.MILLISECONDS); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/soluvas/samples/eventfx/si/SyncListener.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,8 @@ | ||
package com.soluvas.samples.eventfx.si; | ||
|
||
import java.util.EventListener; | ||
|
||
public interface SyncListener<E, R> extends EventListener { | ||
|
||
R update(E event); | ||
} |
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,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:si="http://www.springframework.org/schema/integration" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd | ||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd"> | ||
|
||
<context:component-scan base-package="com.soluvas.samples.eventfx.si" /> | ||
|
||
<bean class="com.soluvas.samples.eventfx.si.Sensor"> | ||
<property name="sensorSyncListener"> | ||
<si:gateway id="sensorSyncListener" service-interface="com.soluvas.samples.eventfx.si.SyncListener" | ||
default-request-channel="Sensor_SensorEvent_sync" /> | ||
</property> | ||
<property name="sensorAsyncListener"> | ||
<si:gateway id="sensorAsyncListener" service-interface="com.soluvas.samples.eventfx.si.AsyncListener" | ||
default-request-channel="Sensor_SensorEvent_async" /> | ||
</property> | ||
</bean> | ||
<bean id="display1" class="com.soluvas.samples.eventfx.si.Display"> | ||
<property name="name" value="Sony(sync)" /> | ||
</bean> | ||
<bean id="display2" class="com.soluvas.samples.eventfx.si.Display"> | ||
<property name="name" value="Samsung(async)" /> | ||
</bean> | ||
|
||
<si:channel id="Sensor_SensorEvent_sync" /> | ||
<si:publish-subscribe-channel id="Sensor_SensorEvent_async" /> | ||
|
||
<si:service-activator input-channel="Sensor_SensorEvent_sync" ref="display1" method="update" /> | ||
<si:chain input-channel="Sensor_SensorEvent_async"> | ||
<si:delayer default-delay="1200" /> | ||
<si:service-activator ref="display2" method="notify" /> | ||
</si:chain> | ||
|
||
</beans> |
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,38 @@ | ||
package com.soluvas.samples.eventfx.si; | ||
|
||
import junit.framework.Test; | ||
import junit.framework.TestCase; | ||
import junit.framework.TestSuite; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
extends TestCase | ||
{ | ||
/** | ||
* Create the test case | ||
* | ||
* @param testName name of the test case | ||
*/ | ||
public AppTest( String testName ) | ||
{ | ||
super( testName ); | ||
} | ||
|
||
/** | ||
* @return the suite of tests being tested | ||
*/ | ||
public static Test suite() | ||
{ | ||
return new TestSuite( AppTest.class ); | ||
} | ||
|
||
/** | ||
* Rigourous Test :-) | ||
*/ | ||
public void testApp() | ||
{ | ||
assertTrue( true ); | ||
} | ||
} |