com.google.common.util.concurrent.ListenableFutureTask Java Examples

The following examples show how to use com.google.common.util.concurrent.ListenableFutureTask. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Scheduler.java    From The-5zig-Mod with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Posts a runnable to the Main Server Thread.
 * <p/>
 *
 * @param runnable The runnable that should be executed.
 * @return a Listenable Future.
 */
public ListenableFuture postToMainThread(Runnable runnable, boolean noThreadCheck, int delay) {
	Callable callable = Executors.callable(runnable);
	ListenableFuture listenableFuture = ListenableFutureTask.create(callable);
	if (noThreadCheck || delay > 0 || !The5zigMod.getVars().isMainThread()) {
		synchronized (jobs) {
			jobs.add(new Task(listenableFuture, delay));
			return listenableFuture;
		}
	} else {
		try {
			return Futures.immediateFuture(callable.call());
		} catch (Exception e) {
			return Futures.immediateFailedCheckedFuture(e);
		}
	}
}
 
Example #2
Source File: WaveServerModule.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a future whose result is the state of the wavelet after it has been
 * loaded from storage. Any failure is reported as a
 * {@link PersistenceException}.
 */
@VisibleForTesting
static ListenableFuture<DeltaStoreBasedWaveletState> loadWaveletState(Executor executor,
    final DeltaStore deltaStore, final DeltaStoreTransient transientDeltaStore,
    final WaveletName waveletName, final Executor persistExecutor,
    final int persistSnapshotOnDeltasCount) {
  ListenableFutureTask<DeltaStoreBasedWaveletState> task = ListenableFutureTask
      .create(new Callable<DeltaStoreBasedWaveletState>() {
        @Override
        public DeltaStoreBasedWaveletState call() throws PersistenceException {

          DeltasAccess deltasAccess = null;
          if (waveletName.waveletId.isTransientWavelet())
            deltasAccess = transientDeltaStore.open(waveletName);
          else
            deltasAccess = deltaStore.open(waveletName);

          return DeltaStoreBasedWaveletState.create(deltasAccess, persistExecutor,
              persistSnapshotOnDeltasCount);
        }
      });
  executor.execute(task);
  return task;
}
 
Example #3
Source File: LucenePerUserWaveViewHandlerImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> onParticipantAdded(final WaveletName waveletName,
    ParticipantId participant) {
  Preconditions.checkNotNull(waveletName);
  Preconditions.checkNotNull(participant);

  ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

    @Override
    public Void call() throws Exception {
      ReadableWaveletData waveletData;
      try {
        waveletData = waveletProvider.getReadableWaveletData(waveletName);
        updateIndex(waveletData);
      } catch (WaveServerException e) {
        LOG.log(Level.SEVERE, "Failed to update index for " + waveletName, e);
        throw e;
      }
      return null;
    }
  });
  executor.execute(task);
  return task;
}
 
Example #4
Source File: LucenePerUserWaveViewHandlerImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> onWaveInit(final WaveletName waveletName) {
  Preconditions.checkNotNull(waveletName);

  ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

    @Override
    public Void call() throws Exception {
      ReadableWaveletData waveletData;
      try {
        waveletData = waveletProvider.getReadableWaveletData(waveletName);
        updateIndex(waveletData);
      } catch (WaveServerException e) {
        LOG.log(Level.SEVERE, "Failed to initialize index for " + waveletName, e);
        throw e;
      }
      return null;
    }
  });
  executor.execute(task);
  return task;
}
 
Example #5
Source File: SolrWaveIndexerImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> onWaveInit(final WaveletName waveletName) {

  ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

    @Override
    public Void call() throws Exception {
      ReadableWaveletData waveletData;
      try {
        waveletData = waveletDataProvider.getReadableWaveletData(waveletName);
        updateIndex(waveletData);
      } catch (WaveServerException e) {
        LOG.log(Level.SEVERE, "Failed to initialize index for " + waveletName, e);
        throw e;
      }
      return null;
    }
  });
  executor.execute(task);
  return task;
}
 
