Search in sources :

Example 1 with GridClientConnectionManager

use of org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager in project ignite by apache.

the class GridClientImpl method createConnectionManager.

/**
     * @param clientId Client ID.
     * @param sslCtx SSL context to enable secured connection or {@code null} to use unsecured one.
     * @param cfg Client configuration.
     * @param routers Routers or empty collection to use endpoints from topology info.
     * @param top Topology.
     * @throws GridClientException In case of error.
     */
private GridClientConnectionManager createConnectionManager(UUID clientId, SSLContext sslCtx, GridClientConfiguration cfg, Collection<InetSocketAddress> routers, GridClientTopology top, @Nullable Byte marshId, boolean routerClient) throws GridClientException {
    GridClientConnectionManager mgr;
    try {
        Class<?> cls = Class.forName(ENT_CONN_MGR_CLS);
        Constructor<?> cons = cls.getConstructor(UUID.class, SSLContext.class, GridClientConfiguration.class, Collection.class, GridClientTopology.class, Byte.class, boolean.class);
        mgr = (GridClientConnectionManager) cons.newInstance(clientId, sslCtx, cfg, routers, top, marshId, routerClient);
    } catch (ClassNotFoundException ignored) {
        mgr = new GridClientConnectionManagerOsImpl(clientId, sslCtx, cfg, routers, top, marshId, routerClient);
    } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new GridClientException("Failed to create client connection manager.", e);
    }
    return mgr;
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientConnectionManagerOsImpl(org.apache.ignite.internal.client.impl.connection.GridClientConnectionManagerOsImpl) GridClientConnectionManager(org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with GridClientConnectionManager

use of org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager in project ignite by apache.

the class GridRouterClientImpl method forwardMessage.

/**
     * Send a raw packet "as is" directly to the given node.
     * The exact types of acceptable arguments and return values depends on underlying connections.
     *
     * @param msg Raw message to send.
     * @param destId Id of node to send message to. If {@code null} than node will be chosen
     *     from the topology randomly.
     * @return Future, representing forwarded message.
     * @throws GridServerUnreachableException If destination node can't be reached.
     * @throws GridClientClosedException If client is closed.
     * @throws GridClientException If any other client-related error occurs.
     * @throws InterruptedException If router was interrupted while trying.
     *     to establish connection with destination node.
     */
GridClientFutureAdapter<?> forwardMessage(Object msg, @Nullable UUID destId, byte marshId) throws GridClientException, InterruptedException {
    GridClientTopology top = clientImpl.topology();
    GridClientNode dest = destId != null ? top.node(destId) : cliCfg.getBalancer().balancedNode(applyFilter(top.nodes(), new GridClientPredicate<GridClientNodeImpl>() {

        @Override
        public boolean apply(GridClientNodeImpl e) {
            return restAvailable(e, cliCfg.getProtocol());
        }
    }));
    if (dest == null)
        throw new GridServerUnreachableException("Failed to resolve node for specified destination ID: " + destId);
    GridClientConnectionManager connMgr = connectionManager(marshId);
    GridClientConnection conn = null;
    // No reconnection handling there. Let client to do it if needed.
    GridClientException cause;
    try {
        conn = connMgr.connection(dest);
        return conn.forwardMessage(msg);
    } catch (GridClientConnectionResetException e) {
        if (destId != null)
            connMgr.terminateConnection(conn, top.node(destId), e);
        else
            connMgr.terminateConnection(conn, null, e);
        cause = e;
    } catch (GridClientException e) {
        cause = e;
    }
    GridClientFutureAdapter<Object> fail = new GridClientFutureAdapter<>();
    fail.onDone(cause);
    return fail;
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientTopology(org.apache.ignite.internal.client.impl.connection.GridClientTopology) GridClientConnectionResetException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException) GridClientConnectionManager(org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager) GridClientConnection(org.apache.ignite.internal.client.impl.connection.GridClientConnection) GridClientFutureAdapter(org.apache.ignite.internal.client.impl.GridClientFutureAdapter) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl)

Aggregations

GridClientException (org.apache.ignite.internal.client.GridClientException)2 GridClientConnectionManager (org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 GridClientNode (org.apache.ignite.internal.client.GridClientNode)1 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)1 GridClientFutureAdapter (org.apache.ignite.internal.client.impl.GridClientFutureAdapter)1 GridClientNodeImpl (org.apache.ignite.internal.client.impl.GridClientNodeImpl)1 GridClientConnection (org.apache.ignite.internal.client.impl.connection.GridClientConnection)1 GridClientConnectionManagerOsImpl (org.apache.ignite.internal.client.impl.connection.GridClientConnectionManagerOsImpl)1 GridClientConnectionResetException (org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException)1 GridClientTopology (org.apache.ignite.internal.client.impl.connection.GridClientTopology)1