Search in sources :

Example 1 with OnOpen

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();
    }
}
Also used : ServerEndpoint(javax.websocket.server.ServerEndpoint) OnOpen(javax.websocket.OnOpen)

Example 2 with OnOpen

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);
    }
}
Also used : Streamer(org.bimserver.servlets.Streamer) BimServer(org.bimserver.BimServer) ServletContext(javax.servlet.ServletContext) OnOpen(javax.websocket.OnOpen)

Example 3 with OnOpen

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);
}
Also used : Message(com.baeldung.model.Message) OnMessage(javax.websocket.OnMessage) OnOpen(javax.websocket.OnOpen)

Example 4 with OnOpen

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);
    }
}
Also used : LanguageClient(org.eclipse.lsp4j.services.LanguageClient) ExecutionException(java.util.concurrent.ExecutionException) OnOpen(javax.websocket.OnOpen)

Example 5 with OnOpen

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())));
            }
        }
    }
}
Also used : CoOpsUsageException(fi.foyt.coops.CoOpsUsageException) CoOpsSession(fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession) CoOpsForbiddenException(fi.foyt.coops.CoOpsForbiddenException) CloseReason(javax.websocket.CloseReason) CoOpsInternalErrorException(fi.foyt.coops.CoOpsInternalErrorException) CoOpsNotFoundException(fi.foyt.coops.CoOpsNotFoundException) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial) ErrorMessage(fi.foyt.coops.extensions.websocket.ErrorMessage) Patch(fi.foyt.coops.model.Patch) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) CoOpsSession(fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession) Session(javax.websocket.Session) OnOpen(javax.websocket.OnOpen)

Aggregations

OnOpen (javax.websocket.OnOpen)5 Message (com.baeldung.model.Message)1 CoOpsForbiddenException (fi.foyt.coops.CoOpsForbiddenException)1 CoOpsInternalErrorException (fi.foyt.coops.CoOpsInternalErrorException)1 CoOpsNotFoundException (fi.foyt.coops.CoOpsNotFoundException)1 CoOpsUsageException (fi.foyt.coops.CoOpsUsageException)1 ErrorMessage (fi.foyt.coops.extensions.websocket.ErrorMessage)1 Patch (fi.foyt.coops.model.Patch)1 CoOpsSession (fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1 ExecutionException (java.util.concurrent.ExecutionException)1 ServletContext (javax.servlet.ServletContext)1 CloseReason (javax.websocket.CloseReason)1 OnMessage (javax.websocket.OnMessage)1 Session (javax.websocket.Session)1 ServerEndpoint (javax.websocket.server.ServerEndpoint)1 BimServer (org.bimserver.BimServer)1 Streamer (org.bimserver.servlets.Streamer)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 LanguageClient (org.eclipse.lsp4j.services.LanguageClient)1