Fitted the Atmosphere Chat example onto Akka
This commit is contained in:
parent
899c86add3
commit
9e88576991
6 changed files with 10 additions and 104 deletions
|
|
@ -43,12 +43,11 @@ class AkkaServlet extends ServletContainer with Logging {
|
|||
|
||||
class AkkaCometServlet extends org.atmosphere.cpr.AtmosphereServlet {
|
||||
|
||||
override def loadConfiguration(sc : ServletConfig) : Unit = {
|
||||
val servlet = new AkkaServlet with AtmosphereServletProcessor {
|
||||
val servlet = new AkkaServlet with AtmosphereServletProcessor {
|
||||
|
||||
//Delegate to implement the behavior for AtmosphereHandler
|
||||
private val handler = new AbstractReflectorAtmosphereHandler {
|
||||
override def onRequest(event: AtmosphereResource[HttpServletRequest, HttpServletResponse]) : Unit = {
|
||||
override def onRequest(event: AtmosphereResource[HttpServletRequest, HttpServletResponse]) {
|
||||
if(event ne null)
|
||||
{
|
||||
event.getRequest.setAttribute(ReflectorServletProcessor.ATMOSPHERE_RESOURCE, event)
|
||||
|
|
@ -64,13 +63,11 @@ class AkkaCometServlet extends org.atmosphere.cpr.AtmosphereServlet {
|
|||
}
|
||||
|
||||
override def onRequest(resource: AtmosphereResource[HttpServletRequest, HttpServletResponse]) {
|
||||
if(resource ne null)
|
||||
handler onRequest resource
|
||||
}
|
||||
}
|
||||
|
||||
override def loadConfiguration(sc : ServletConfig) {
|
||||
atmosphereHandlers.put("/*", new AtmosphereHandlerWrapper(servlet, new JerseyBroadcaster))
|
||||
}
|
||||
|
||||
override def loadAtmosphereDotXml(is: InputStream, urlc: URLClassLoader) = () //Hide it
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,13 @@ class Chat extends Actor with Logging {
|
|||
@Suspend
|
||||
@GET
|
||||
@Produces(Array("text/html"))
|
||||
def suspend = <!-- Comet is a programming technique that enables web servers to send data to the client without having any need for the client to request it. -->
|
||||
def suspend = {
|
||||
val s = new StringBuilder
|
||||
s append "<!-- "
|
||||
for(i <- 1 to 10) s append "Comet is a programming technique that enables web servers to send data to the client without having any need for the client to request it. "
|
||||
s append " -->"
|
||||
s toString
|
||||
}
|
||||
|
||||
override def receive: PartialFunction[Any, Unit] = {
|
||||
case Chat(who, what, msg) => {
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
<atmosphere-handlers>
|
||||
<!-- Associate a context-root (servlet-mapping) to an AtmosphereHandler.
|
||||
Request sent using that context-root will be mapped to its associated AtmosphereHandler
|
||||
-->
|
||||
<atmosphere-handler context-root="" class-name="se.scalablesolutions.akka.kernel.rest.AkkaServlet" broadcaster="org.atmosphere.core.JerseyBroadcaster">
|
||||
<!-- Define some AtmosphereHandler properties -->
|
||||
<property name="com.sun.jersey.spi.container.ResourceFilters" value="org.atmosphere.core.AtmosphereFilter"/>
|
||||
</atmosphere-handler>
|
||||
</atmosphere-handlers>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Context>
|
||||
<!-- <Loader className="org.atmosphere.util.AtmosphereClassloader"/> -->
|
||||
<Loader delegate="true"/>
|
||||
</Context>
|
||||
19
deploy/root/jquery-1.3.2.min.js
vendored
19
deploy/root/jquery-1.3.2.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,64 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Push Services Demo</title>
|
||||
<script language="javascript" src="jquery-1.3.2.min.js">
|
||||
</script>
|
||||
<style>
|
||||
.hide {
|
||||
visibility : hidden;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body id="body">
|
||||
<div id="container">
|
||||
<div id="chat">
|
||||
<div id="chatwindow">
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" name="name" id="name"/>
|
||||
<input type="button" name="login" value="Login" id="login" />
|
||||
<textarea id="msg" class="hide" name="message" rows="10" cols="150"></textarea>
|
||||
<input type="button" name="Send" id="send" value="Send" class="hide"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script language="javascript">
|
||||
$(function(){
|
||||
window.app = {
|
||||
update : function(data) {
|
||||
if(data && data.name)
|
||||
$('#chatwindow').append('<p>' + data.name + (data.message ? (': ' + data.message) : '') + '</p>');
|
||||
else
|
||||
alert(data);
|
||||
}
|
||||
}
|
||||
|
||||
$('#send').click( function(e){
|
||||
var message = $('#msg').val();
|
||||
$('#msg').val('');
|
||||
|
||||
$.post('/chat',
|
||||
{
|
||||
'action' : 'post',
|
||||
'name' : $('#name').val(),
|
||||
'message' : message
|
||||
});
|
||||
});
|
||||
|
||||
$('#login').click( function(e) {
|
||||
$.post('/chat',
|
||||
{
|
||||
'action' : 'login',
|
||||
'name' : $('#name').val()
|
||||
},
|
||||
function(data) { $('#login').hide();
|
||||
$('#name').attr('disabled','disabled');
|
||||
$('#msg').removeClass('hide');
|
||||
$('#send').removeClass('hide');
|
||||
$('<iframe style="display:hidden;" id="comet" src="/chat"></iframe>').appendTo('#body');
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue