use of org.apache.ignite.internal.client.marshaller.GridClientMarshaller 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, cfg.getUserAttributes());
} 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, cfg.getUserAttributes());
} 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.GridClientMarshaller in project ignite by apache.
the class GridTcpRestProtocol method onProcessorStart.
/**
* {@inheritDoc}
*/
@Override
public void onProcessorStart() {
super.onProcessorStart();
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));
try {
IgnitePredicate<String> clsFilter = MarshallerUtils.classNameFilter(getClass().getClassLoader());
marshMap.put(GridClientJdkMarshaller.ID, new GridClientJdkMarshaller(clsFilter));
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
lsnr.marshallers(marshMap);
}
use of org.apache.ignite.internal.client.marshaller.GridClientMarshaller 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);
}
use of org.apache.ignite.internal.client.marshaller.GridClientMarshaller in project ignite by apache.
the class ClientMarshallerBenchmarkTest method testCacheRequestTime.
/**
* @throws Exception If failed.
*/
@Test
public void testCacheRequestTime() throws Exception {
GridClientCacheRequest req = new GridClientCacheRequest(CAS);
req.clientId(UUID.randomUUID());
req.cacheName("CacheName");
req.requestId(1024);
req.key("key");
req.value(1L);
req.value2(2L);
Map<Object, Object> additional = new HashMap<>();
for (int i = 0; i < 1000; i++) additional.put("key" + i, (long) i);
req.values(additional);
// Warm up.
for (GridClientMarshaller marshaller : marshallers) {
GridClientCacheRequest res = runMarshallUnmarshalLoop(req, 1, marshaller);
assertEquals(req.operation(), res.operation());
// requestId is not marshalled.
assertEquals(0, res.requestId());
// clientId is not marshalled.
assertEquals(null, res.clientId());
// destinationId is not marshalled.
assertEquals(null, res.destinationId());
assertEquals(req.cacheName(), res.cacheName());
assertEquals(req.key(), res.key());
assertEquals(req.value(), res.value());
assertEquals(req.value2(), res.value2());
for (Map.Entry<Object, Object> e : req.values().entrySet()) assertEquals(e.getValue(), res.values().get(e.getKey()));
}
// Now real test.
for (GridClientMarshaller marshaller : marshallers) runMarshallUnmarshalLoop(req, 1000, marshaller);
}
use of org.apache.ignite.internal.client.marshaller.GridClientMarshaller 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());
}
} 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);
}
Aggregations