-
-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for #159 Add support for Hazelcast
- Loading branch information
Showing
25 changed files
with
1,350 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,64 @@ | ||
<?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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.atmosphere</groupId> | ||
<artifactId>atmosphere-project</artifactId> | ||
<version>0.9-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.atmosphere</groupId> | ||
<artifactId>atmosphere-hazelcast</artifactId> | ||
<packaging>bundle</packaging> | ||
<version>0.9-SNAPSHOT</version> | ||
<name>atmosphere-hazelcast</name> | ||
<url>https://github.com/Atmosphere/atmosphere</url> | ||
<build> | ||
<defaultGoal>install</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<version>${felix-version}</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Import-Package>*</Import-Package> | ||
<Export-Package> | ||
org.atmosphere.plugin.hazelcast.* | ||
</Export-Package> | ||
</instructions> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>osgi-bundle</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>bundle</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.atmosphere</groupId> | ||
<artifactId>atmosphere-jersey</artifactId> | ||
<version>${pom.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.hazelcast</groupId> | ||
<artifactId>hazelcast</artifactId> | ||
<version>1.9.4.6</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
88 changes: 88 additions & 0 deletions
88
extras/hazelcast/src/main/java/org/atmosphere/plugin/hazelcast/HazelcastBroadcaster.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,88 @@ | ||
/* | ||
* Copyright 2012 Jeanfrancois Arcand | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.atmosphere.plugin.hazelcast; | ||
|
||
|
||
import com.hazelcast.core.ITopic; | ||
import com.hazelcast.core.Hazelcast; | ||
import com.hazelcast.core.MessageListener; | ||
|
||
import org.atmosphere.cpr.AtmosphereServlet; | ||
import org.atmosphere.util.AbstractBroadcasterProxy; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* Simple {@link org.atmosphere.cpr.Broadcaster} implementation based on Hazelcast | ||
* | ||
* @author Jeanfrancois Arcand | ||
*/ | ||
public class HazelcastBroadcaster extends AbstractBroadcasterProxy { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(org.atmosphere.plugin.hazelcast.HazelcastBroadcaster.class); | ||
private ITopic topic; | ||
|
||
public HazelcastBroadcaster(String id, AtmosphereServlet.AtmosphereConfig config) { | ||
this(id, URI.create("http://localhost:6379"), config); | ||
} | ||
|
||
public HazelcastBroadcaster(String id, URI uri, AtmosphereServlet.AtmosphereConfig config) { | ||
super(id, uri, config); | ||
} | ||
|
||
public void setUp() { | ||
topic = Hazelcast.<String>getTopic(getID()); | ||
} | ||
|
||
@Override | ||
public synchronized void setID(String id) { | ||
super.setID(id); | ||
setUp(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void destroy() { | ||
topic.destroy(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void incomingBroadcast() { | ||
logger.info("Subscribing to: {}", getID()); | ||
topic.addMessageListener(new MessageListener<String>() { | ||
@Override | ||
public void onMessage(String message) { | ||
broadcastReceivedMessage(message); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void outgoingBroadcast(Object message) { | ||
topic.publish(message.toString()); | ||
} | ||
|
||
} |
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
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
3 changes: 3 additions & 0 deletions
3
...jquery-pubsub-hazelcast/overlays/org.atmosphere.atmosphere-jquery-0.8.0-RC3-SNAPSHOT.info
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,3 @@ | ||
1320257818000 | ||
(?:[^/]+/)*?[^/]*? | ||
META-INF(?:$|/.+) |
3 changes: 3 additions & 0 deletions
3
...jquery-pubsub-hazelcast/overlays/org.atmosphere.atmosphere-jquery-0.8.0-RC4-SNAPSHOT.info
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,3 @@ | ||
1322056397000 | ||
(?:[^/]+/)*?[^/]*? | ||
META-INF(?:$|/.+) |
3 changes: 3 additions & 0 deletions
3
...les/jquery-pubsub-hazelcast/overlays/org.atmosphere.atmosphere-jquery-0.8.1-SNAPSHOT.info
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,3 @@ | ||
1322237374000 | ||
(?:[^/]+/)*?[^/]*? | ||
META-INF(?:$|/.+) |
3 changes: 3 additions & 0 deletions
3
...les/jquery-pubsub-hazelcast/overlays/org.atmosphere.atmosphere-jquery-0.8.2-SNAPSHOT.info
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,3 @@ | ||
1324429089000 | ||
(?:[^/]+/)*?[^/]*? | ||
META-INF(?:$|/.+) |
3 changes: 3 additions & 0 deletions
3
samples/jquery-pubsub-hazelcast/overlays/org.atmosphere.atmosphere-jquery-0.8.2.info
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,3 @@ | ||
1324492840000 | ||
(?:[^/]+/)*?[^/]*? | ||
META-INF(?:$|/.+) |
3 changes: 3 additions & 0 deletions
3
...les/jquery-pubsub-hazelcast/overlays/org.atmosphere.atmosphere-jquery-0.8.3-SNAPSHOT.info
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,3 @@ | ||
1324480420000 | ||
(?:[^/]+/)*?[^/]*? | ||
META-INF(?:$|/.+) |
3 changes: 3 additions & 0 deletions
3
...les/jquery-pubsub-hazelcast/overlays/org.atmosphere.atmosphere-jquery-0.8.4-SNAPSHOT.info
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,3 @@ | ||
1326923560000 | ||
(?:[^/]+/)*?[^/]*? | ||
META-INF(?:$|/.+) |
3 changes: 3 additions & 0 deletions
3
samples/jquery-pubsub-hazelcast/overlays/org.atmosphere.atmosphere-jquery-0.9-SNAPSHOT.info
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,3 @@ | ||
1326733811000 | ||
(?:[^/]+/)*?[^/]*? | ||
META-INF(?:$|/.+) |
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,50 @@ | ||
<?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/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.atmosphere.samples</groupId> | ||
<artifactId>atmosphere-samples</artifactId> | ||
<version>0.9-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.atmosphere.samples</groupId> | ||
<artifactId>atmosphere-pubsub-hazelcast</artifactId> | ||
<packaging>war</packaging> | ||
<version>0.9-SNAPSHOT</version> | ||
<name>atmosphere-pubsub-hazelcast</name> | ||
<url>http://maven.apache.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.atmosphere</groupId> | ||
<artifactId>atmosphere-jquery</artifactId> | ||
<version>${pom.version}</version> | ||
<type>war</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.atmosphere</groupId> | ||
<artifactId>atmosphere-jersey</artifactId> | ||
<version>${pom.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.atmosphere</groupId> | ||
<artifactId>atmosphere-hazelcast</artifactId> | ||
<version>${pom.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>${logback-version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<version>${logback-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.geronimo.specs</groupId> | ||
<artifactId>geronimo-servlet_3.0_spec</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
55 changes: 55 additions & 0 deletions
55
...les/jquery-pubsub-hazelcast/src/main/java/org/atmosphere/samples/pubsub/EventsLogger.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,55 @@ | ||
/* | ||
* Copyright 2012 Jeanfrancois Arcand | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.atmosphere.samples.pubsub; | ||
|
||
import org.atmosphere.cpr.AtmosphereResourceEvent; | ||
import org.atmosphere.cpr.AtmosphereResourceEventListener; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class EventsLogger implements AtmosphereResourceEventListener { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(EventsLogger.class); | ||
|
||
public EventsLogger() { | ||
} | ||
|
||
public void onSuspend(final AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) { | ||
logger.info("onSuspend(): {}:{}", event.getResource().getRequest().getRemoteAddr(), | ||
event.getResource().getRequest().getRemotePort()); | ||
} | ||
|
||
public void onResume(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) { | ||
logger.info("onResume(): {}:{}", event.getResource().getRequest().getRemoteAddr(), | ||
event.getResource().getRequest().getRemotePort()); | ||
} | ||
|
||
public void onDisconnect(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) { | ||
logger.info("onDisconnect(): {}:{}", event.getResource().getRequest().getRemoteAddr(), | ||
event.getResource().getRequest().getRemotePort()); | ||
} | ||
|
||
public void onBroadcast(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) { | ||
logger.info("onBroadcast(): {}", event.getMessage()); | ||
} | ||
|
||
public void onThrowable(AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event) { | ||
logger.warn("onThrowable(): {}", event); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...les/jquery-pubsub-hazelcast/src/main/java/org/atmosphere/samples/pubsub/FileResource.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,45 @@ | ||
/* | ||
* Copyright 2012 Jeanfrancois Arcand | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package org.atmosphere.samples.pubsub; | ||
|
||
import javax.servlet.ServletContext; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.PathSegment; | ||
import java.io.InputStream; | ||
|
||
@Path("/") | ||
@Produces("text/html") | ||
public class FileResource { | ||
|
||
private | ||
@Context | ||
ServletContext sc; | ||
|
||
@Path("/jquery/{id}") | ||
@GET | ||
public InputStream getJQuery(@PathParam("id") PathSegment ps) { | ||
return sc.getResourceAsStream("/jquery/" + ps.getPath()); | ||
} | ||
|
||
@GET | ||
public InputStream getIndex() { | ||
return sc.getResourceAsStream("/index.html"); | ||
} | ||
} |
Oops, something went wrong.