use of javax.websocket.OnOpen in project undertow by undertow-io.
the class ThreadSafetyEndpoint method onOpen.
@OnOpen
public void onOpen(final Session session) {
s = session;
for (int i = 0; i < NUM_THREADS; ++i) {
final int tnum = i;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (int j = 0; j < NUM_MESSAGES; ++j) {
session.getAsyncRemote().sendText("t" + tnum + "-m" + j);
}
}
});
t.start();
}
}
use of javax.websocket.OnOpen in project BIMserver by opensourceBIM.
the class Jsr356Impl method onOpen.
@OnOpen
public void onOpen(Session websocketSession, EndpointConfig config) {
LOGGER.debug("WebSocket open");
try {
this.websocketSession = websocketSession;
if (additionalWebSocketConfigurator != null) {
additionalWebSocketConfigurator.configure(websocketSession);
}
ServletContext servletContext = servletContexts.get(websocketSession.getContainer());
if (servletContext == null) {
servletContext = defaultServletContext;
}
BimServer bimServer = (BimServer) servletContext.getAttribute("bimserver");
streamer = new Streamer(this, bimServer);
streamer.onOpen();
} catch (Throwable t) {
LOGGER.error("", t);
}
}
use of javax.websocket.OnOpen in project tutorials by eugenp.
the class ChatEndpoint method onOpen.
@OnOpen
public void onOpen(Session session, @PathParam("username") String username) throws IOException, EncodeException {
this.session = session;
chatEndpoints.add(this);
users.put(session.getId(), username);
Message message = new Message();
message.setFrom(username);
message.setContent("Connected!");
broadcast(message);
}
use of javax.websocket.OnOpen in project ballerina by ballerina-lang.
the class BallerinaLangServerService method onOpen.
@OnOpen
public void onOpen(Session session) {
sessions.add(session);
if (launcher != null) {
return;
}
this.launcher = this.launchRPCServer(server, LanguageClient.class);
LanguageClient client = launcher.getRemoteProxy();
server.connect(client);
Future<?> startListening = launcher.startListening();
try {
startListening.get();
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Error starting language server", e);
}
}
use of javax.websocket.OnOpen in project muikku by otavanopisto.
the class CoOpsDocumentWebSocket method onOpen.
@OnOpen
public void onOpen(final Session client, EndpointConfig endpointConfig, @PathParam("HTMLMATERIALID") String htmlMaterialId, @PathParam("SESSIONID") String sessionId) throws IOException {
synchronized (this) {
//
// TODO: RequestScope is not available on the websockets, switch to ticket system
//
// if (!sessionController.isLoggedIn()) {
// client.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Permission denied"));
// }
//
// UserEntity userEntity = sessionController.getLoggedUserEntity();
//
// EnvironmentUser environmentUser = environmentUserController.findEnvironmentUserByUserEntity(userEntity);
//
// if (environmentUser.getRole() == null || environmentUser.getRole().getArchetype() == EnvironmentRoleArchetype.STUDENT) {
// client.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Permission denied"));
// }
CoOpsSession session = coOpsSessionController.findSessionBySessionId(sessionId);
if (session == null) {
client.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "Not Found"));
return;
}
if (!session.getHtmlMaterial().getId().equals(NumberUtils.createLong(htmlMaterialId))) {
client.close(new CloseReason(CloseReason.CloseCodes.VIOLATED_POLICY, "Session is associated with another fileId"));
return;
}
Map<String, Session> sessions = fileClients.get(htmlMaterialId);
if (sessions == null) {
fileClients.put(htmlMaterialId, new HashMap<String, Session>());
}
fileClients.get(htmlMaterialId).put(client.getId(), client);
coOpsSessionController.updateSessionType(session, CoOpsSessionType.WS);
HtmlMaterial htmlMaterial = session.getHtmlMaterial();
Long currentRevisionNumber = htmlMaterial.getRevisionNumber();
if (session.getJoinRevision() < currentRevisionNumber) {
ObjectMapper objectMapper = new ObjectMapper();
List<Patch> patches;
try {
patches = coOpsApi.fileUpdate(session.getHtmlMaterial().getId().toString(), session.getSessionId(), session.getJoinRevision());
for (Patch patch : patches) {
sendPatch(client, patch);
}
} catch (CoOpsInternalErrorException e) {
client.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, "Internal Error"));
} catch (CoOpsUsageException e) {
client.getAsyncRemote().sendText(objectMapper.writeValueAsString(new ErrorMessage("patchError", 400, e.getMessage())));
} catch (CoOpsNotFoundException e) {
client.getAsyncRemote().sendText(objectMapper.writeValueAsString(new ErrorMessage("patchError", 404, e.getMessage())));
} catch (CoOpsForbiddenException e) {
client.getAsyncRemote().sendText(objectMapper.writeValueAsString(new ErrorMessage("patchError", 500, e.getMessage())));
}
}
}
}
Aggregations