本文整理汇总了Java中org.eclipse.jetty.websocket.api.RemoteEndpoint类的典型用法代码示例。如果您正苦于以下问题:Java RemoteEndpoint类的具体用法?Java RemoteEndpoint怎么用?Java RemoteEndpoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RemoteEndpoint类属于org.eclipse.jetty.websocket.api包,在下文中一共展示了RemoteEndpoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
@Override
public void send( final String message )
{
final RemoteEndpoint endpoint = getRemote();
if ( endpoint == null )
{
return;
}
try
{
endpoint.sendString( message );
}
catch ( final Exception e )
{
LOG.log( Level.SEVERE, "Failed to send web-socket message", e );
}
}
示例2: sendMessage
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
public boolean sendMessage(Message message) {
try {
RemoteEndpoint remote = session.getRemote();
synchronized (remote) {
try {
remote.sendString(message.getBody());
return true;
} catch (Exception we) {
System.out.println("[GameWebSocketHandler] Ошибка при отправке пакета (" + we.getMessage() + "). Дисконнектинг игрока.");
return false;
}
}
} catch (Exception e) {
System.out.println("[GameWebSocketHandler] Ошибка при получении RemoteEndpoint (" + e.getMessage() + "). Дисконнектинг игрока.");
return false;
}
}
示例3: newNodeVisible
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
@FiberOnly
private void newNodeVisible(NewNodeVisible nodeVisibilityMessage) {
Availability availability = nodeVisibilityMessage.nodeInfo.availability;
ByteArrayOutputStream jsonBytes = new ByteArrayOutputStream();
try {
JsonIOUtil.writeTo(jsonBytes, availability, availability, false);
String jsonString = jsonBytes.toString();
String finalString = "{\"type\":\"newNode\", \"data\": " + jsonString + "}";
System.out.println(finalString);
for (WebsocketClient client : websocketClients) {
RemoteEndpoint wsRemote = client.getRemote();
if (wsRemote != null) {
client.getRemote().sendString(finalString);
}
}
} catch (IOException e) {
LOG.error("Processing new node visible message", e);
}
}
示例4: setUp
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
@Before
public void setUp() {
client = mock(GraqlClient.class);
Session session = mock(Session.class);
remote = mock(RemoteEndpoint.class);
CompletableFuture<Session> future = new CompletableFuture<>();
future.complete(session);
when(client.connect(any(), any())).thenReturn(future);
when(session.getRemote()).thenReturn(remote);
}
示例5: setUp
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
clientManager = new ClientManagerImpl(clientInformationHandler, singleDriverHandler);
// mocking session
session = mock(Session.class);
remoteEndpoint = mock(RemoteEndpoint.class);
when(session.getRemote()).thenReturn(remoteEndpoint);
when(session.getRemoteAddress()).thenReturn(new InetSocketAddress(0));
when(session.isOpen()).thenReturn(false);
}
示例6: send
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
public void send(WsContractDto contract) {
if ((this.getSession() == null) || !this.getSession().isOpen()) {
return;
}
RemoteEndpoint remoteEndpoint = this.getSession().getRemote();
String jsonResult = this.jsonConverter.toJson(contract);
remoteEndpoint.sendStringByFuture(jsonResult);
}
示例7: send
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
/**
* Receives a WSSocket object and WsContractDto to write it to the stream
*
* @param session
* @param contract
*/
public void send(WSSocket session, WsContractDto contract) {
if (session != null && session.isConnected()) {
RemoteEndpoint remoteEndpoint = session.getRemote();
String jsonResult = this.jsonConverter.toJson(contract);
remoteEndpoint.sendStringByFuture(jsonResult);
}
}
示例8: getRemote
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
private RemoteEndpoint getRemote()
{
try
{
return this.raw.getRemote();
}
catch ( final Exception e )
{
return null;
}
}
示例9: tabletStateChanges
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
@FiberOnly
private void tabletStateChanges(TabletStateChange tabletStateChange) {
// TODO send to the websockets
TabletStateNotification note = new TabletStateNotification(
tabletStateChange.tablet.getRegionInfo().getEncodedName(),
tabletStateChange.tablet.getRegionInfo().getRegionNameAsString(),
tabletStateChange.state.toString(),
tabletStateChange.tablet.getPeers(),
0
);
ByteArrayOutputStream jsonBytes = new ByteArrayOutputStream();
try {
JsonIOUtil.writeTo(jsonBytes, note, note, false);
String jsonString = jsonBytes.toString();
String finalString = "{\"type\":\"tablet\", \"data\": " + jsonString + "}";
System.out.println(finalString);
for (WebsocketClient client : websocketClients) {
RemoteEndpoint wsRemote = client.getRemote();
if (wsRemote != null) {
client.getRemote().sendString(finalString);
}
}
} catch (IOException e) {
LOG.error("Processing tablet message", e);
}
}
示例10: testProcess
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
@Test
public void testProcess() throws Exception {
HttpRoutingContext routingContext = new HttpRoutingContext();
HttpDmClient httpDmClient = new HttpDmClient( routingContext );
// Not connected => no processing
Message message = Mockito.mock( Message.class );
Session session = Mockito.mock( Session.class );
Mockito.when( session.isOpen()).thenReturn( false );
httpDmClient.process( session, message );
Mockito.verifyZeroInteractions( message );
Mockito.verify( session, Mockito.only()).isOpen();
// Connected => processing...
Mockito.reset( session );
Future<Void> future = Mockito.mock( Future.class );
RemoteEndpoint remote = Mockito.mock( RemoteEndpoint.class );
Mockito.when( remote.sendBytesByFuture( Mockito.any( ByteBuffer.class ) )).thenReturn( future );
Mockito.when( session.getRemote()).thenReturn( remote );
Mockito.when( session.isOpen()).thenReturn( true );
httpDmClient.process( session, message );
Mockito.verifyZeroInteractions( message );
Mockito.verify( session, Mockito.times( 1 )).isOpen();
Mockito.verify( session, Mockito.times( 1 )).getRemote();
Mockito.verifyNoMoreInteractions( session );
}
示例11: configuredHandler
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
private WebSocketHandler configuredHandler() {
this.session = Mockito.mock( Session.class );
this.remoteEndpoint = Mockito.mock( RemoteEndpoint.class );
Mockito.when( this.session.getRemote()).thenReturn( this.remoteEndpoint );
WebSocketHandler.addSession( this.session );
WebSocketHandler handler = new WebSocketHandler();
return handler;
}
示例12: KafkaClient
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
public KafkaClient(String zooKeeper, String groupId, String topic, RemoteEndpoint remote)
{
this.consumer = kafka.consumer.Consumer.createJavaConsumerConnector(
createConsumerConfig(zooKeeper, groupId ));
this.topic = topic;
this.remote = remote;
}
示例13: send
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
/**
* @param text
* the message to be sent
* @throws IOException
* if unable to send the text message
*/
void send(String text) throws IOException {
RemoteEndpoint remote = getRemote();
if (remote != null) {
// FIXME this log creates a recursion when using
// the "log start -l debug" console command via WebSockets
logger.debug("Sending: '{}' - Host: {}", text, hostname);
remote.sendStringByFuture(text);
}
}
示例14: sendBytes
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
@Override
public void sendBytes(final ByteBuffer data, final SuccessCallback success,
final OnError err) {
requireNonNull(data, NO_DATA_TO_SEND);
RemoteEndpoint remote = session.getRemote();
remote.sendBytes(data, callback(log, success, err));
}
示例15: sendText
import org.eclipse.jetty.websocket.api.RemoteEndpoint; //导入依赖的package包/类
@Override
public void sendText(final String data, final SuccessCallback success, final OnError err) {
requireNonNull(data, NO_DATA_TO_SEND);
RemoteEndpoint remote = session.getRemote();
remote.sendString(data, callback(log, success, err));
}