use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class GridClientTopology method nodes.
/**
* Gets a collection of nodes from last saved topology snapshot by their ids.
*
* @param ids Collection of ids for which nodes should be retrieved..
* @return Collection of nodes that are in topology.
* @throws GridClientException If topology is failed and no nodes available.
*/
public Collection<GridClientNode> nodes(Iterable<UUID> ids) throws GridClientException {
assert ids != null;
Collection<GridClientNode> res = new LinkedList<>();
lock.readLock().lock();
try {
if (lastError != null)
throw new GridClientDisconnectedException("Latest topology update failed.", lastError);
for (UUID id : ids) {
GridClientNodeImpl node = nodes.get(id);
if (node != null)
res.add(node);
}
return res;
} finally {
lock.readLock().unlock();
}
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class GridClientTopology method fail.
/**
* Marks topology as failed. After this method called all accessors will throw exception
* until a next successful update.
*
* @param cause Exception caused the failure.
*/
public void fail(GridClientException cause) {
lock.writeLock().lock();
try {
lastError = cause;
for (GridClientNode n : nodes.values()) notifyEvents(Collections.singletonList(new TopologyEvent(false, n)));
nodes = Collections.emptyMap();
} finally {
lock.writeLock().unlock();
}
}
use of org.apache.ignite.internal.client.GridClientNode 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;
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class TcpRouterAbstractSelfTest method testConnectable.
/**
* @throws Exception If failed.
*/
@Override
public void testConnectable() throws Exception {
GridClient client = client();
List<GridClientNode> nodes = client.compute().refreshTopology(false, false);
assertFalse(F.first(nodes).connectable());
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class GridClientRoundRobinBalancer method balancedNode.
/** {@inheritDoc} */
@Override
public GridClientNode balancedNode(Collection<? extends GridClientNode> nodes) throws GridClientException {
assert !nodes.isEmpty();
if (isPreferDirectNodes()) {
Collection<GridClientNode> direct = selectDirectNodes(nodes);
int directSize = direct.size();
// replace original set of nodes with directly available.
if (directSize > 0 && directSize < nodes.size())
nodes = direct;
}
Map<UUID, GridClientNode> lookup = U.newHashMap(nodes.size());
for (GridClientNode node : nodes) lookup.put(node.nodeId(), node);
lock.lock();
try {
GridClientNode balanced = null;
for (Iterator<UUID> iter = nodeQueue.iterator(); iter.hasNext(); ) {
UUID nodeId = iter.next();
balanced = lookup.get(nodeId);
if (balanced != null) {
iter.remove();
break;
}
}
if (balanced != null) {
nodeQueue.addLast(balanced.nodeId());
return balanced;
}
throw new GridClientException("Passed nodes doesn't present in topology " + "[nodes=" + nodes + ", top=" + nodeQueue);
} finally {
lock.unlock();
}
}
Aggregations