org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect Java Examples

The following examples show how to use org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSocketProvider.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@OnWebSocketConnect @SuppressWarnings("unused")
public void onWebSocketConnect(final Session session)
{
    SocketAddress localAddress = session.getLocalAddress();
    SocketAddress remoteAddress = session.getRemoteAddress();
    _protocolEngine = _factory.newProtocolEngine(remoteAddress);

    // Let AMQP do timeout handling
    session.setIdleTimeout(0);

    _connectionWrapper = new ConnectionWrapper(session, localAddress, remoteAddress, _protocolEngine, _server.getThreadPool());
    if (session.getUpgradeRequest() instanceof ServletUpgradeRequest)
    {
        ServletUpgradeRequest upgradeRequest = (ServletUpgradeRequest) session.getUpgradeRequest();
        if (upgradeRequest.getCertificates() != null && upgradeRequest.getCertificates().length > 0)
        {
            _connectionWrapper.setPeerCertificate(upgradeRequest.getCertificates()[0]);
        }
    }
    _protocolEngine.setNetworkConnection(_connectionWrapper);
    _protocolEngine.setWorkListener(object -> _server.getThreadPool().execute(() -> _connectionWrapper.doWork()));
    _activeConnections.add(_connectionWrapper);
    _idleTimeoutChecker.wakeup();

}
 
Example #2
Source File: SocketImplementation.java    From hapi-fhir-jpaserver-starter with Apache License 2.0 6 votes vote down vote up
/**
 * This method is executed when the client is connecting to the server.
 * In this case, we are sending a message to create the subscription dynamiclly
 *
 * @param session
 */
@OnWebSocketConnect
public void onConnect(Session session) {
	ourLog.info("Got connect: {}", session);
	this.session = session;
	try {
		String sending = "bind " + myCriteria;
		ourLog.info("Sending: {}", sending);
		session.getRemote().sendString(sending);

		ourLog.info("Connection: DONE");
	} catch (Throwable t) {
		t.printStackTrace();
		ourLog.error("Failure", t);
	}
}
 
Example #3
Source File: ConsoleLogSocket.java    From gocd with Apache License 2.0 6 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) throws Exception {
    this.session = session;
    socketHealthService.register(this);
    LOGGER.debug("{} connected", sessionName());

    session.getRemote().sendString(consoleLogCharsetJSONMessage);

    long start = parseStartLine(session.getUpgradeRequest());
    LOGGER.debug("{} sending logs for {} starting at line {}.", sessionName(), jobIdentifier, start);

    try {
        handler.process(this, jobIdentifier, start);
    } catch (IOException e) {
        if ("Connection output is closed".equals(e.getMessage())) {
            LOGGER.debug("{} client (likely, browser) closed connection prematurely.", sessionName());
            close(); // for good measure
        } else {
            throw e;
        }
    }
}
 
Example #4
Source File: WebSocketClientSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
  if (StringUtils.isNotEmpty(this.conf.requestBody)) {
    try {
      session.getRemote().sendString(this.conf.requestBody);
    } catch (IOException e) {
      errorQueue.offer(e);
      LOG.error(Errors.WEB_SOCKET_04.getMessage(), e.toString(), e);
    }
  }
}
 
Example #5
Source File: SonyAudioClientSocket.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session wssession) {
    logger.debug("Connected to server");
    session = wssession;
    connected = true;
    if (eventHandler != null) {
        scheduler.submit(() -> {
            try {
                eventHandler.onConnectionOpened(uri);
            } catch (Exception e) {
                logger.error("Error handling onConnectionOpened() {}", e.getMessage(), e);
            }
        });
    }
}
 
Example #6
Source File: JettySocket.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
    this.session = session;
    connected = true;
    closeLatch.countDown();
    startPing();
}
 
Example #7
Source File: JettySocket.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
    this.session = session;
    connected = true;
    closeLatch.countDown();
    startPing();
}
 
Example #8
Source File: SimpleWebSocket.java    From java-11-examples with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
    LOG.info("onConnect");
    this.session = session;
    this.openLatch.countDown();
    this.sessionListener.onSessionReady();
}
 
Example #9
Source File: JettyWebSocketHandlerAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@OnWebSocketConnect
public void onWebSocketConnect(Session session) {
	try {
		this.wsSession.initializeNativeSession(session);
		this.webSocketHandler.afterConnectionEstablished(this.wsSession);
	}
	catch (Throwable ex) {
		ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
	}
}
 
