Search in sources :

Example 1 with GridClientFutureListener

use of org.apache.ignite.internal.client.GridClientFutureListener in project ignite by apache.

the class GridTcpRouterNioListenerAdapter method onMessage.

/** {@inheritDoc} */
@SuppressWarnings("TypeMayBeWeakened")
@Override
public void onMessage(final GridNioSession ses, final GridClientMessage msg) {
    if (msg instanceof GridRouterRequest) {
        GridRouterRequest routerMsg = (GridRouterRequest) msg;
        final UUID clientId = routerMsg.clientId();
        final long reqId = routerMsg.requestId();
        try {
            client.forwardMessage(routerMsg, routerMsg.destinationId(), ses.<Byte>meta(MARSHALLER_ID.ordinal())).listen(new GridClientFutureListener() {

                @Override
                public void onDone(GridClientFuture fut) {
                    try {
                        GridRouterResponse res = (GridRouterResponse) fut.get();
                        // Restoring original request id, because it was overwritten by the client.
                        res.requestId(reqId);
                        ses.send(res);
                    } catch (GridClientException e) {
                        ses.send(makeFailureResponse(e, clientId, reqId));
                    }
                }
            });
        } catch (GridClientException e) {
            ses.send(makeFailureResponse(e, clientId, reqId));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            U.warn(log, "Message forwarding was interrupted (will ignore last message): " + e.getMessage(), "Message forwarding was interrupted.");
        }
    } else if (msg instanceof GridClientHandshakeRequest) {
        GridClientHandshakeRequest hs = (GridClientHandshakeRequest) msg;
        short ver = hs.version();
        if (!SUPP_VERS.contains(ver)) {
            U.error(log, "Client protocol version is not supported [ses=" + ses + ", ver=" + ver + ", supported=" + SUPP_VERS + ']');
            ses.close();
        } else {
            byte marshId = hs.marshallerId();
            GridClientMarshaller marsh = marshMap.get(marshId);
            if (marsh == null) {
                U.error(log, "Client marshaller ID is invalid. Note that .NET and C++ clients " + "are supported only in enterprise edition [ses=" + ses + ", marshId=" + marshId + ']');
                ses.close();
            } else {
                ses.addMeta(MARSHALLER_ID.ordinal(), marshId);
                ses.addMeta(MARSHALLER.ordinal(), marsh);
                ses.send(GridClientHandshakeResponse.OK);
            }
        }
    } else if (msg instanceof GridClientPingPacket)
        ses.send(GridClientPingPacket.PING_MESSAGE);
    else
        throw new IllegalArgumentException("Unsupported input message: " + msg);
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientFuture(org.apache.ignite.internal.client.GridClientFuture) GridRouterResponse(org.apache.ignite.internal.processors.rest.client.message.GridRouterResponse) GridClientMarshaller(org.apache.ignite.internal.client.marshaller.GridClientMarshaller) GridRouterRequest(org.apache.ignite.internal.processors.rest.client.message.GridRouterRequest) GridClientPingPacket(org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacket) GridClientFutureListener(org.apache.ignite.internal.client.GridClientFutureListener) GridClientHandshakeRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequest) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)1 GridClientException (org.apache.ignite.internal.client.GridClientException)1 GridClientFuture (org.apache.ignite.internal.client.GridClientFuture)1 GridClientFutureListener (org.apache.ignite.internal.client.GridClientFutureListener)1 GridClientMarshaller (org.apache.ignite.internal.client.marshaller.GridClientMarshaller)1 GridClientHandshakeRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequest)1 GridClientPingPacket (org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacket)1 GridRouterRequest (org.apache.ignite.internal.processors.rest.client.message.GridRouterRequest)1 GridRouterResponse (org.apache.ignite.internal.processors.rest.client.message.GridRouterResponse)1