当前位置: 首页>>代码示例>>Java>>正文


Java WebSocket类代码示例

本文整理汇总了Java中org.eclipse.jetty.websocket.WebSocket的典型用法代码示例。如果您正苦于以下问题:Java WebSocket类的具体用法?Java WebSocket怎么用?Java WebSocket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebSocket类属于org.eclipse.jetty.websocket包,在下文中一共展示了WebSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doWebSocketConnect

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
    if (isStopped) {
        return null;
    }

    // FIXME: Replace this with globally shared opaque token to allow secure failover
    Principal p = request.getUserPrincipal();
    String userName = p != null ? p.getName() : FAKE_USERNAME;

    UiWebSocket socket = new UiWebSocket(directory, userName);
    synchronized (sockets) {
        sockets.add(socket);
    }
    return socket;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:UiWebSocketServlet.java

示例2: toWebSocketConnection

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
WebSocketConnection toWebSocketConnection(final WebSocket.Connection connection) {
    return new WebSocketConnection() {
        @Override
        public void write(String data) throws IOException {
            connection.sendMessage(data);
        }

        @Override
        public void disconnect() {
            connection.disconnect();
        }

        @Override
        public boolean isOpen() {
            return connection.isOpen();
        }

        @Override
        public void setMaxIdleTime(int ms) {
            connection.setMaxIdleTime(ms);
        }
    };
}
 
开发者ID:alibaba,项目名称:jvm-sandbox,代码行数:24,代码来源:WebSocketAcceptorServlet.java

示例3: createNote

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
private void createNote(WebSocket conn, Notebook notebook, Message message) throws IOException {
  Note note = notebook.createNote();
  note.addParagraph(); // it's an empty note. so add one paragraph
  if (message != null) {
    String noteName = (String) message.get("name");
    if (noteName == null || noteName.isEmpty()){
      noteName = "Note " + note.getId();
    }
    note.setName(noteName);
  }

  note.persist();
  addConnectionToNote(note.id(), (NotebookSocket) conn);
  broadcastNote(note);
  broadcastNoteList();
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:17,代码来源:NotebookServer.java

示例4: WebSocketServer

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
public WebSocketServer(int port, String rootDirPath, final MainWindow m, final Statement smt, final java.sql.Connection sqlcon) {
	idCounter = 0;

	connector = new SelectChannelConnector();
	connector.setPort(port);
	addConnector(connector);

	wsHandler = new WebSocketHandler() {
		@Override
		public WebSocket doWebSocketConnect(HttpServletRequest request,
				String protocol) {
			idCounter++;
			System.out.printf("Protocol:%s\n", protocol);
			return new MyWebSocket(idCounter, m, smt, sqlcon);
		}
	};

	resHandler = new ResourceHandler();
	resHandler.setDirectoriesListed(true);
	resHandler.setResourceBase(rootDirPath);

	wsHandler.setHandler(resHandler);
	setHandler(wsHandler);
}
 
开发者ID:ryohashioka,项目名称:Visual-Programming-Environment-for-Coordinating-Appliances-and-Services-in-a-Smart-House,代码行数:25,代码来源:WebSocketServer.java

示例5: doWebSocketConnect

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
    // determine if we need to send in binary
    boolean binary = false;
    if(protocol.equals(PROTOCOL_BSON)) {
        binary = true;
    }
    // get the object mapper
    ObjectMapper mapper = getMapper(request, protocol);
    if(mapper == null) {
        throw new RuntimeException("Unknown protocol " + protocol);
    }
    // create transport
    JsonRpcWsTransport transport = new JsonRpcWsTransport(mapper, true);
    transport.setAcceptTextMessages(!binary);
    transport.setSendBinaryMessages(binary);
    // get server and handler
    JsonRpcServer server = getServer(request, protocol);
    Object handler = getHandler(request, protocol);
    // bind the transport and return it
    transport.bindServer(server, handler);
    return transport;
}
 
开发者ID:promovicz,项目名称:better-jsonrpc,代码行数:24,代码来源:JsonRpcWsServlet.java

示例6: doWebSocketConnect

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
/**
 * 构造模块的WebSocket通讯连接
 * <p>对应的模块必须实现了{@link WebSocketAcceptor}接口</p>
 * <p>访问的路径为/sandbox/module/websocket/MODULE_NAME</p>
 *
 * @param req      req
 * @param protocol websocket protocol
 * @return WebSocket
 */
@Override
public WebSocket doWebSocketConnect(final HttpServletRequest req,
                                    final String protocol) {

    final String uniqueId = parseUniqueId(req.getPathInfo());
    if (StringUtils.isBlank(uniqueId)) {
        logger.warn("websocket value={} is illegal.", req.getPathInfo());
        return null;
    }

    final CoreModule coreModule = coreModuleManager.get(uniqueId);
    if (null == coreModule) {
        logger.warn("module[id={};] was not existed.", uniqueId);
        return null;
    }

    if (!(coreModule.getModule() instanceof WebSocketAcceptor)) {
        logger.warn("module[id={};class={};] is not implements WebSocketAcceptor.",
                uniqueId, coreModule.getModule().getClass());
        return null;
    }

    final WebSocketConnectionListener listener =
            ((WebSocketAcceptor) coreModule.getModule()).onAccept(req, protocol);
    logger.info("accept websocket connection, module[id={};class={};], value={};",
            uniqueId, coreModule.getModule().getClass(), req.getPathInfo());

    if (listener instanceof TextMessageListener) {
        return new InnerOnTextMessage(uniqueId, (TextMessageListener) listener);
    } else {
        return new InnerWebSocket(uniqueId, listener);
    }
}
 
