use of org.apache.ignite.internal.client.GridClientException 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;
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class GridClientNioTcpConnection method execute.
/** {@inheritDoc} */
@Override
public <R> GridClientFutureAdapter<R> execute(String taskName, Object arg, UUID destNodeId, final boolean keepBinaries) throws GridClientConnectionResetException, GridClientClosedException {
GridClientTaskRequest msg = new GridClientTaskRequest();
msg.taskName(taskName);
msg.argument(arg);
msg.keepBinaries(keepBinaries);
return this.<GridClientTaskResultBean>makeRequest(msg, destNodeId).chain(new GridClientFutureCallback<GridClientTaskResultBean, R>() {
@Override
public R onComplete(GridClientFuture<GridClientTaskResultBean> fut) throws GridClientException {
return fut.get().getResult();
}
});
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class GridClientAbstractProjection method withReconnectHandling.
/**
* This method executes request to a communication layer and handles connection error, if it occurs.
* In case of communication exception client instance is notified and new instance of client is created.
* If none of the grid servers can be reached, an exception is thrown.
*
* @param c Closure to be executed.
* @param <R> Result future type.
* @return Future returned by closure.
*/
protected <R> GridClientFuture<R> withReconnectHandling(ClientProjectionClosure<R> c) {
try {
GridClientNode node = null;
boolean changeNode = false;
Throwable cause = null;
for (int i = 0; i < RETRY_CNT; i++) {
if (node == null || changeNode)
try {
node = balancedNode(node);
} catch (GridClientException e) {
if (node == null)
throw e;
else
throw new GridServerUnreachableException("All nodes in projection failed when retrying to perform request. Attempts made: " + i, cause);
}
GridClientConnection conn = null;
try {
conn = client.connectionManager().connection(node);
return c.apply(conn, node.nodeId());
} catch (GridConnectionIdleClosedException e) {
client.connectionManager().terminateConnection(conn, node, e);
// It's ok, just reconnect to the same node.
changeNode = false;
cause = e;
} catch (GridClientConnectionResetException e) {
client.connectionManager().terminateConnection(conn, node, e);
changeNode = true;
cause = e;
} catch (GridServerUnreachableException e) {
changeNode = true;
cause = e;
}
U.sleep(RETRY_DELAY);
}
assert cause != null;
throw new GridServerUnreachableException("Failed to communicate with grid nodes " + "(maximum count of retries reached).", cause);
} catch (GridClientException e) {
return new GridClientFutureAdapter<>(e);
} catch (IgniteInterruptedCheckedException | InterruptedException e) {
Thread.currentThread().interrupt();
return new GridClientFutureAdapter<>(new GridClientException("Interrupted when (re)trying to perform request.", e));
}
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class CommandHandler method main.
/**
* @param args Args.
*/
public static void main(String[] args) throws GridClientException {
String host = "127.0.0.1";
String port = "11212";
Boolean activate = null;
if (args.length == 1 && "help".equals(args[0])) {
System.out.println("Example: --host {ip} --port {port} --{activate/deactivate} " + "or without command --host {ip} --port {port} then will print status.");
return;
}
if (args.length > 5)
throw new IllegalArgumentException("incorrect number of arguments");
for (int i = 0; i < args.length; i++) {
String str = args[i];
if ("--host".equals(str))
host = args[i + 1];
else if ("--port".equals(str))
port = args[i + 1];
else if ("--activate".equals(str))
activate = true;
else if ("--deactivate".equals(str))
activate = false;
}
if (host == null)
throw new IllegalArgumentException("host can not be empty");
if (port == null)
throw new IllegalArgumentException("port can not be empty");
GridClientConfiguration cfg = new GridClientConfiguration();
cfg.setServers(Collections.singletonList(host + ":" + port));
try (GridClient client = GridClientFactory.start(cfg)) {
GridClientClusterState state = client.state();
if (activate != null)
try {
state.active(activate);
System.out.println(host + ":" + port + " - was " + (activate ? "activate" : "deactivate"));
} catch (Exception e) {
System.out.println("Something fail during " + (activate ? "activation" : "deactivation") + ", exception message: " + e.getMessage());
}
else
System.out.println(host + ":" + port + " - " + (state.active() ? "active" : "inactive"));
}
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class JdbcResultSet method next.
/** {@inheritDoc} */
@Override
public boolean next() throws SQLException {
ensureNotClosed();
if (fields == null && !finished) {
assert nodeId != null;
assert futId != null;
try {
GridClientCompute compute = stmt.connection().client().compute();
GridClientCompute prj = compute.projection(compute.node(nodeId));
byte[] packet = prj.execute(TASK_NAME, JdbcUtils.marshalArgument(JdbcUtils.taskArgument(nodeId, futId, fetchSize, stmt.getMaxRows())));
byte status = packet[0];
byte[] data = new byte[packet.length - 1];
U.arrayCopy(packet, 1, data, 0, data.length);
if (status == 1)
throw JdbcUtils.unmarshalError(data);
else {
List<?> msg = JdbcUtils.unmarshal(data);
assert msg.size() == 2;
fields = ((Collection<List<Object>>) msg.get(0)).iterator();
finished = (Boolean) msg.get(1);
}
} catch (GridClientException e) {
throw new SQLException("Failed to query Ignite.", e);
}
}
if (fields != null && fields.hasNext()) {
curr = fields.next();
if (!fields.hasNext())
fields = null;
pos++;
return true;
} else {
curr = null;
return false;
}
}
Aggregations