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


Java WebSocketException类代码示例

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


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

示例1: broadcast

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
/** Broadcast text to all connected clients. */
void broadcast(String message, Session sourceSession) {
	String sourceName = null;
	synchronized(sessionToName) {
		sourceName = sessionToName.get(sourceSession);
	}
	if (sourceName != null && !sourceName.isEmpty()) {
		message = "<strong>" + sourceName + "</strong>: " + message;
	}
	synchronized(sessionToName) {
		for (Session s : sessionToName.keySet()) {
			try {
				if (s.isOpen()) {
					s.getRemote().sendStringByFuture(message);
				}
			} catch (WebSocketException e) {
				System.out.println("The error " + e.getLocalizedMessage() + " occurred. This " 
						+ "can happen if the player dies before a broadcast arrives.");
			}
		}
	}
}
 
开发者ID:nashkevin,项目名称:Shape-Shmup,代码行数:23,代码来源:GameSocket.java

示例2: sendJson

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
void sendJson(Json json) throws WebSocketException, IOException {
    try {
        executor.submit(() -> {
            try {
                session.getRemote().sendString(json.toString());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).get();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (ExecutionException e) {
        Throwable inner = e.getCause();
        Throwable cause = inner.getCause();
        if (cause instanceof IOException) {
            throw (IOException) cause;
        } else {
            assert inner instanceof RuntimeException; // We know the runnable never throws a checked exception
            throw (RuntimeException) inner;
        }
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:23,代码来源:JsonSession.java

示例3: unicast

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
/** Send text to a single client */
void unicast(String message, Session session) {
	try {
		if (session.isOpen()) {
			session.getRemote().sendStringByFuture(message);
		}
	} catch (WebSocketException e) {
		System.out.println("The error " + e.getLocalizedMessage() + " occurred. This " 
				+ "can happen if the player dies before a unicast arrives.");
	}
}
 
开发者ID:nashkevin,项目名称:Shape-Shmup,代码行数:12,代码来源:GameSocket.java

示例4: onWebSocketText

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
@Override
public void onWebSocketText(String message)
{
    for (Session sess: sockets.values()){
        if (!sess.isOpen()) {
            sockets.remove(sess.getRemoteAddress().toString());
        } else {
            try {
                sess.getRemote().sendString(message);
            } catch (IOException | WebSocketException | IllegalStateException e) {
                // continue it may be closing / blocking etc..
                sockets.remove(sess.getRemoteAddress().toString());
            }
        }
    }
}
 
开发者ID:rozza,项目名称:reactiveBTC,代码行数:17,代码来源:TradeSocket.java

示例5: write

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
@Override
public void write(String message, Object writeLock) throws IOException {
    // The explicit connnectionClosed check is because the session is null until the connection is initially established
    if (connectionClosed) {
        throw new EOFException("WebSocket is closed.");
    }

    if (queuedMessageCount.get() > MAX_QUEUED_MESSAGES.get()) {
        throw new IOException("Reached max queued messages [" + MAX_QUEUED_MESSAGES.get() + "].");
    }

    if (session != null && session.isOpen()) {
        try {
            session.getRemote().sendString(message, new WebSocketWriteCallback(this));
            queuedMessageCount.incrementAndGet();
        } catch (WebSocketException e) {
            // Thrown if getRemote() determines the connection was closed by the client. No need to log.
            close();
        }
    }
}
 
开发者ID:rancher,项目名称:cattle,代码行数:22,代码来源:WebSocketMessageWriter.java

示例6: broadcast

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
public synchronized void broadcast(JSONObject message){
	if(message == null)
		return;
	
	for(ClientWebSocket subscriber : subscribers){
		try{
			subscriber.session.getRemote().sendStringByFuture(message.toString());
		}catch(WebSocketException e){
			subscribers.remove(subscriber);
			log.error(e);
		}
	}
}
 
开发者ID:BuaBook,项目名称:buabook-api-interface,代码行数:14,代码来源:Broadcaster.java

示例7: whenWebSocketFailsThenPingShouldThrowException

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
@Test
public void whenWebSocketFailsThenPingShouldThrowException() throws IOException {
    JsonSession session = mock(JsonSession.class);

    when(session.isOpen()).thenReturn(true);
    doThrow(new WebSocketException()).when(session).sendJson(any());

    exception.expect(RuntimeException.class);

    WebSocketPing.ping(session);
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:12,代码来源:WebSocketPingTest.java

示例8: whenWebSocketClosesThenPingShouldNotThrowException

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
@Test
public void whenWebSocketClosesThenPingShouldNotThrowException() throws IOException {
    JsonSession session = mock(JsonSession.class);

    when(session.isOpen()).thenReturn(false);
    doThrow(new WebSocketException()).when(session).sendJson(any());

    WebSocketPing.ping(session);
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:10,代码来源:WebSocketPingTest.java

示例9: sendResponse

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
/**
 * Send POST response
 *
 * This method is used by the connection acceptor to return the POST response
 *
 * @param   requestId           Request identifier
 * @param   response            Response message
 * @throws  IOException         I/O error occurred
 */
public void sendResponse(long requestId, String response) throws IOException {
    lock.lock();
    try {
        if (session != null && session.isOpen()) {
            byte[] responseBytes = response.getBytes("UTF-8");
            int responseLength = responseBytes.length;
            int flags = 0;
            if (isGzipEnabled && responseLength>=MIN_COMPRESS_SIZE) {
                flags |= FLAG_COMPRESSED;
                ByteArrayOutputStream outStream = new ByteArrayOutputStream(responseLength);
                try (GZIPOutputStream gzipStream = new GZIPOutputStream(outStream)) {
                    gzipStream.write(responseBytes);
                }
                responseBytes = outStream.toByteArray();
            }
            ByteBuffer buf = ByteBuffer.allocate(responseBytes.length + 20);
            buf.putInt(version)
               .putLong(requestId)
               .putInt(flags)
               .putInt(responseLength)
               .put(responseBytes)
               .flip();
            if (buf.limit() > MAX_MESSAGE_SIZE) {
                throw new ProtocolException("POST response length exceeds max message size");
            }
            session.getRemote().sendBytes(buf);
        }
    } catch (WebSocketException exc) {
        throw new SocketException(exc.getMessage());
    } finally {
        lock.unlock();
    }
}
 
开发者ID:BitcoinFullnode,项目名称:ROKOS-OK-Bitcoin-Fullnode,代码行数:43,代码来源:PeerWebSocket.java

示例10: retrieveGstreamerDots

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
@FailedTest
public static void retrieveGstreamerDots() {
  if (kurentoClient != null) {
    try {
      List<MediaPipeline> pipelines = kurentoClient.getServerManager().getPipelines();
      log.debug("Retrieving GStreamerDots for all pipelines in KMS ({})", pipelines.size());

      for (MediaPipeline pipeline : pipelines) {

        String pipelineName = pipeline.getName();
        log.debug("Saving GstreamerDot for pipeline {}", pipelineName);

        String gstreamerDotFile = KurentoTest.getDefaultOutputFile("-" + pipelineName);

        try {
          FileUtils.writeStringToFile(new File(gstreamerDotFile), pipeline.getGstreamerDot());

        } catch (IOException ioe) {
          log.error("Exception writing GstreamerDot file", ioe);
        }
      }
    } catch (WebSocketException e) {
      log.warn("WebSocket exception while reading existing pipelines. Maybe KMS is closed: {}:{}",
          e.getClass().getName(), e.getMessage());
    }
  }
}
 
开发者ID:Kurento,项目名称:kurento-java,代码行数:28,代码来源:KurentoClientBrowserTest.java

示例11: writeBytes

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
@Override
public synchronized void writeBytes(Address toAddress,
                                    byte[] message,
                                    long timeout,
                                    TimeUnit unit,
                                    final SuccessAction successAction,
                                    final FailureAction failureAction) {
    if (!(toAddress instanceof WebSocketClientAddress)) {
        throw new JoynrIllegalStateException("Web Socket Server can only send to WebSocketClientAddresses");
    }

    WebSocketClientAddress toClientAddress = (WebSocketClientAddress) toAddress;
    Session session = sessionMap.get(toClientAddress.getId());
    if (session == null) {
        //TODO We need a delay with invalidation of the stub
        throw new JoynrDelayMessageException("no active session for WebSocketClientAddress: "
                + toClientAddress.getId());
    }
    try {
        session.getRemote().sendBytes(ByteBuffer.wrap(message), new WriteCallback() {
            @Override
            public void writeSuccess() {
                successAction.execute();
            }

            @Override
            public void writeFailed(Throwable error) {
                if (shutdown) {
                    return;
                }
                failureAction.execute(error);
            }
        });
    } catch (WebSocketException e) {
        // Jetty throws WebSocketException when expecting [OPEN or CONNECTED] but found a different state
        // The client must reconnect, but the message can be queued in the mean time.
        sessionMap.remove(toClientAddress.getId());
        //TODO We need a delay with invalidation of the stub
        throw new JoynrDelayMessageException(e.getMessage(), e);
    }
}
 
开发者ID:bmwcarit,项目名称:joynr,代码行数:42,代码来源:WebSocketJettyServer.java

示例12: whenSendJsonSeesAWebSocketExceptionThenItShouldThrowItBack

import org.eclipse.jetty.websocket.api.WebSocketException; //导入依赖的package包/类
@Test
public void whenSendJsonSeesAWebSocketExceptionThenItShouldThrowItBack() throws IOException {
    doThrow(WebSocketException.class).when(remote).sendString(any());

    JsonSession jsonSession = new JsonSession(client, uri);

    exception.expect(WebSocketException.class);

    jsonSession.sendJson(Json.object(ACTION, ACTION_END));
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:11,代码来源:JsonSessionTest.java


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