Example #6
Source File: SolrWaveIndexerImpl.java    From swellrt with Apache License 2.0 6 votes vote down vote up
@Override
public void waveletCommitted(final WaveletName waveletName, final HashedVersion version) {

  Preconditions.checkNotNull(waveletName);

  ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

    @Override
    public Void call() throws Exception {
      ReadableWaveletData waveletData;
      try {
        waveletData = waveletDataProvider.getReadableWaveletData(waveletName);
        LOG.fine("commit " + version + " " + waveletData.getVersion());
        if (waveletData.getVersion() == version.getVersion()) {
          updateIndex(waveletData);
        }
      } catch (WaveServerException e) {
        LOG.log(Level.SEVERE, "Failed to update index for " + waveletName, e);
        throw e;
      }
      return null;
    }
  });
  executor.execute(task);
}
 
Example #7
Source File: LongBTreeTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static void testOneSlice(final String id, final NavigableSet<Integer> test, final NavigableSet<Integer> canon, List<ListenableFuture<?>> results)
{
    ListenableFutureTask<?> f = ListenableFutureTask.create(new Runnable()
    {

        @Override
        public void run()
        {
            test(id + " Count", test.size(), canon.size());
            testEqual(id, test.iterator(), canon.iterator());
            testEqual(id + "->DSCI", test.descendingIterator(), canon.descendingIterator());
            testEqual(id + "->DSCS", test.descendingSet().iterator(), canon.descendingSet().iterator());
            testEqual(id + "->DSCS->DSCI", test.descendingSet().descendingIterator(), canon.descendingSet().descendingIterator());
        }
    }, null);
    results.add(f);
    COMPARE.execute(f);
}
 
Example #8
Source File: PhoenixStatsCacheLoader.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<GuidePostsInfo> reload(
        final GuidePostsKey key,
        GuidePostsInfo prevGuidepostInfo)
{
    if (statsLoader.needsLoad()) {
        // schedule asynchronous task
        ListenableFutureTask<GuidePostsInfo> task =
                ListenableFutureTask.create(new Callable<GuidePostsInfo>() {
                    public GuidePostsInfo call() {
                        try {
                            return statsLoader.loadStats(key, prevGuidepostInfo);
                        } catch (Exception e) {
                            LOGGER.warn("Unable to load stats from table: " + key.toString(), e);
                            return prevGuidepostInfo;
                        }
                    }
                });
        executor.execute(task);
        return task;
    }
    else {
        return Futures.immediateFuture(prevGuidepostInfo);
    }
}
 
Example #9
Source File: AbstractJobInstance.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
public AbstractJobInstance(Config config) {
    Assert.notNull(config.parameters, "parameters is null");
    Assert.notNull(config.job, "job is null");
    Assert.notNull(config.jobsManager, "jobsManager is null");
    Assert.notNull(config.info, "info is null");
    this.jobContext = new JobContext(this, config.parameters);
    this.infoRef = new AtomicReference<>(config.info);
    this.manager = config.jobsManager;
    // create wait future with stub
    this.atEndFuture = SettableFuture.create();
    this.job = config.job;
    this.authentication = config.authentication;
    this.watcher = config.watcher;
    this.cancelFuture = ListenableFutureTask.create(this::innerCancel);
    this.startFuture = ListenableFutureTask.create(this::innerStart);
}
 
Example #10
Source File: WaveServerModule.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a future whose result is the state of the wavelet after it has been
 * loaded from storage. Any failure is reported as a
 * {@link PersistenceException}.
 */
@VisibleForTesting
static ListenableFuture<DeltaStoreBasedWaveletState> loadWaveletState(Executor executor,
    final DeltaStore deltaStore, final WaveletName waveletName, final Executor persistExecutor) {
  ListenableFutureTask<DeltaStoreBasedWaveletState> task =
      ListenableFutureTask.create(
         new Callable<DeltaStoreBasedWaveletState>() {
           @Override
           public DeltaStoreBasedWaveletState call() throws PersistenceException {
             return DeltaStoreBasedWaveletState.create(deltaStore.open(waveletName),
                                                              persistExecutor);
           }
         });
  executor.execute(task);
  return task;
}
 
Example #11
Source File: LucenePerUserWaveViewHandlerImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> onParticipantAdded(final WaveletName waveletName,
    ParticipantId participant) {
  Preconditions.checkNotNull(waveletName);
  Preconditions.checkNotNull(participant);

  ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

    @Override
    public Void call() throws Exception {
      ReadableWaveletData waveletData;
      try {
        waveletData = waveletProvider.getReadableWaveletData(waveletName);
        updateIndex(waveletData);
      } catch (WaveServerException e) {
        LOG.log(Level.SEVERE, "Failed to update index for " + waveletName, e);
        throw e;
      }
      return null;
    }
  });
  executor.execute(task);
  return task;
}
 
Example #12
Source File: LucenePerUserWaveViewHandlerImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> onWaveInit(final WaveletName waveletName) {
  Preconditions.checkNotNull(waveletName);

  ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

    @Override
    public Void call() throws Exception {
      ReadableWaveletData waveletData;
      try {
        waveletData = waveletProvider.getReadableWaveletData(waveletName);
        updateIndex(waveletData);
      } catch (WaveServerException e) {
        LOG.log(Level.SEVERE, "Failed to initialize index for " + waveletName, e);
        throw e;
      }
      return null;
    }
  });
  executor.execute(task);
  return task;
}
 
Example #13
Source File: SolrWaveIndexerImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Override
public ListenableFuture<Void> onWaveInit(final WaveletName waveletName) {

  ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

    @Override
    public Void call() throws Exception {
      ReadableWaveletData waveletData;
      try {
        waveletData = waveletDataProvider.getReadableWaveletData(waveletName);
        updateIndex(waveletData);
      } catch (WaveServerException e) {
        LOG.log(Level.SEVERE, "Failed to initialize index for " + waveletName, e);
        throw e;
      }
      return null;
    }
  });
  executor.execute(task);
  return task;
}
 
Example #14
Source File: SolrWaveIndexerImpl.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Override
public void waveletCommitted(final WaveletName waveletName, final HashedVersion version) {

  Preconditions.checkNotNull(waveletName);

  ListenableFutureTask<Void> task = ListenableFutureTask.create(new Callable<Void>() {

    @Override
    public Void call() throws Exception {
      ReadableWaveletData waveletData;
      try {
        waveletData = waveletDataProvider.getReadableWaveletData(waveletName);
        LOG.fine("commit " + version + " " + waveletData.getVersion());
        if (waveletData.getVersion() == version.getVersion()) {
          updateIndex(waveletData);
        }
      } catch (WaveServerException e) {
        LOG.log(Level.SEVERE, "Failed to update index for " + waveletName, e);
        throw e;
      }
      return null;
    }
  });
  executor.execute(task);
}
 
Example #15
Source File: Scheduler.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
/**
 * Posts a runnable to the Main Server Thread.
 * <p/>
 *
 * @param runnable The runnable that should be executed.
 * @return a Listenable Future.
 */
public ListenableFuture postToMainThread(Runnable runnable, boolean noThreadCheck, int delay) {
	Callable callable = Executors.callable(runnable);
	ListenableFuture listenableFuture = ListenableFutureTask.create(callable);
	if (noThreadCheck || delay > 0 || !The5zigMod.getVars().isMainThread()) {
		synchronized (jobs) {
			jobs.add(new Task(listenableFuture, delay));
			return listenableFuture;
		}
	} else {
		try {
			return Futures.immediateFuture(callable.call());
		} catch (Exception e) {
			return Futures.immediateFailedCheckedFuture(e);
		}
	}
}
 
Example #16
Source File: DeltaStoreBasedWaveletState.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<Void> persist(final HashedVersion version) {
  Preconditions.checkArgument(version.getVersion() > 0,
      "Cannot persist non-positive version %s", version);
  Preconditions.checkArgument(isDeltaBoundary(version),
      "Version to persist %s matches no delta", version);
  synchronized (persistLock) {
    if (latestVersionToPersist != null) {
      // There's a persist task in flight.
      if (version.getVersion() <= latestVersionToPersist.getVersion()) {
        LOG.info("Attempt to persist version " + version
            + " smaller than last version requested " + latestVersionToPersist);
      } else {
        latestVersionToPersist = version;
      }
      if (nextPersistTask == null) {
        nextPersistTask = ListenableFutureTask.<Void>create(persisterTask);
      }
      return nextPersistTask;
    } else {
      latestVersionToPersist = version;
      ListenableFutureTask<Void> resultTask = ListenableFutureTask.<Void>create(persisterTask);
      persistExecutor.execute(resultTask);
      return resultTask;
    }
  }
}
 