开发者ID:alibaba,项目名称:jvm-sandbox,代码行数:43,代码来源:WebSocketAcceptorServlet.java

示例7: execute

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
@Override
public Object execute(ActionArgumentAggregatorFactory.ActionArgumentAggregator aggregator) throws Exception {
    HttpServletRequest request = aggregator.find(HttpServletRequest.class, InstanceSource.Request);
    HttpServletResponse response = aggregator.find(HttpServletResponse.class, InstanceSource.Request);
    WebSocket webSocket = socketImplDelegate.apply(aggregator);
    WebSocketFactory.Acceptor acceptor = WebSocketAcceptorFactory.factorize(webSocket);

    new WebSocketFactory(acceptor).acceptWebSocket(request, response);

    return ActionResult.NoOp();
}
 
开发者ID:ShotaOd,项目名称:carbon,代码行数:12,代码来源:WebSocketActionFactory.java

示例8: updateNote

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
private void updateNote(WebSocket conn, Notebook notebook, Message fromMessage)
    throws SchedulerException, IOException {
  String noteId = (String) fromMessage.get("id");
  String name = (String) fromMessage.get("name");
  Map<String, Object> config = (Map<String, Object>) fromMessage
      .get("config");
  if (noteId == null) {
    return;
  }
  if (config == null) {
    return;
  }

  Note note = notebook.getNote(noteId);
  if (note != null) {
    boolean cronUpdated = isCronUpdated(config, note.getConfig());
    note.setName(name);
    note.setConfig(config);
    if (cronUpdated) {
      notebook.refreshCron(note.id());
    }

    note.persist();
    broadcastNote(note);
    broadcastNoteList();
  }
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:28,代码来源:NotebookServer.java

示例9: removeNote

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
private void removeNote(WebSocket conn, Notebook notebook, Message fromMessage)
    throws IOException {
  String noteId = (String) fromMessage.get("id");
  if (noteId == null) {
    return;
  }

  Note note = notebook.getNote(noteId);
  notebook.removeNote(noteId);
  removeNote(noteId);
  broadcastNoteList();
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:13,代码来源:NotebookServer.java

示例10: doWebSocketConnect

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol)
{
  @SuppressWarnings("unchecked")
  PRINCIPAL principal = (PRINCIPAL)request.getAttribute(authAttribute);
  return new PubSubWebSocket(principal);
}
 
开发者ID:apache,项目名称:apex-core,代码行数:8,代码来源:PubSubWebSocketServlet.java

示例11: start

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
public void start() throws Exception
{
  server = new Server();
  Connector connector = new SelectChannelConnector();
  connector.setPort(port);
  server.addConnector(connector);

    // Setup the basic application "context" for this application at "/"
  // This is also known as the handler tree (in jetty speak)
  ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
  contextHandler.setContextPath("/");
  server.setHandler(contextHandler);
  WebSocketServlet webSocketServlet = new WebSocketServlet()
  {
    @Override
    public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol)
    {
      return websocket;
    }
  };

  contextHandler.addServlet(new ServletHolder(webSocketServlet), "/pubsub");
  server.start();
  if (port == 0) {
    port = server.getConnectors()[0].getLocalPort();
  }
}
 
开发者ID:apache,项目名称:apex-core,代码行数:28,代码来源:StramTestSupport.java

示例12: simpleTest

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
@Test
public void simpleTest() throws Exception
{
  final int port = 6666;
  String connectionURI = "ws://localhost:" + port + WebSocketServerInputOperator.DEFAULT_EXTENSION;

  final String message = "hello world";

  WebSocketServerInputOperator wssio = new TestWSSIO();
  wssio.setPort(port);
  wssio.setup(null);

  WebSocketClientFactory clientFactory = new WebSocketClientFactory();
  clientFactory.start();
  WebSocketClient client = new WebSocketClient(clientFactory);

  Future<WebSocket.Connection> connectionFuture = client.open(new URI(connectionURI), new TestWebSocket());
  WebSocket.Connection connection = connectionFuture.get(5, TimeUnit.SECONDS);

  connection.sendMessage(message);

  long startTime = System.currentTimeMillis();

  while (startTime + 10000 > System.currentTimeMillis()) {
    if (TestWSSIO.messages.size() >= 1) {
      break;
    }
    Thread.sleep(100);
  }

  Assert.assertEquals("The number of messages recieved is incorrect.", 1, TestWSSIO.messages.size());
  Assert.assertEquals("Incorrect message received", message, TestWSSIO.messages.get(0));

  connection.close();
  wssio.teardown();
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:37,代码来源:WebSocketServerInputOperatorTest.java

示例13: doWebSocketConnect

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
    TopologyViewWebSocket socket = new TopologyViewWebSocket(directory);
    synchronized (sockets) {
        sockets.add(socket);
    }
    return socket;
}
 
开发者ID:ravikumaran2015,项目名称:ravikumaran201504,代码行数:9,代码来源:GuiWebSocketServlet.java

示例14: doWebSocketConnect

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
    UiWebSocket socket = new UiWebSocket(directory);
    synchronized (sockets) {
        sockets.add(socket);
    }
    return socket;
}
 
开发者ID:ravikumaran2015,项目名称:ravikumaran201504,代码行数:9,代码来源:UiWebSocketServlet.java

示例15: doWebSocketConnect

import org.eclipse.jetty.websocket.WebSocket; //导入依赖的package包/类
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
    WebSocket socket;
    if (protocol.startsWith("mqtt")) {
        socket = new MQTTSocket();
    } else {
        socket = new StompSocket();
    }
    listener.onAccept((Transport)socket);
    return socket;
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:12,代码来源:WSServlet.java


注:本文中的org.eclipse.jetty.websocket.WebSocket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。