下面列出了javax.websocket.Session#getAsyncRemote ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@OnOpen
public void onOpen(Session session, @PathParam("uuid") String uuid) {
UUID key = UUID.fromString(uuid);
peers.put(key, session);
JsonArrayBuilder builder = Json.createArrayBuilder();
for (StatusMessage statusMessage : StatusMessage.values()) {
JsonObjectBuilder object = Json.createObjectBuilder();
builder.add(object.add(statusMessage.name(), statusMessage.getMessage()).build());
}
RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
asyncRemote.sendText(builder.build().toString());
// Send pending messages
List<String> messages = messageBuffer.remove(key);
if (messages != null) {
messages.forEach(asyncRemote::sendText);
}
}
@Before
public void before() throws Exception {
notificationCollector = new NotificationCollector();
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
String uri = "ws://localhost:8080/pnc-rest-new/" + NotificationsEndpoint.ENDPOINT_PATH;
Session session = container.connectToServer(notificationCollector, URI.create(uri));
waitForWSClientConnection();
notificationCollector.clear();
asyncRemote = session.getAsyncRemote();
}
public Client(Session session) {
this.session = session;
this.async = session.getAsyncRemote();
}
public Client(Session session) {
this.session = session;
this.async = session.getAsyncRemote();
}
public Client(Session session) {
this.session = session;
this.async = session.getAsyncRemote();
}
public Client(Session session) {
this.session = session;
this.async = session.getAsyncRemote();
}
public Client(Session session) {
this.session = session;
this.async = session.getAsyncRemote();
}
public MessageSender(Session session) {
this.session = session;
async = session.getAsyncRemote();
sendQueue = new LinkedList<>();
sendHandler = new MessageSendHandler();
}