Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

WorkQueueProvider.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2014 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.guice;
  17. import com.gitblit.IStoredSettings;
  18. import com.gitblit.Keys;
  19. import com.gitblit.manager.IRuntimeManager;
  20. import com.gitblit.utils.IdGenerator;
  21. import com.gitblit.utils.WorkQueue;
  22. import com.google.inject.Inject;
  23. import com.google.inject.Provider;
  24. import com.google.inject.Singleton;
  25. /**
  26. * Provides a lazily-instantiated WorkQueue configured from IStoredSettings.
  27. *
  28. * @author James Moger
  29. *
  30. */
  31. @Singleton
  32. public class WorkQueueProvider implements Provider<WorkQueue> {
  33. private final IRuntimeManager runtimeManager;
  34. private volatile WorkQueue workQueue;
  35. @Inject
  36. public WorkQueueProvider(IRuntimeManager runtimeManager) {
  37. this.runtimeManager = runtimeManager;
  38. }
  39. @Override
  40. public synchronized WorkQueue get() {
  41. if (workQueue != null) {
  42. return workQueue;
  43. }
  44. IStoredSettings settings = runtimeManager.getSettings();
  45. int defaultThreadPoolSize = settings.getInteger(Keys.execution.defaultThreadPoolSize, 1);
  46. IdGenerator idGenerator = new IdGenerator();
  47. workQueue = new WorkQueue(idGenerator, defaultThreadPoolSize);
  48. return workQueue;
  49. }
  50. }