Search in sources :

Example 1 with CompletionListener

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);
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CompletionListener(org.teiid.client.util.ResultsFuture.CompletionListener) FakeService(org.teiid.transport.TestSocketRemoting.FakeService) Properties(java.util.Properties) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) SessionServiceException(org.teiid.dqp.service.SessionServiceException) CommunicationException(org.teiid.net.CommunicationException) ConnectionException(org.teiid.net.ConnectionException) Test(org.junit.Test)

Example 2 with CompletionListener

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);
    }
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletionListener(org.teiid.client.util.ResultsFuture.CompletionListener) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ResultsFuture (org.teiid.client.util.ResultsFuture)2 CompletionListener (org.teiid.client.util.ResultsFuture.CompletionListener)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1 SessionServiceException (org.teiid.dqp.service.SessionServiceException)1 CommunicationException (org.teiid.net.CommunicationException)1 ConnectionException (org.teiid.net.ConnectionException)1 SocketServerConnection (org.teiid.net.socket.SocketServerConnection)1 FakeService (org.teiid.transport.TestSocketRemoting.FakeService)1