Search in sources :

Example 1 with GridClientZipOptimizedMarshaller

use of org.apache.ignite.internal.client.marshaller.optimized.GridClientZipOptimizedMarshaller in project ignite by apache.

the class GridClientConnectionManagerAdapter method connect.

/**
     * Create new connection to specified server.
     *
     * @param nodeId {@code UUID} of node for mapping with connection.
     *      {@code null} if no need of mapping.
     * @param addr Remote socket to connect.
     * @return Established connection.
     * @throws IOException If connection failed.
     * @throws GridClientException If protocol error happened.
     * @throws InterruptedException If thread was interrupted before connection was established.
     */
protected GridClientConnection connect(@Nullable UUID nodeId, InetSocketAddress addr) throws IOException, GridClientException, InterruptedException {
    endpointStripedLock.lock(addr);
    try {
        GridClientConnection old = conns.get(addr);
        if (old != null) {
            if (old.isClosed()) {
                conns.remove(addr, old);
                if (nodeId != null)
                    nodeConns.remove(nodeId, old);
            } else {
                if (nodeId != null)
                    nodeConns.put(nodeId, old);
                return old;
            }
        }
        SecurityCredentials cred = null;
        try {
            if (cfg.getSecurityCredentialsProvider() != null)
                cred = cfg.getSecurityCredentialsProvider().credentials();
        } catch (IgniteCheckedException e) {
            throw new GridClientException("Failed to obtain client credentials.", e);
        }
        GridClientConnection conn;
        if (cfg.getProtocol() == GridClientProtocol.TCP) {
            GridClientMarshaller marsh = cfg.getMarshaller();
            try {
                conn = new GridClientNioTcpConnection(srv, clientId, addr, sslCtx, pingExecutor, cfg.getConnectTimeout(), cfg.getPingInterval(), cfg.getPingTimeout(), cfg.isTcpNoDelay(), marsh, marshId, top, cred, keepBinariesThreadLocal());
            } catch (GridClientException e) {
                if (marsh instanceof GridClientZipOptimizedMarshaller) {
                    log.warning("Failed to connect with GridClientZipOptimizedMarshaller," + " trying to fallback to default marshaller: " + e);
                    conn = new GridClientNioTcpConnection(srv, clientId, addr, sslCtx, pingExecutor, cfg.getConnectTimeout(), cfg.getPingInterval(), cfg.getPingTimeout(), cfg.isTcpNoDelay(), ((GridClientZipOptimizedMarshaller) marsh).defaultMarshaller(), marshId, top, cred, keepBinariesThreadLocal());
                } else
                    throw e;
            }
        } else
            throw new GridServerUnreachableException("Failed to create client (protocol is not supported): " + cfg.getProtocol());
        old = conns.putIfAbsent(addr, conn);
        assert old == null;
        if (nodeId != null)
            nodeConns.put(nodeId, conn);
        return conn;
    } finally {
        endpointStripedLock.unlock(addr);
    }
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) SecurityCredentials(org.apache.ignite.plugin.security.SecurityCredentials) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridClientMarshaller(org.apache.ignite.internal.client.marshaller.GridClientMarshaller) GridClientZipOptimizedMarshaller(org.apache.ignite.internal.client.marshaller.optimized.GridClientZipOptimizedMarshaller)

Example 2 with GridClientZipOptimizedMarshaller

use of org.apache.ignite.internal.client.marshaller.optimized.GridClientZipOptimizedMarshaller in project ignite by apache.

the class GridTcpRestProtocol method onKernalStart.

/** {@inheritDoc} */
@Override
public void onKernalStart() {
    super.onKernalStart();
    Map<Byte, GridClientMarshaller> marshMap = new HashMap<>();
    ArrayList<PluginProvider> providers = new ArrayList<>(ctx.plugins().allProviders());
    GridClientOptimizedMarshaller optMarsh = new GridClientOptimizedMarshaller(providers);
    marshMap.put(GridClientOptimizedMarshaller.ID, optMarsh);
    marshMap.put(GridClientZipOptimizedMarshaller.ID, new GridClientZipOptimizedMarshaller(optMarsh, providers));
    marshMap.put(GridClientJdkMarshaller.ID, new GridClientJdkMarshaller());
    lsnr.marshallers(marshMap);
}
Also used : GridClientJdkMarshaller(org.apache.ignite.internal.client.marshaller.jdk.GridClientJdkMarshaller) GridClientMarshaller(org.apache.ignite.internal.client.marshaller.GridClientMarshaller) GridClientOptimizedMarshaller(org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PluginProvider(org.apache.ignite.plugin.PluginProvider) GridClientZipOptimizedMarshaller(org.apache.ignite.internal.client.marshaller.optimized.GridClientZipOptimizedMarshaller)

Aggregations

GridClientMarshaller (org.apache.ignite.internal.client.marshaller.GridClientMarshaller)2 GridClientZipOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientZipOptimizedMarshaller)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridClientException (org.apache.ignite.internal.client.GridClientException)1 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)1 GridClientJdkMarshaller (org.apache.ignite.internal.client.marshaller.jdk.GridClientJdkMarshaller)1 GridClientOptimizedMarshaller (org.apache.ignite.internal.client.marshaller.optimized.GridClientOptimizedMarshaller)1 PluginProvider (org.apache.ignite.plugin.PluginProvider)1 SecurityCredentials (org.apache.ignite.plugin.security.SecurityCredentials)1