/hazelcast/src/main/java/com/hazelcast/impl/NamedExecutorService.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 52 lines · 27 code · 10 blank · 15 comment · 0 complexity · c05467792ce5bcf4efe7f3b10cbc076d MD5 · raw file

  1. /*
  2. * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  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.hazelcast.impl;
  17. import com.hazelcast.impl.executor.ParallelExecutor;
  18. public class NamedExecutorService {
  19. private final String name;
  20. private final ParallelExecutor parallelExecutor;
  21. private final ExecutionLoadBalancer executionLoadBalancer;
  22. public NamedExecutorService(String name, ParallelExecutor parallelExecutor) {
  23. this.name = name;
  24. this.parallelExecutor = parallelExecutor;
  25. this.executionLoadBalancer = new RoundRobinLoadBalancer();
  26. }
  27. public void appendState(StringBuffer sbState) {
  28. sbState.append("\nExecutor." + name + ".size=" + parallelExecutor.getPoolSize());
  29. }
  30. public void stop() {
  31. parallelExecutor.shutdown();
  32. }
  33. public void execute(Runnable runnable) {
  34. parallelExecutor.execute(runnable);
  35. }
  36. public void executeOrderedRunnable(int hash, Runnable runnable) {
  37. parallelExecutor.execute(runnable, hash);
  38. }
  39. public ExecutionLoadBalancer getExecutionLoadBalancer() {
  40. return executionLoadBalancer;
  41. }
  42. }