Example #10
Source File: JettyWebSocketHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@OnWebSocketConnect
public void onWebSocketConnect(Session session) {
	this.delegateSession = this.sessionFactory.apply(session);
	this.delegateHandler.handle(this.delegateSession)
			.checkpoint(session.getUpgradeRequest().getRequestURI() + " [JettyWebSocketHandlerAdapter]")
			.subscribe(this.delegateSession);
}
 
Example #11
Source File: MinicapWebSocketHandler.java    From android-uiconductor with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
  Integer port = ((WebSocketSession) session).getRequestURI().getPort();
  if (MinicapServerManager.portSessionMapping.get(port) == null) {
    MinicapServerManager.portSessionMapping.put(port, new ConcurrentSet<>());
  }
  MinicapServerManager.portSessionMapping.get(port).add(session);
  System.out.println("New session opened");
}
 
Example #12
Source File: LogWebSocketHandler.java    From android-uiconductor with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
  logger.info("New session connect to log server.");
  session.setIdleTimeout(IDLE_TIMEOUT.toMillis());

  // start new thread to handle log
  TailLogThread thread = new TailLogThread(session);
  thread.start();
}
 
Example #13
Source File: ServiceSocket.java    From JMeter-WebSocketSampler with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onOpen(Session session) {
    logMessage.append(" - WebSocket conection has been opened").append("\n");
    log.debug("Connect " + session.isOpen());
    this.session = session;
    connected = true;
    openLatch.countDown();
}
 
Example #14
Source File: JettyWebSocketHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onWebSocketConnect(Session session) {
	try {
		this.wsSession.initializeNativeSession(session);
		this.webSocketHandler.afterConnectionEstablished(this.wsSession);
	}
	catch (Throwable ex) {
		ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
	}
}
 
Example #15
Source File: ThreadedChatWebSocket.java    From flowchat with GNU General Public License v3.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {

  try {
    Tools.dbInit();

    // Get or create the session scope
    SessionScope ss = setupSessionScope(session);

    sendRecurringPings(session);

    // Send them their user info
    // TODO
    // session.getRemote().sendString(ss.getUserObj().json("user"));

    LazyList<Model> comments = fetchComments(ss);

    // send the comments
    sendMessage(session,
        messageWrapper(MessageType.Comments, Comments
            .create(comments, fetchVotesMap(ss.getUserObj().getId()), topLimit, maxDepth, ss.getCommentComparator())
            .json()));

    // send the updated users to everyone in the right scope(just discussion)
    Set<SessionScope> filteredScopes = SessionScope.constructFilteredUserScopesFromSessionRequest(sessionScopes,
        session);
    broadcastMessage(filteredScopes,
        messageWrapper(MessageType.Users, Users.create(SessionScope.getUserObjects(filteredScopes)).json()));

    log.debug("session scope " + ss + " joined");

  } catch (Exception e) {
    e.printStackTrace();
  } finally {
    Tools.dbClose();
  }

}
 
Example #16
Source File: WebsocketAPI.java    From cineast with MIT License 5 votes vote down vote up
/**
 * Invoked whenever a new connection is established. Configures the session and stashes it in the {@link WebsocketAPI#SESSIONS} map.
 *
 * @param session Session associated with the new connection.
 */
@OnWebSocketConnect
public void connected(Session session) {
    session.getPolicy().setMaxTextMessageSize(Config.sharedConfig().getApi().getMaxMessageSize());
    session.getPolicy().setMaxBinaryMessageSize(Config.sharedConfig().getApi().getMaxMessageSize());
    SESSIONS.add(session);
    LOGGER.debug("New session {} connected!", session.getRemoteAddress().toString());
}
 
Example #17
Source File: CoinbaseSocket.java    From cloud-bigtable-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Upon connection to the Coinbase Websocket market feed, we send our
 * subscription message to indicate the product we want to subscribe to.
 * @param session Websocket session
 */
@OnWebSocketConnect
public void onConnect(Session session) {
  LOG.info("Got connect: %s%n", session);
  try {
    Future<Void> fut;
    fut = session.getRemote().sendStringByFuture(COINBASE_SUBSCRIBE_MESSAGE);
    fut.get(2, TimeUnit.SECONDS);
  } catch (Throwable t) {
    t.printStackTrace();
  }
}
 
Example #18
Source File: EgressInteractiveHandler.java    From warp10-platform with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onWebSocketConnect(Session session) {
  if (this.handler.capacity <= this.handler.connections.get()) {
    try {
      session.getRemote().sendString("// Maximum server capacity is reached (" + this.handler.capacity + ").");
      session.disconnect();
    } catch (IOException ioe) {
      throw new RuntimeException(ioe);
    }
  }
  
  this.handler.connections.incrementAndGet();

  this.processor.init(session);
}
 
