Search in sources :

Example 6 with HelloResponse

use of org.bboxdb.network.packages.response.HelloResponse in project bboxdb by jnidzwetzki.

the class HandshakeHandler method handleRequest.

/**
 * Handle the handshake request
 */
@Override
public boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    logger.info("Handshaking with: {}", clientConnectionHandler.clientSocket.getInetAddress());
    try {
        final HelloRequest heloRequest = HelloRequest.decodeRequest(encodedPackage);
        clientConnectionHandler.setConnectionCapabilities(heloRequest.getPeerCapabilities());
        final HelloResponse responsePackage = new HelloResponse(packageSequence, NetworkConst.PROTOCOL_VERSION, clientConnectionHandler.getConnectionCapabilities());
        clientConnectionHandler.writeResultPackage(responsePackage);
        clientConnectionHandler.setConnectionStateToOpen();
        return true;
    } catch (Exception e) {
        logger.warn("Error while reading network package", e);
        final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
        clientConnectionHandler.writeResultPackage(responsePackage);
        return false;
    }
}
Also used : HelloResponse(org.bboxdb.network.packages.response.HelloResponse) HelloRequest(org.bboxdb.network.packages.request.HelloRequest) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Aggregations

HelloResponse (org.bboxdb.network.packages.response.HelloResponse)6 ByteBuffer (java.nio.ByteBuffer)3 PeerCapabilities (org.bboxdb.network.capabilities.PeerCapabilities)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)2 HelloRequest (org.bboxdb.network.packages.request.HelloRequest)2 InputStream (java.io.InputStream)1 SocketException (java.net.SocketException)1 ExecutionException (java.util.concurrent.ExecutionException)1 HelloFuture (org.bboxdb.network.client.future.HelloFuture)1 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)1 CompressionEnvelopeResponse (org.bboxdb.network.packages.response.CompressionEnvelopeResponse)1 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)1