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);
}
}
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);
}
Aggregations