Example #19
Source File: XmppWebSocket.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session)
{
    wsSession = session;
    wsConnection = new WebSocketConnection(this, session.getRemoteAddress());
    pingTask = new PingTask();
    TaskEngine.getInstance().schedule(pingTask, JiveConstants.MINUTE, JiveConstants.MINUTE);
}
 
Example #20
Source File: JobAnalysisSocket.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * On connect.
 *
 * @param session
 *            the session
 * @throws Exception
 *             the exception
 */
@OnWebSocketConnect
public void onConnect(Session session) {
	LOGGER.debug("Connected to result socket. Executing job: " + jobName);
	SocketPinger socketPinger = null;
	try {
		socketPinger = new SocketPinger(session);
		new Thread(socketPinger).start();
		String result = getReport();
		if (isJobScheduled(jobName)) {
			session.getRemote().sendString(getScheduledTuningJobResult(jobName));
		} else if (result != null) {
			session.getRemote().sendString(result);
		} else {
			HttpReportsBean reports = triggerJumbuneJob();
			asyncPublishResult(reports, session);
		}

	} catch (Exception e) {
		LOGGER.error(JumbuneRuntimeException.throwException(e.getStackTrace()));
	} finally {
		socketPinger.terminate();
		if (session != null && session.isOpen()) {
			session.close();
		}
		LOGGER.debug("Session closed sucessfully");
	}
}
 
Example #21
Source File: MyWebSocketHandler.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
    System.out.println("Connect: " + session.getRemoteAddress().getAddress());
    try {
        session.getRemote().sendString("Hello Webbrowser");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #22
Source File: VisWebSocket.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onOpen (Session peer) {
    if (!peers.contains(peer)){
        peers.add(peer);
        System.out.println("Connected... adding peer");
        this.setChanged();
        this.notifyObservers();
    }
    
    
}
 
Example #23
Source File: SimpleEchoSocket.java    From java_rosbridge with GNU Lesser General Public License v3.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
	System.out.printf("Got connect: %s%n", session);
	this.session = session;
	try {
		Future<Void> fut;
		fut = session.getRemote().sendStringByFuture("Hello");
		fut.get(2, TimeUnit.SECONDS);
		fut = session.getRemote().sendStringByFuture("Thanks for the conversation.");
		fut.get(2, TimeUnit.SECONDS);
		session.close(StatusCode.NORMAL, "I'm done");
	} catch (Throwable t) {
		t.printStackTrace();
	}
}
 
Example #24
Source File: RosBridge.java    From java_rosbridge with GNU Lesser General Public License v3.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
	System.out.printf("Got connect for ros: %s%n", session);
	this.session = session;
	this.hasConnected = true;
	synchronized(this) {
		this.notifyAll();
	}

}
 
Example #25
Source File: WebSocketChannelImpl.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onOpen(Session session) {
  synchronized (this) {
    this.session = session;
    count++;
  }

  LOG.info("Websocket[" + connectionId + "] open (#" + count + ")");
}
 
Example #26
Source File: SimpleEchoSocket.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
  System.out.printf("Got connect: %s%n",session);
  try {
    Future<Void> fut = session.getRemote().sendStringByFuture("{\"field1\" : \"value\"}");
    fut.get(2, TimeUnit.SECONDS); // wait for send to complete.

    session.close(StatusCode.NORMAL,"I'm done");
  } catch (Throwable t) {
    t.printStackTrace();
  }
}
 
Example #27
Source File: JettyWebSocketHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@OnWebSocketConnect
public void onWebSocketConnect(Session session) {
	try {
		this.wsSession.initializeNativeSession(session);
		this.webSocketHandler.afterConnectionEstablished(this.wsSession);
	}
	catch (Throwable ex) {
		ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
	}
}
 
Example #28
Source File: WebSocketRunnerMock.java    From codenjoy with GNU General Public License v3.0 4 votes vote down vote up
@OnWebSocketConnect
public void onConnect(Session session) {
    System.out.println("client started!");
    started = true;
}
 
Example #29
Source File: ChatWebSocket.java    From tp_java_2015_02 with MIT License 4 votes vote down vote up
@OnWebSocketConnect
public void onOpen(Session session) {
    users.add(this);
    setSession(session);
    logger.info("onOpen");
}
 
Example #30
Source File: GameWebSocket.java    From tp_java_2015_02 with MIT License 4 votes vote down vote up
@OnWebSocketConnect
public void onOpen(Session session) {
    setSession(session);
    webSocketService.addUser(this);
    gameMechanics.addUser(myName);
}