use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.
the class GridDhtAtomicCache method sendDeferredUpdateResponse.
/**
* @param part Partition.
* @param primaryId Primary ID.
* @param futId Future ID.
*/
private void sendDeferredUpdateResponse(int part, UUID primaryId, long futId) {
Map<UUID, GridDhtAtomicDeferredUpdateResponse> resMap = defRes.get();
GridDhtAtomicDeferredUpdateResponse msg = resMap.get(primaryId);
if (msg == null) {
msg = new GridDhtAtomicDeferredUpdateResponse(ctx.cacheId(), new GridLongList(DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE));
if (DEFERRED_UPDATE_RESPONSE_TIMEOUT > 0) {
GridTimeoutObject timeoutSnd = new DeferredUpdateTimeout(part, primaryId);
msg.timeoutSender(timeoutSnd);
ctx.time().addTimeoutObject(timeoutSnd);
}
resMap.put(primaryId, msg);
}
GridLongList futIds = msg.futureIds();
assert futIds.size() < DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE : futIds.size();
futIds.add(futId);
if (futIds.size() >= DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE) {
resMap.remove(primaryId);
sendDeferredUpdateResponse(primaryId, msg);
}
}
use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.
the class GridDhtPartitionDemander method forceRebalance.
/**
* @return Rebalance future.
*/
IgniteInternalFuture<Boolean> forceRebalance() {
GridTimeoutObject obj = lastTimeoutObj.getAndSet(null);
if (obj != null)
ctx.time().removeTimeoutObject(obj);
final GridDhtPartitionsExchangeFuture exchFut = lastExchangeFut;
if (exchFut != null) {
if (log.isDebugEnabled())
log.debug("Forcing rebalance event for future: " + exchFut);
final GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
exchFut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
if (t.error() == null) {
IgniteInternalFuture<Boolean> fut0 = ctx.exchange().forceRebalance(exchFut.exchangeId());
fut0.listen(new IgniteInClosure<IgniteInternalFuture<Boolean>>() {
@Override
public void apply(IgniteInternalFuture<Boolean> fut1) {
try {
fut.onDone(fut1.get());
} catch (Exception e) {
fut.onDone(e);
}
}
});
} else
fut.onDone(t.error());
}
});
return fut;
} else if (log.isDebugEnabled())
log.debug("Ignoring force rebalance request (no topology event happened yet).");
return new GridFinishedFuture<>(true);
}
use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.
the class StartNodeCallableImpl method exec.
/**
* Executes command using {@code exec} channel with setting encoding.
*
* @param ses SSH session.
* @param cmd Command.
* @param encoding Process output encoding, {@code null} for default charset encoding.
* @return Output result.
* @throws JSchException In case of SSH error.
* @throws IOException If failed.
*/
private String exec(Session ses, final String cmd, String encoding) throws JSchException, IOException {
ChannelExec ch = null;
try {
ch = (ChannelExec) ses.openChannel("exec");
ch.setCommand(cmd);
ch.connect();
if (encoding == null)
encoding = Charset.defaultCharset().name();
GridTimeoutObject to = null;
SB out = null;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(ch.getInputStream(), encoding))) {
String line;
boolean first = true;
while ((line = reader.readLine()) != null) {
if (first)
out = new SB();
else
out.a('\n');
out.a(line);
if (first) {
to = initTimer(cmd);
first = false;
}
}
} catch (InterruptedIOException ignore) {
// No-op.
} finally {
if (to != null) {
boolean r = proc.removeTimeoutObject(to);
assert r || to.endTime() <= U.currentTimeMillis() : "Timeout object was not removed: " + to;
}
}
return out == null ? null : out.toString();
} finally {
if (ch != null && ch.isConnected())
ch.disconnect();
}
}
Aggregations