Example #17
Source File: DatasetMaxDataTimeCacheLoader.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<Long> reload(final String dataset, Long preMaxDataTime) {
  ListenableFutureTask<Long> reloadTask = ListenableFutureTask.create(new Callable<Long>() {
    @Override public Long call() throws Exception {
      return DatasetMaxDataTimeCacheLoader.this.load(dataset);
    }
  });
  reloadExecutor.execute(reloadTask);
  LOGGER.info("Passively refreshing max data time of collection: {}", dataset);
  return reloadTask;
}
 
Example #18
Source File: FCFSQueryScheduler.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ListenableFuture<byte[]> submit(@Nonnull ServerQueryRequest queryRequest) {
  if (!isRunning) {
    return immediateErrorResponse(queryRequest, QueryException.SERVER_SCHEDULER_DOWN_ERROR);
  }
  queryRequest.getTimerContext().startNewPhaseTimer(ServerQueryPhase.SCHEDULER_WAIT);
  QueryExecutorService queryExecutorService = resourceManager.getExecutorService(queryRequest, null);
  ListenableFutureTask<byte[]> queryTask = createQueryFutureTask(queryRequest, queryExecutorService);
  resourceManager.getQueryRunners().submit(queryTask);
  return queryTask;
}
 
Example #19
Source File: WaveMap.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a future whose result is the ids of stored wavelets in the given wave.
 * Any failure is reported as a {@link PersistenceException}.
 */
private static ListenableFuture<ImmutableSet<WaveletId>> lookupWavelets(
    final WaveId waveId, final WaveletStore<?> waveletStore, Executor lookupExecutor) {
  ListenableFutureTask<ImmutableSet<WaveletId>> task =
      ListenableFutureTask.create(
         new Callable<ImmutableSet<WaveletId>>() {
           @Override
           public ImmutableSet<WaveletId> call() throws PersistenceException {
             return waveletStore.lookup(waveId);
           }
         });
  lookupExecutor.execute(task);
  return task;
}
 
Example #20
Source File: WaveMap.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a future whose result is the ids of stored wavelets in the given wave.
 * Any failure is reported as a {@link PersistenceException}.
 */
private static ListenableFuture<ImmutableSet<WaveletId>> lookupWavelets(
    final WaveId waveId, final WaveletStore<?> waveletStore, Executor lookupExecutor) {
  ListenableFutureTask<ImmutableSet<WaveletId>> task =
      ListenableFutureTask.create(
         new Callable<ImmutableSet<WaveletId>>() {
           @Override
           public ImmutableSet<WaveletId> call() throws PersistenceException {
             return waveletStore.lookup(waveId);
           }
         });
  lookupExecutor.execute(task);
  return task;
}
 
Example #21
Source File: EsIndexCacheImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Inject
public EsIndexCacheImpl( final EsProvider provider, final IndexFig indexFig ) {

    this.refreshExecutors =
        MoreExecutors.listeningDecorator( Executors.newScheduledThreadPool( indexFig.getIndexCacheMaxWorkers() ) );

    this.provider = provider;

    aliasIndexCache = CacheBuilder.newBuilder().maximumSize( 1000 ).refreshAfterWrite( 5, TimeUnit.MINUTES )
                                  .build( new CacheLoader<String, String[]>() {
                                      @Override
                                      public ListenableFuture<String[]> reload( final String key,
                                                                                String[] oldValue )
                                          throws Exception {
                                          ListenableFutureTask<String[]> task =
                                              ListenableFutureTask.create( new Callable<String[]>() {
                                                  public String[] call() {
                                                      return load( key );
                                                  }
                                              } );
                                          refreshExecutors.execute( task );
                                          return task;
                                      }


                                      @Override
                                      public String[] load( final String aliasName ) {
                                         return getIndexesFromEs(aliasName);
                                      }
                                  } );
}
 
