Java Code Examples for javax.websocket.SendResult#isOK()

The following examples show how to use javax.websocket.SendResult#isOK() . 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: MessageSender.java    From everrest with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void onResult(SendResult result) {
    LOG.debug(" SendQueue size {} ,  maxNumberOfMessageInQueue {} result {}",
              sendQueue.size(),
              maxNumberOfMessageInQueue,
              result.isOK());

    if (!result.isOK()) {
        try {
            session.close();
        } catch (IOException ignored) {
        } finally {
            sendQueue.clear();
        }
    }
    synchronized (lock) {
        if (sendQueue.isEmpty()) {
            sendingInProgress = false;
        } else {
            MessageWrapper message = sendQueue.remove();
            doSend(message);
        }
    }
}
 
Example 2
Source File: WsRemoteEndpointImplBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (isDone) {
        endpoint.stateMachine.complete(isLast);
        handler.onResult(result);
    } else if(!result.isOK()) {
        handler.onResult(result);
    } else if (closed){
        SendResult sr = new SendResult(new IOException(
                sm.getString("wsRemoteEndpoint.closedDuringMessage")));
        handler.onResult(sr);
    } else {
        write();
    }
}
 
Example 3
Source File: Client.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (!result.isOK()) {
        // Message could not be sent. In this case, we don't
        // set isSendingMessage to false because we must assume the connection
        // broke (and onClose will be called), so we don't try to send
        // other messages.
        // As a precaution, we close the session (e.g. if a send timeout occured).
        // TODO: session.close() blocks, while this handler shouldn't block.
        // Ideally, there should be some abort() method that cancels the
        // connection immediately...
        try {
            session.close();
        } catch (IOException ex) {
            // Ignore
        }
    }
    synchronized (messagesToSend) {

        if (!messagesToSend.isEmpty()) {
            AbstractWebsocketMessage msg = messagesToSend.remove();
            messagesToSendLength -= calculateMessageLength(msg);

            internalSendMessageAsync(msg);

        } else {
            isSendingMessage = false;
        }

    }
}
 
Example 4
Source File: WsRemoteEndpointImplBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        stateMachine.complete(true);
    }
    handler.onResult(result);
}
 
Example 5
Source File: WsRemoteEndpointImplBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        outputBuffer.clear();
    }
    handler.onResult(result);
}
 
Example 6
Source File: WsRemoteEndpointImplBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        if (outputBuffer.hasRemaining()) {
            endpoint.doWrite(this, outputBuffer);
        } else {
            outputBuffer.clear();
            write();
        }
    } else {
        handler.onResult(result);
    }
}
 
Example 7
Source File: WsRemoteEndpointImplBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (isDone) {
        endpoint.stateMachine.complete(isLast);
        handler.onResult(result);
    } else if(!result.isOK()) {
        handler.onResult(result);
    } else if (closed){
        SendResult sr = new SendResult(new IOException(
                sm.getString("wsRemoteEndpoint.closedDuringMessage")));
        handler.onResult(sr);
    } else {
        write();
    }
}
 
Example 8
Source File: WsRemoteEndpointImplBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        stateMachine.complete(true);
    }
    handler.onResult(result);
}
 
Example 9
Source File: WsRemoteEndpointImplBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        outputBuffer.clear();
    }
    handler.onResult(result);
}
 
Example 10
Source File: WsRemoteEndpointImplBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        if (outputBuffer.hasRemaining()) {
            endpoint.doWrite(this, outputBuffer);
        } else {
            outputBuffer.clear();
            write();
        }
    } else {
        handler.onResult(result);
    }
}
 
Example 11
Source File: Client.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (!result.isOK()) {
        // Message could not be sent. In this case, we don't
        // set isSendingMessage to false because we must assume the connection
        // broke (and onClose will be called), so we don't try to send
        // other messages.
        // As a precaution, we close the session (e.g. if a send timeout occurred).
        // TODO: session.close() blocks, while this handler shouldn't block.
        // Ideally, there should be some abort() method that cancels the
        // connection immediately...
        try {
            session.close();
        } catch (IOException ex) {
            // Ignore
        }
    }
    synchronized (messagesToSend) {

        if (!messagesToSend.isEmpty()) {
            AbstractWebsocketMessage msg = messagesToSend.remove();
            messagesToSendLength -= calculateMessageLength(msg);

            internalSendMessageAsync(msg);

        } else {
            isSendingMessage = false;
        }

    }
}
 
Example 12
Source File: StandardWebSocketSession.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
	if (result.isOK()) {
		getSendProcessor().setReadyToSend(true);
		getSendProcessor().onWritePossible();
	}
	else {
		getSendProcessor().cancel();
		getSendProcessor().onError(result.getException());
	}
}
 
Example 13
Source File: SendResultFuture.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (done) {
        return;
    }
    done = true;
    if (!result.isOK()) {
        exception = result.getException();
    }
    if (waiters > 0) {
        notifyAll();
    }
}
 
Example 14
Source File: StandardWebSocketSession.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
	if (result.isOK()) {
		getSendProcessor().setReadyToSend(true);
		getSendProcessor().onWritePossible();
	}
	else {
		getSendProcessor().cancel();
		getSendProcessor().onError(result.getException());
	}
}
 
Example 15
Source File: Client.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (!result.isOK()) {
        // Message could not be sent. In this case, we don't
        // set isSendingMessage to false because we must assume the connection
        // broke (and onClose will be called), so we don't try to send
        // other messages.
        // As a precaution, we close the session (e.g. if a send timeout occurred).
        // TODO: session.close() blocks, while this handler shouldn't block.
        // Ideally, there should be some abort() method that cancels the
        // connection immediately...
        try {
            session.close();
        } catch (IOException ex) {
            // Ignore
        }
    }
    synchronized (messagesToSend) {

        if (!messagesToSend.isEmpty()) {
            AbstractWebsocketMessage msg = messagesToSend.remove();
            messagesToSendLength -= calculateMessageLength(msg);

            internalSendMessageAsync(msg);

        } else {
            isSendingMessage = false;
        }

    }
}
 
Example 16
Source File: WsRemoteEndpointImplBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        stateMachine.complete(true);
    }
    handler.onResult(result);
}
 
Example 17
Source File: WsRemoteEndpointImplBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        outputBuffer.clear();
    }
    handler.onResult(result);
}
 
Example 18
Source File: WsRemoteEndpointImplBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (result.isOK()) {
        if (outputBuffer.hasRemaining()) {
            endpoint.doWrite(this, blockingWriteTimeoutExpiry, outputBuffer);
        } else {
            outputBuffer.clear();
            write();
        }
    } else {
        handler.onResult(result);
    }
}
 
Example 19
Source File: WsRemoteEndpointImplBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void onResult(SendResult result) {
    if (isDone) {
        endpoint.stateMachine.complete(isLast);
        handler.onResult(result);
    } else if(!result.isOK()) {
        handler.onResult(result);
    } else if (closed){
        SendResult sr = new SendResult(new IOException(
                sm.getString("wsRemoteEndpoint.closedDuringMessage")));
        handler.onResult(sr);
    } else {
        write();
    }
}
 
Example 20
Source File: AnnotatedEndpoint.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
public void onResult(final SendResult result) {
    if (!result.isOK()) {
        AnnotatedEndpoint.this.onError(session, result.getException());
    }
}