-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from vuong-idnow/master
Upgrade atmosphere-play to use play 2.6
- Loading branch information
Showing
9 changed files
with
226 additions
and
129 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
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
71 changes: 71 additions & 0 deletions
71
module/src/main/java/org/atmosphere/play/AtmosphereWebSocketActor.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,71 @@ | ||
package org.atmosphere.play; | ||
|
||
import akka.actor.AbstractActor; | ||
import akka.actor.ActorRef; | ||
import akka.actor.Props; | ||
import akka.util.ByteString; | ||
import org.atmosphere.cpr.AtmosphereConfig; | ||
import org.atmosphere.cpr.AtmosphereRequest; | ||
import org.atmosphere.cpr.AtmosphereResponseImpl; | ||
import org.atmosphere.cpr.WebSocketProcessorFactory; | ||
import org.atmosphere.websocket.WebSocketProcessor; | ||
import play.Logger; | ||
import play.api.mvc.RequestHeader; | ||
import play.mvc.Http; | ||
|
||
import java.util.Map; | ||
|
||
public class AtmosphereWebSocketActor extends AbstractActor { | ||
private static final Logger.ALogger LOG = Logger.of(AtmosphereWebSocketActor.class); | ||
private PlayWebSocket playWebSocket = null; | ||
private WebSocketProcessor webSocketProcessor = null; | ||
private ActorRef actorRef; | ||
private RequestHeader requestHeader; | ||
private Map<String, Object> additionalAttributes; | ||
private AtmosphereConfig atmosphereConfig; | ||
|
||
public static Props props(ActorRef actorRef, RequestHeader requestHeader, Map<String, Object> additionalAtts, AtmosphereConfig config) { | ||
return Props.create(AtmosphereWebSocketActor.class, actorRef, requestHeader, additionalAtts, config); | ||
} | ||
|
||
public AtmosphereWebSocketActor(ActorRef actorRef, RequestHeader requestHeader, Map<String, Object> additionalAttributes, AtmosphereConfig atmosphereConfig) { | ||
this.actorRef = actorRef; | ||
this.requestHeader = requestHeader; | ||
this.additionalAttributes = additionalAttributes; | ||
this.atmosphereConfig = atmosphereConfig; | ||
} | ||
|
||
@Override | ||
public void preStart() { | ||
try { | ||
this.playWebSocket = new PlayWebSocket(actorRef, atmosphereConfig); | ||
this.webSocketProcessor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(atmosphereConfig.framework()); | ||
AtmosphereRequest atmosphereRequest = AtmosphereUtils.request(new Http.RequestImpl(requestHeader), additionalAttributes); | ||
this.webSocketProcessor.open(playWebSocket, atmosphereRequest, AtmosphereResponseImpl.newInstance(atmosphereConfig, atmosphereRequest, playWebSocket)); | ||
} catch (Throwable throwable) { | ||
LOG.error("Failed to start the actor ", throwable); | ||
} | ||
} | ||
|
||
@Override | ||
public void postStop() { | ||
this.webSocketProcessor.close(playWebSocket, 1002); | ||
} | ||
|
||
@Override | ||
public Receive createReceive() { | ||
return receiveBuilder() | ||
.match(String.class, this::handleString) | ||
.match(ByteString.class, this::handleByteString) | ||
.build(); | ||
} | ||
|
||
private void handleString(String string) { | ||
this.webSocketProcessor.invokeWebSocketProtocol(this.playWebSocket, string); | ||
} | ||
|
||
private void handleByteString(ByteString byteString) { | ||
this.webSocketProcessor.invokeWebSocketProtocol(this.playWebSocket, byteString.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.atmosphere.play; | ||
|
||
public interface OutStream { | ||
void write(String message); | ||
void close(); | ||
|
||
} |
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
Oops, something went wrong.