Example #22
Source File: NodeShardCacheImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<CacheEntry> reload( final CacheKey key, final CacheEntry oldValue ) throws Exception {
    ListenableFutureTask<CacheEntry> task = ListenableFutureTask.create( new Callable<CacheEntry>() {
        public CacheEntry call() {
            return load( key );
        }
    } );
    //load via the refresh executor
    refreshExecutors.execute( task );
    return task;
}
 
Example #23
Source File: DeltaStoreBasedWaveletState.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<Void> persist(final HashedVersion version) {
  Preconditions.checkArgument(version.getVersion() > 0,
      "Cannot persist non-positive version %s", version);
  Preconditions.checkArgument(isDeltaBoundary(version),
      "Version to persist %s matches no delta", version);
  synchronized (persistLock) {
    if (latestVersionToPersist != null) {
      // There's a persist task in flight.
      if (version.getVersion() <= latestVersionToPersist.getVersion()) {
        LOG.info("Attempt to persist version " + version
            + " smaller than last version requested " + latestVersionToPersist);
      } else {
        latestVersionToPersist = version;
      }
      if (nextPersistTask == null) {
        nextPersistTask = ListenableFutureTask.<Void>create(persisterTask);
      }
      return nextPersistTask;
    } else {
      latestVersionToPersist = version;
      ListenableFutureTask<Void> resultTask = ListenableFutureTask.<Void>create(persisterTask);
      persistExecutor.execute(resultTask);
      return resultTask;
    }
  }
}
 
Example #24
Source File: Espresso.java    From android-test with Apache License 2.0 5 votes vote down vote up
/**
 * Loops the main thread until the app goes idle.
 *
 * <p>Same as {@link Espresso#onIdle()}, but takes an additional {@link Callable} as parameter,
 * which is executed after the app goes idle.
 *
 * @param action callable executed when the app goes idle.
 * @return the computed result of the action callable
 * @throws AppNotIdleException when app does not go Idle within the master policies timeout
 */
public static <T> T onIdle(Callable<T> action) {
  Executor mainThreadExecutor = BASE.mainThreadExecutor();
  ListenableFutureTask<Void> idleFuture =
      ListenableFutureTask.create(
          new Runnable() {
            @Override
            public void run() {
              BASE.uiController().loopMainThreadUntilIdle();
            }
          },
          null);
  FutureTask<T> actionTask = new FutureTask<>(action);
  idleFuture.addListener(actionTask, mainThreadExecutor);
  mainThreadExecutor.execute(idleFuture);
  BASE.controlledLooper().drainMainThreadUntilIdle();

  try {
    idleFuture.get();
    return actionTask.get();
  } catch (InterruptedException ie) {
    throw new RuntimeException(ie);
  } catch (ExecutionException ee) {
    if (ee.getCause() instanceof AppNotIdleException) {
      throw (AppNotIdleException) ee.getCause();
    } else {
      throw new RuntimeException(ee);
    }
  }
}
 
Example #25
Source File: SubThreadPoolExecutor.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
    ListenableFutureTask<T> ret = impl instanceof SubThreadPoolExecutor
            ? (ListenableFutureTask) ((SubThreadPoolExecutor) impl).newTaskFor(callable)
            : ListenableFutureTask.create(callable);
    ret.addListener(new Runnable() {
        @Override
        public void run() {
            releaseThread();
        }
    }, MoreExecutors.sameThreadExecutor());
    return ret;
}
 
Example #26
Source File: SubThreadPoolExecutor.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
    ListenableFutureTask<T> ret = impl instanceof SubThreadPoolExecutor
            ? (ListenableFutureTask) ((SubThreadPoolExecutor) impl).newTaskFor(runnable, value)
            : ListenableFutureTask.create(runnable, value);
    ret.addListener(new Runnable() {
        @Override
        public void run() {
            releaseThread();
        }
    }, MoreExecutors.sameThreadExecutor());
    return ret;
}
 
