use of org.teiid.client.util.ResultsFuture.CompletionListener in project teiid by teiid.
the class TestCommSockets method testAutoFailoverPing.
@Test
public void testAutoFailoverPing() throws Exception {
Properties p = new Properties();
p.setProperty(TeiidURL.CONNECTION.AUTO_FAILOVER, "true");
p.setProperty("org.teiid.sockets.synchronousttl", "20000");
SocketServerConnection conn = helpEstablishConnection(false, new SSLConfiguration(), p);
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
Future<?> future = exec.submit(new Runnable() {
@Override
public void run() {
final FakeService fs = conn.getService(FakeService.class);
ResultsFuture<Integer> f = fs.delayedAsynchResult();
f.addCompletionListener(new CompletionListener<Integer>() {
@Override
public void onCompletion(ResultsFuture<Integer> future) {
// potentially recurrent;
fs.asynchResult();
}
});
try {
f.get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
future.get(19, TimeUnit.SECONDS);
}
use of org.teiid.client.util.ResultsFuture.CompletionListener in project teiid by teiid.
the class MaterializationManager method runJob.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void runJob(final CompositeVDB vdb, final Table table, final long ttl, final boolean onetimeJob) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
String command = "execute SYSADMIN.loadMatView('" + StringUtil.replaceAll(table.getParent().getName(), "'", "''") + "','" + StringUtil.replaceAll(table.getName(), "'", "''") + "')";
try {
final AtomicInteger procReturn = new AtomicInteger();
executeAsynchQuery(vdb.getVDB(), command, new DQPCore.ResultsListener() {
@Override
public void onResults(List<String> columns, List<? extends List<?>> results) throws Exception {
procReturn.set((Integer) results.get(0).get(0));
}
}).addCompletionListener(new CompletionListener() {
@Override
public void onCompletion(ResultsFuture future) {
try {
future.get();
if (!onetimeJob) {
if (procReturn.get() >= 0) {
scheduleSnapshotJob(vdb, table, ttl, ttl, onetimeJob);
} else {
// when in error re-schedule in 1 min or less
scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
}
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
// re-schedule the same job in one minute
scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
}
}
});
} catch (SQLException e) {
LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
// re-schedule the same job in one minute
scheduleSnapshotJob(vdb, table, ttl, Math.min(ttl / 4, WAITTIME), onetimeJob);
}
}
Aggregations