Java Code Examples for org.springframework.messaging.tcp.TcpConnection#onReadInactivity()

The following examples show how to use org.springframework.messaging.tcp.TcpConnection#onReadInactivity() . 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: WebSocketStompClientTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void cancelInactivityTasks() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();

	ScheduledFuture future = mock(ScheduledFuture.class);
	given(this.taskScheduler.scheduleWithFixedDelay(any(), eq(1L))).willReturn(future);

	tcpConnection.onReadInactivity(mock(Runnable.class), 2L);
	tcpConnection.onWriteInactivity(mock(Runnable.class), 2L);

	this.webSocketHandlerCaptor.getValue().afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL);

	verify(future, times(2)).cancel(true);
	verifyNoMoreInteractions(future);
}
 
Example 2
Source File: WebSocketStompClientTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void cancelInactivityTasks() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();

	ScheduledFuture future = mock(ScheduledFuture.class);
	when(this.taskScheduler.scheduleWithFixedDelay(any(), eq(1L))).thenReturn(future);

	tcpConnection.onReadInactivity(mock(Runnable.class), 2L);
	tcpConnection.onWriteInactivity(mock(Runnable.class), 2L);

	this.webSocketHandlerCaptor.getValue().afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL);

	verify(future, times(2)).cancel(true);
	verifyNoMoreInteractions(future);
}
 
Example 3
Source File: WebSocketStompClientTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void cancelInactivityTasks() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();

	ScheduledFuture future = mock(ScheduledFuture.class);
	when(this.taskScheduler.scheduleWithFixedDelay(any(), eq(1L))).thenReturn(future);

	tcpConnection.onReadInactivity(mock(Runnable.class), 2L);
	tcpConnection.onWriteInactivity(mock(Runnable.class), 2L);

	this.webSocketHandlerCaptor.getValue().afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL);

	verify(future, times(2)).cancel(true);
	verifyNoMoreInteractions(future);
}
 
Example 4
Source File: StompBrokerRelayMessageHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void afterConnected(TcpConnection<byte[]> connection) {
	if (logger.isDebugEnabled()) {
		logger.debug("TCP connection opened in session=" + getSessionId());
	}
	this.tcpConnection = connection;
	connection.onReadInactivity(() -> {
		if (this.tcpConnection != null && !this.isStompConnected) {
			handleTcpConnectionFailure("No CONNECTED frame received in " +
					MAX_TIME_TO_CONNECTED_FRAME + " ms.", null);
		}
	}, MAX_TIME_TO_CONNECTED_FRAME);
	connection.send(MessageBuilder.createMessage(EMPTY_PAYLOAD, this.connectHeaders.getMessageHeaders()));
}
 
Example 5
Source File: WebSocketStompClientTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void readInactivityAfterDelayHasElapsed() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();
	Runnable runnable = mock(Runnable.class);
	long delay = 2;
	tcpConnection.onReadInactivity(runnable, delay);
	testInactivityTaskScheduling(runnable, delay, 10);
}
 
Example 6
Source File: WebSocketStompClientTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void readInactivityBeforeDelayHasElapsed() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();
	Runnable runnable = mock(Runnable.class);
	long delay = 10000;
	tcpConnection.onReadInactivity(runnable, delay);
	testInactivityTaskScheduling(runnable, delay, 0);
}
 
Example 7
Source File: StompBrokerRelayMessageHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterConnected(TcpConnection<byte[]> connection) {
	if (logger.isDebugEnabled()) {
		logger.debug("TCP connection opened in session=" + getSessionId());
	}
	this.tcpConnection = connection;
	connection.onReadInactivity(() -> {
		if (this.tcpConnection != null && !this.isStompConnected) {
			handleTcpConnectionFailure("No CONNECTED frame received in " +
					MAX_TIME_TO_CONNECTED_FRAME + " ms.", null);
		}
	}, MAX_TIME_TO_CONNECTED_FRAME);
	connection.send(MessageBuilder.createMessage(EMPTY_PAYLOAD, this.connectHeaders.getMessageHeaders()));
}
 
Example 8
Source File: WebSocketStompClientTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void readInactivityAfterDelayHasElapsed() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();
	Runnable runnable = mock(Runnable.class);
	long delay = 2;
	tcpConnection.onReadInactivity(runnable, delay);
	testInactivityTaskScheduling(runnable, delay, 10);
}
 
Example 9
Source File: WebSocketStompClientTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void readInactivityBeforeDelayHasElapsed() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();
	Runnable runnable = mock(Runnable.class);
	long delay = 10000;
	tcpConnection.onReadInactivity(runnable, delay);
	testInactivityTaskScheduling(runnable, delay, 0);
}
 
Example 10
Source File: WebSocketStompClientTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void readInactivityAfterDelayHasElapsed() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();
	Runnable runnable = mock(Runnable.class);
	long delay = 2;
	tcpConnection.onReadInactivity(runnable, delay);
	testInactivityTaskScheduling(runnable, delay, 10);
}
 
Example 11
Source File: WebSocketStompClientTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void readInactivityBeforeDelayHasElapsed() throws Exception {
	TcpConnection<byte[]> tcpConnection = getTcpConnection();
	Runnable runnable = mock(Runnable.class);
	long delay = 10000;
	tcpConnection.onReadInactivity(runnable, delay);
	testInactivityTaskScheduling(runnable, delay, 0);
}