Example #27
Source File: RequestErrorTracker.java    From presto with Apache License 2.0 5 votes vote down vote up
public ListenableFuture<?> acquireRequestPermit()
{
    long delayNanos = backoff.getBackoffDelayNanos();

    if (delayNanos == 0) {
        return Futures.immediateFuture(null);
    }

    ListenableFutureTask<Object> futureTask = ListenableFutureTask.create(() -> null);
    scheduledExecutor.schedule(futureTask, delayNanos, NANOSECONDS);
    return futureTask;
}
 
Example #28
Source File: Loader.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<V> reload(final K key, final V oldValue) {
    
    if (log.isTraceEnabled())
        log.trace("Reload the cache");
    
    ListenableFutureTask<V> task = null;
    if (!lazy) {
        if (log.isTraceEnabled())
            log.trace("Reloading synchronously");
        try {
            build(null);
            
            return Futures.immediateCheckedFuture(load(key));
            
        } catch (Exception e) {
            log.error(e);
        }
    } else {
        
        task = ListenableFutureTask.create(() -> {
            build(null);
            return load(key);
        });
        
        executor.execute(task);
    }
    
    return task;
    
}
 
Example #29
Source File: ChunkRenderDispatcherLitematica.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ListenableFuture<Object> uploadChunkBlocks(final BlockRenderLayer layer, final BufferBuilder buffer,
        final RenderChunkSchematicVbo renderChunk, final CompiledChunk compiledChunk, final double distanceSq)
{
    if (Minecraft.getMinecraft().isCallingFromMinecraftThread())
    {
        //if (GuiBase.isCtrlDown()) System.out.printf("uploadChunkBlocks()\n");
        if (OpenGlHelper.useVbo())
        {
            this.uploadVertexBuffer(buffer, renderChunk.getVertexBufferByLayer(layer.ordinal()));
        }
        else
        {
            this.uploadDisplayList(buffer, ((RenderChunkSchematicList) renderChunk).getDisplayList(layer, compiledChunk), renderChunk);
        }

        buffer.setTranslation(0.0D, 0.0D, 0.0D);

        return Futures.<Object>immediateFuture(null);
    }
    else
    {
        ListenableFutureTask<Object> futureTask = ListenableFutureTask.<Object>create(new Runnable()
        {
            @Override
            public void run()
            {
                ChunkRenderDispatcherLitematica.this.uploadChunkBlocks(layer, buffer, renderChunk, compiledChunk, distanceSq);
            }
        }, null);

        synchronized (this.queueChunkUploads)
        {
            this.queueChunkUploads.add(new ChunkRenderDispatcherLitematica.PendingUpload(futureTask, distanceSq));
            return futureTask;
        }
    }
}
 
Example #30
Source File: ChunkRenderDispatcherLitematica.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ListenableFuture<Object> uploadChunkOverlay(final OverlayRenderType type, final BufferBuilder buffer,
        final RenderChunkSchematicVbo renderChunk, final CompiledChunkSchematic compiledChunk, final double distanceSq)
{
    if (Minecraft.getMinecraft().isCallingFromMinecraftThread())
    {
        //if (GuiBase.isCtrlDown()) System.out.printf("uploadChunkOverlay()\n");
        if (OpenGlHelper.useVbo())
        {
            this.uploadVertexBuffer(buffer, renderChunk.getOverlayVertexBuffer(type));
        }
        else
        {
            this.uploadDisplayList(buffer, ((RenderChunkSchematicList) renderChunk).getOverlayDisplayList(type, compiledChunk), renderChunk);
        }

        buffer.setTranslation(0.0D, 0.0D, 0.0D);

        return Futures.<Object>immediateFuture(null);
    }
    else
    {
        ListenableFutureTask<Object> futureTask = ListenableFutureTask.<Object>create(new Runnable()
        {
            @Override
            public void run()
            {
                ChunkRenderDispatcherLitematica.this.uploadChunkOverlay(type, buffer, renderChunk, compiledChunk, distanceSq);
            }
        }, null);

        synchronized (this.queueChunkUploads)
        {
            this.queueChunkUploads.add(new ChunkRenderDispatcherLitematica.PendingUpload(futureTask, distanceSq));
            return futureTask;
        }
    }
}